]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/migrations/0705-local-video-viewers.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / initializers / migrations / 0705-local-video-viewers.ts
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 const { transaction } = utils
10
11 {
12 const query = `
13 CREATE TABLE IF NOT EXISTS "localVideoViewer" (
14 "id" serial,
15 "startDate" timestamp with time zone NOT NULL,
16 "endDate" timestamp with time zone NOT NULL,
17 "watchTime" integer NOT NULL,
18 "country" varchar(255),
19 "uuid" uuid NOT NULL,
20 "url" varchar(255) NOT NULL,
21 "videoId" integer NOT NULL REFERENCES "video" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
22 "createdAt" timestamp with time zone NOT NULL,
23 PRIMARY KEY ("id")
24 );
25 `
26 await utils.sequelize.query(query, { transaction })
27 }
28
29 {
30 const query = `
31 CREATE TABLE IF NOT EXISTS "localVideoViewerWatchSection" (
32 "id" serial,
33 "watchStart" integer NOT NULL,
34 "watchEnd" integer NOT NULL,
35 "localVideoViewerId" integer NOT NULL REFERENCES "localVideoViewer" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
36 "createdAt" timestamp with time zone NOT NULL,
37 PRIMARY KEY ("id")
38 );
39 `
40 await utils.sequelize.query(query, { transaction })
41 }
42
43 }
44
45 function down () {
46 throw new Error('Not implemented.')
47 }
48
49 export {
50 up,
51 down
52 }