diff options
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r-- | server/initializers/migrations/0795-duplicate-runner-name.ts | 24 |
1 files changed, 24 insertions, 0 deletions
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 | } | ||