forked from hirosystems/ordinals-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1690832271103_location-pointer-constraints.ts
55 lines (51 loc) · 2.11 KB
/
1690832271103_location-pointer-constraints.ts
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
/* eslint-disable @typescript-eslint/naming-convention */
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
export const shorthands: ColumnDefinitions | undefined = undefined;
export function up(pgm: MigrationBuilder): void {
pgm.dropConstraint('genesis_locations', 'genesis_locations_inscription_id_unique');
pgm.createConstraint('genesis_locations', 'genesis_locations_inscription_id_pk', {
primaryKey: 'inscription_id',
});
pgm.createConstraint(
'genesis_locations',
'genesis_locations_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'genesis_locations',
'genesis_locations_location_id_fk',
'FOREIGN KEY(location_id) REFERENCES locations(id) ON DELETE CASCADE'
);
pgm.dropConstraint('current_locations', 'current_locations_inscription_id_unique');
pgm.createConstraint('current_locations', 'current_locations_inscription_id_pk', {
primaryKey: 'inscription_id',
});
pgm.createConstraint(
'current_locations',
'current_locations_inscription_id_fk',
'FOREIGN KEY(inscription_id) REFERENCES inscriptions(id) ON DELETE CASCADE'
);
pgm.createConstraint(
'current_locations',
'current_locations_location_id_fk',
'FOREIGN KEY(location_id) REFERENCES locations(id) ON DELETE CASCADE'
);
}
export function down(pgm: MigrationBuilder): void {
pgm.dropConstraint('genesis_locations', 'genesis_locations_inscription_id_pk');
pgm.dropConstraint('genesis_locations', 'genesis_locations_inscription_id_fk');
pgm.dropConstraint('genesis_locations', 'genesis_locations_location_id_fk');
pgm.createConstraint(
'genesis_locations',
'genesis_locations_inscription_id_unique',
'UNIQUE(inscription_id)'
);
pgm.dropConstraint('current_locations', 'current_locations_inscription_id_pk');
pgm.dropConstraint('current_locations', 'current_locations_inscription_id_fk');
pgm.dropConstraint('current_locations', 'current_locations_location_id_fk');
pgm.createConstraint(
'current_locations',
'current_locations_inscription_id_unique',
'UNIQUE(inscription_id)'
);
}