diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-12 10:53:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-07-12 10:56:07 +0200 |
commit | d959b763f089ed4c1087aa4aeb824a8ef6743111 (patch) | |
tree | f4b5e77757fde022c91e415906bcf4619f8ec31c /server/initializers | |
parent | 88cde4392a27d5d37685a471f9bf83d537282c43 (diff) | |
download | PeerTube-d959b763f089ed4c1087aa4aeb824a8ef6743111.tar.gz PeerTube-d959b763f089ed4c1087aa4aeb824a8ef6743111.tar.zst PeerTube-d959b763f089ed4c1087aa4aeb824a8ef6743111.zip |
Avoid duplicate runner names
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/migrations/0795-duplicate-runner-name.ts | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 03ae94d35..e09f0e3c6 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -27,7 +27,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' | |||
27 | 27 | ||
28 | // --------------------------------------------------------------------------- | 28 | // --------------------------------------------------------------------------- |
29 | 29 | ||
30 | const LAST_MIGRATION_VERSION = 790 | 30 | const LAST_MIGRATION_VERSION = 795 |
31 | 31 | ||
32 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
33 | 33 | ||
diff --git a/server/initializers/migrations/0795-duplicate-runner-name.ts b/server/initializers/migrations/0795-duplicate-runner-name.ts new file mode 100644 index 000000000..dd15a8157 --- /dev/null +++ b/server/initializers/migrations/0795-duplicate-runner-name.ts | |||
@@ -0,0 +1,24 @@ | |||
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 | }): Promise<void> { | ||
8 | const { transaction } = utils | ||
9 | |||
10 | const query = 'DELETE FROM "runner" r1 ' + | ||
11 | 'USING (SELECT MIN(id) as id, "name" FROM "runner" GROUP BY "name" HAVING COUNT(*) > 1) r2 ' + | ||
12 | 'WHERE r1."name" = r2."name" AND r1.id <> r2.id' | ||
13 | |||
14 | await utils.sequelize.query(query, { transaction }) | ||
15 | } | ||
16 | |||
17 | function down (options) { | ||
18 | throw new Error('Not implemented.') | ||
19 | } | ||
20 | |||
21 | export { | ||
22 | up, | ||
23 | down | ||
24 | } | ||