mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-21 07:59:01 +00:00
93 lines
2.5 KiB
TypeScript
93 lines
2.5 KiB
TypeScript
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm';
|
|
|
|
export class CreateComponentTable1691006952074 implements MigrationInterface {
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.createTable(
|
|
new Table({
|
|
name: 'components',
|
|
columns: [
|
|
{
|
|
name: 'id',
|
|
type: 'uuid',
|
|
isPrimary: true,
|
|
default: 'gen_random_uuid()',
|
|
},
|
|
{
|
|
name: 'name',
|
|
type: 'varchar',
|
|
isNullable: false,
|
|
},
|
|
{
|
|
name: 'type',
|
|
type: 'varchar',
|
|
isNullable: false,
|
|
},
|
|
{
|
|
name: 'page_id',
|
|
type: 'uuid',
|
|
isNullable: false,
|
|
},
|
|
{
|
|
name: 'parent',
|
|
type: 'varchar',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'properties',
|
|
type: 'json',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'styles',
|
|
type: 'json',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'validations',
|
|
type: 'json',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'created_at',
|
|
type: 'timestamp',
|
|
isNullable: true,
|
|
default: 'now()',
|
|
},
|
|
{
|
|
name: 'updated_at',
|
|
type: 'timestamp',
|
|
isNullable: true,
|
|
default: 'now()',
|
|
},
|
|
],
|
|
})
|
|
);
|
|
|
|
await queryRunner.createForeignKey(
|
|
'components',
|
|
new TableForeignKey({
|
|
columnNames: ['page_id'],
|
|
referencedColumnNames: ['id'],
|
|
referencedTableName: 'pages',
|
|
onDelete: 'CASCADE',
|
|
})
|
|
);
|
|
|
|
await queryRunner.createIndex('components', new TableIndex({ columnNames: ['name'] }));
|
|
await queryRunner.createIndex('components', new TableIndex({ columnNames: ['type'] }));
|
|
await queryRunner.createIndex('components', new TableIndex({ columnNames: ['page_id'] }));
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
// Drop indexes
|
|
await queryRunner.dropIndex('components', 'IDX_COMPONENT_NAME');
|
|
await queryRunner.dropIndex('components', 'IDX_COMPONENT_TYPE');
|
|
await queryRunner.dropIndex('components', 'IDX_COMPONENT_PAGE');
|
|
|
|
// Drop foreign key
|
|
await queryRunner.dropForeignKey('components', 'FK_COMPONENT_PAGE');
|
|
|
|
// Drop table
|
|
await queryRunner.dropTable('components');
|
|
}
|
|
}
|