mirror of
https://github.com/ToolJet/ToolJet
synced 2026-04-21 21:47:17 +00:00
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
import { MigrationInterface, QueryRunner, Table, TableForeignKey } from 'typeorm';
|
|
|
|
export class CreateLayoutTable1691007037021 implements MigrationInterface {
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.createTable(
|
|
new Table({
|
|
name: 'layouts',
|
|
columns: [
|
|
{
|
|
name: 'id',
|
|
type: 'uuid',
|
|
isPrimary: true,
|
|
default: 'gen_random_uuid()',
|
|
},
|
|
{
|
|
name: 'type',
|
|
type: 'enum',
|
|
enumName: 'layout_type',
|
|
enum: ['desktop', 'mobile'],
|
|
isNullable: false,
|
|
},
|
|
{
|
|
name: 'top',
|
|
type: 'double precision',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'left',
|
|
type: 'double precision',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'width',
|
|
type: 'double precision',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'height',
|
|
type: 'double precision',
|
|
isNullable: true,
|
|
},
|
|
{
|
|
name: 'component_id',
|
|
type: 'uuid',
|
|
isNullable: false,
|
|
},
|
|
],
|
|
})
|
|
);
|
|
|
|
// Add foreign key to relate Layout with Component
|
|
await queryRunner.createForeignKey(
|
|
'layouts',
|
|
new TableForeignKey({
|
|
columnNames: ['component_id'],
|
|
referencedColumnNames: ['id'],
|
|
referencedTableName: 'components',
|
|
onDelete: 'CASCADE',
|
|
})
|
|
);
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.dropTable('layouts');
|
|
}
|
|
}
|