feat: initial commit
This commit is contained in:
21
migrations/1775776542850-adds-base-triggers.ts
Normal file
21
migrations/1775776542850-adds-base-triggers.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddsBaseTriggers1775776542850 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE OR REPLACE FUNCTION set_updated_at()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
--end-sql`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`--sql
|
||||
DROP FUNCTION set_updated_at();
|
||||
--end-sql`);
|
||||
}
|
||||
}
|
||||
31
migrations/1775776680658-adds-user-table.ts
Normal file
31
migrations/1775776680658-adds-user-table.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddsUserTable1775776680658 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`--sql
|
||||
CREATE TYPE user_role AS ENUM ('admin', 'internal', 'user');
|
||||
|
||||
CREATE TABLE users (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT NOT NULL UNIQUE,
|
||||
role user_role NOT NULL DEFAULT 'user',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
external_id UUID NOT NULL DEFAULT gen_random_uuid()
|
||||
);
|
||||
|
||||
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 TABLE users CASCADE;
|
||||
DROP TYPE user_role;
|
||||
--end-sql`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user