diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-19 11:56:04 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-01-19 13:54:52 +0100 |
commit | f008e9f3f34ed1724afd5e071c39ed931741acbc (patch) | |
tree | d6d338714d4dc051e8a7ffcfa707f6d4e9e44c0c /server/initializers/migrations/0755-unique-viewer-url.ts | |
parent | 5bdfa604f102a5e51b5152457cd1a16d79177e26 (diff) | |
download | PeerTube-f008e9f3f34ed1724afd5e071c39ed931741acbc.tar.gz PeerTube-f008e9f3f34ed1724afd5e071c39ed931741acbc.tar.zst PeerTube-f008e9f3f34ed1724afd5e071c39ed931741acbc.zip |
Add missing url unique index in local video viewer
Diffstat (limited to 'server/initializers/migrations/0755-unique-viewer-url.ts')
-rw-r--r-- | server/initializers/migrations/0755-unique-viewer-url.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/server/initializers/migrations/0755-unique-viewer-url.ts b/server/initializers/migrations/0755-unique-viewer-url.ts new file mode 100644 index 000000000..b3dff9258 --- /dev/null +++ b/server/initializers/migrations/0755-unique-viewer-url.ts | |||
@@ -0,0 +1,27 @@ | |||
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 | const query = 'DELETE FROM "localVideoViewer" t1 ' + | ||
12 | 'USING (SELECT MIN(id) as id, "url" FROM "localVideoViewer" GROUP BY "url" HAVING COUNT(*) > 1) t2 ' + | ||
13 | 'WHERE t1."url" = t2."url" AND t1.id <> t2.id' | ||
14 | |||
15 | await utils.sequelize.query(query, { transaction }) | ||
16 | } | ||
17 | |||
18 | async function down (utils: { | ||
19 | queryInterface: Sequelize.QueryInterface | ||
20 | transaction: Sequelize.Transaction | ||
21 | }) { | ||
22 | } | ||
23 | |||
24 | export { | ||
25 | up, | ||
26 | down | ||
27 | } | ||