feat: implement article management features with CRUD operations
Some checks failed
Build and Test / run-test (20.x) (push) Has been cancelled
Some checks failed
Build and Test / run-test (20.x) (push) Has been cancelled
This commit is contained in:
33
migrations/1775782403581-adds-articles-table.ts
Normal file
33
migrations/1775782403581-adds-articles-table.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddsArticlesTable1775782403581 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`--sql
|
||||
CREATE TABLE articles (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
slug VARCHAR(255) NOT NULL UNIQUE,
|
||||
description TEXT NOT NULL,
|
||||
cover_image_url TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
author_id BIGINT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
external_id UUID NOT NULL DEFAULT gen_random_uuid() UNIQUE,
|
||||
|
||||
FOREIGN KEY (author_id) REFERENCES users (id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TRIGGER set_articles_updated_at
|
||||
BEFORE UPDATE on articles
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION set_updated_at();
|
||||
--end-sql`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`--sql
|
||||
DROP TABLE articles CASCADE;
|
||||
--end-sql`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user