/* eslint-disable @typescript-eslint/camelcase */ import { MigrationBuilder } from 'node-pg-migrate'; import environment from '@bmd-studio/genstack-environment'; const { POSTGRES_PUBLIC_SCHEMA_NAME } = environment.env; const TABLE_NAME = 'projects'; export const up = async (pgm: MigrationBuilder): Promise => { // create table pgm.createTable({ schema: POSTGRES_PUBLIC_SCHEMA_NAME, name: TABLE_NAME, }, { id: { type: 'uuid', primaryKey: true, default: pgm.func('uuid_generate_v4()'), }, status: { type: 'int', default: 1, }, name: { type : 'varchar', notNull: true, default: '', }, description: { type: 'text', notNull: true, default: '', }, created_at: { type: 'timestamptz', default: pgm.func('current_timestamp'), }, updated_at: { type: 'timestamptz', default: pgm.func('current_timestamp'), }, }); // add indexes pgm.createIndex(TABLE_NAME, `status`); pgm.createIndex(TABLE_NAME, `name`); pgm.createIndex(TABLE_NAME, `created_at`, { opclass: 'DESC' }); pgm.createIndex(TABLE_NAME, `updated_at`, { opclass: 'DESC' }); // add triggers pgm.createTrigger(TABLE_NAME, 'set_update_timestamp', { when: 'BEFORE', operation: 'UPDATE', function: 'set_update_timestamp', }); }; export const down = async (pgm: MigrationBuilder): Promise => { pgm.dropTable(TABLE_NAME); };