]>
Commit | Line | Data |
---|---|---|
d9a2a031 C |
1 | import * as Sequelize from 'sequelize' |
2 | ||
3 | async function up (utils: { | |
4 | transaction: Sequelize.Transaction | |
5 | queryInterface: Sequelize.QueryInterface | |
6 | sequelize: Sequelize.Sequelize | |
7 | db: any | |
8 | }): Promise<void> { | |
9 | { | |
10 | const query = `CREATE TABLE IF NOT EXISTS "tracker" ( | |
11 | "id" serial, | |
12 | "url" varchar(255) NOT NULL, | |
13 | "createdAt" timestamp WITH time zone NOT NULL, | |
14 | "updatedAt" timestamp WITH time zone NOT NULL, | |
15 | PRIMARY KEY ("id") | |
16 | );` | |
17 | ||
18 | await utils.sequelize.query(query) | |
19 | } | |
20 | ||
21 | { | |
22 | const query = `CREATE TABLE IF NOT EXISTS "videoTracker" ( | |
23 | "videoId" integer REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | |
24 | "trackerId" integer REFERENCES "tracker" ("id") ON DELETE CASCADE ON UPDATE CASCADE, | |
25 | "createdAt" timestamp WITH time zone NOT NULL, | |
26 | "updatedAt" timestamp WITH time zone NOT NULL, | |
27 | UNIQUE ("videoId", "trackerId"), | |
28 | PRIMARY KEY ("videoId", "trackerId") | |
29 | );` | |
30 | ||
31 | await utils.sequelize.query(query) | |
32 | } | |
33 | ||
34 | await utils.sequelize.query(`CREATE UNIQUE INDEX "tracker_url" ON "tracker" ("url")`) | |
35 | } | |
36 | ||
37 | function down (options) { | |
38 | throw new Error('Not implemented.') | |
39 | } | |
40 | ||
41 | export { | |
42 | up, | |
43 | down | |
44 | } |