forked from DhanushNehru/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1687363681284-CreateOrgEnvironmentConstantsTable.ts
More file actions
121 lines (114 loc) · 3.27 KB
/
1687363681284-CreateOrgEnvironmentConstantsTable.ts
File metadata and controls
121 lines (114 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableUnique } from 'typeorm';
export class CreateOrgEnvironmentConstantsTable1687363681284 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// Create organization_constants table
await queryRunner.createTable(
new Table({
name: 'organization_constants',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
default: 'gen_random_uuid()',
},
{
name: 'constant_name',
type: 'varchar',
isNullable: false,
},
{
name: 'organization_id',
type: 'uuid',
isNullable: false,
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
true
);
// Create org_environment_constant_values table
await queryRunner.createTable(
new Table({
name: 'org_environment_constant_values',
columns: [
{
name: 'id',
type: 'uuid',
isPrimary: true,
default: 'gen_random_uuid()',
},
{
name: 'organization_constant_id',
type: 'uuid',
isNullable: false,
},
{
name: 'environment_id',
type: 'uuid',
isNullable: false,
},
{
name: 'value',
type: 'varchar',
isNullable: true,
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
true
);
// Add foreign key constraint for organization_constant_id in org_environment_constant_values
await queryRunner.createForeignKey(
'org_environment_constant_values',
new TableForeignKey({
columnNames: ['organization_constant_id'],
referencedColumnNames: ['id'],
referencedTableName: 'organization_constants',
onDelete: 'CASCADE',
})
);
// Add foreign key constraint for environment_id in org_environment_constant_values
await queryRunner.createForeignKey(
'org_environment_constant_values',
new TableForeignKey({
columnNames: ['environment_id'],
referencedColumnNames: ['id'],
referencedTableName: 'app_environments',
onDelete: 'CASCADE',
})
);
// Add unique constraint for organization_constant_id and environment_id in org_environment_constant_values
await queryRunner.createUniqueConstraint(
'org_environment_constant_values',
new TableUnique({
columnNames: ['organization_constant_id', 'environment_id'],
})
);
await queryRunner.createUniqueConstraint(
'organization_constants',
new TableUnique({
columnNames: ['constant_name', 'organization_id'],
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {}
}