mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-25 15:37:37 +00:00
79 lines
2 KiB
TypeScript
79 lines
2 KiB
TypeScript
|
|
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from 'typeorm';
|
||
|
|
|
||
|
|
export class CreateEventHandlerTable1691004706564 implements MigrationInterface {
|
||
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||
|
|
await queryRunner.createTable(
|
||
|
|
new Table({
|
||
|
|
name: 'event_handlers',
|
||
|
|
columns: [
|
||
|
|
{
|
||
|
|
name: 'id',
|
||
|
|
type: 'uuid',
|
||
|
|
isPrimary: true,
|
||
|
|
default: 'gen_random_uuid()',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'name',
|
||
|
|
type: 'varchar',
|
||
|
|
isNullable: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'index',
|
||
|
|
type: 'int',
|
||
|
|
isNullable: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'event',
|
||
|
|
type: 'jsonb',
|
||
|
|
isNullable: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'app_version_id',
|
||
|
|
type: 'uuid',
|
||
|
|
isNullable: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'source_id',
|
||
|
|
type: 'varchar',
|
||
|
|
isNullable: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'target',
|
||
|
|
type: 'enum',
|
||
|
|
enum: ['page', 'component', 'data_query', 'table_column', 'table_action'],
|
||
|
|
default: "'page'",
|
||
|
|
isNullable: false,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'created_at',
|
||
|
|
type: 'timestamp',
|
||
|
|
isNullable: true,
|
||
|
|
default: 'now()',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: 'updated_at',
|
||
|
|
type: 'timestamp',
|
||
|
|
isNullable: true,
|
||
|
|
default: 'now()',
|
||
|
|
},
|
||
|
|
],
|
||
|
|
})
|
||
|
|
);
|
||
|
|
|
||
|
|
// Add foreign key to relate EventHandler with AppVersion
|
||
|
|
await queryRunner.createForeignKey(
|
||
|
|
'event_handlers',
|
||
|
|
new TableForeignKey({
|
||
|
|
columnNames: ['app_version_id'],
|
||
|
|
referencedColumnNames: ['id'],
|
||
|
|
referencedTableName: 'app_versions',
|
||
|
|
onDelete: 'CASCADE',
|
||
|
|
})
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||
|
|
await queryRunner.dropTable('event_handlers');
|
||
|
|
}
|
||
|
|
}
|