feat: implements article table
This commit is contained in:
33
migrations/1775011588385-adds-base-triggers.ts
Normal file
33
migrations/1775011588385-adds-base-triggers.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddsBaseTriggers1775011588385 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
queryRunner.query(`
|
||||
CREATE OR REPLACE FUNCTION set_updated_at()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
CREATE TRIGGER set_articles_updated_at
|
||||
BEFORE UPDATE ON articles
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION set_updated_at();
|
||||
|
||||
CREATE TRIGGER set_users_updated_at
|
||||
BEFORE UPDATE on users
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION set_updated_at();
|
||||
--end-sql`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`--sql
|
||||
DROP TRIGGER set_articles_updated_at ON articles;
|
||||
DROP TRIGGER set_users_updated_at ON users;
|
||||
DROP FUNCTION set_updated_at();
|
||||
--end-sql`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user