diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-24 13:36:47 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | b211106695bb82f6c32e53306081b5262c3d109d (patch) | |
tree | fa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/initializers/migrations/0705-local-video-viewers.ts | |
parent | 69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff) | |
download | PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip |
Support video views/viewers stats in server
* Add "currentTime" and "event" body params to view endpoint
* Merge watching and view endpoints
* Introduce WatchAction AP activity
* Add tables to store viewer information of local videos
* Add endpoints to fetch video views/viewers stats of local videos
* Refactor views/viewers handlers
* Support "views" and "viewers" counters for both VOD and live videos
Diffstat (limited to 'server/initializers/migrations/0705-local-video-viewers.ts')
-rw-r--r-- | server/initializers/migrations/0705-local-video-viewers.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/initializers/migrations/0705-local-video-viewers.ts b/server/initializers/migrations/0705-local-video-viewers.ts new file mode 100644 index 000000000..123402641 --- /dev/null +++ b/server/initializers/migrations/0705-local-video-viewers.ts | |||
@@ -0,0 +1,52 @@ | |||
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 | } | ||