Skip to content

Commit

Permalink
migration update
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Nov 8, 2021
1 parent fa5519a commit c2d42bc
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class serviceMigration1635631125262 implements MigrationInterface {
name = 'serviceMigration1635631125262';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = (await queryRunner.query(`SELECT * from \`settings\``)).filter((o: any) => {
return o.namespace === '/core/oauth'
|| o.namespace === '/core/tmi'
|| o.namespace === '/core/twitch';
});
for (const item of items) {
await queryRunner.query(`UPDATE \`settings\` SET \`namespace\`="/services/twitch" WHERE \`id\`="${item.id}"`);
}
await queryRunner.query(`INSERT INTO \`settings\`(\`namespace\`, \`value\`, \`name\`) VALUES ("/services/twitch", "${JSON.stringify(true)}", "enabled")`);

const items2 = (await queryRunner.query(`SELECT * from \`settings\``)).filter((o: any) => {
return o.namespace === '/core/eventsub';
});

for (const item of items2) {
if (item.name === 'useTunneling' || item.name === 'domain' || item.name === 'appToken' || item.name === 'secret') {
await queryRunner.query(`UPDATE \`settings\` SET \`namespace\`="/services/twitch" WHERE \`id\`="${item.id}"`);
} else {
await queryRunner.query(`UPDATE \`settings\` SET \`namespace\`="/services/twitch", \`name\`="eventSub${item.name.charAt(0).toUpperCase() + item.name.slice(1)}" WHERE \`id\`="${item.id}"`);
}

}
}

public async down(queryRunner: QueryRunner): Promise<void> {
console.log('Please revert you db from backup.');
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class serviceMigration1635631125262 implements MigrationInterface {
name = 'serviceMigration1635631125262';

public async up(queryRunner: QueryRunner): Promise<void> {
const items = (await queryRunner.query(`SELECT * from "settings"`)).filter((o: any) => {
return o.namespace === '/core/oauth'
|| o.namespace === '/core/tmi'
|| o.namespace === '/core/twitch';
});
for (const item of items) {
await queryRunner.query(`UPDATE "settings" SET "namespace"='/services/twitch' WHERE "id"='${item.id}'`);
}
await queryRunner.query(`INSERT INTO "settings"("namespace", "value", "name") VALUES ('/services/twitch', '${JSON.stringify(true)}', 'enabled')`);

const items2 = (await queryRunner.query(`SELECT * from "settings"`)).filter((o: any) => {
return o.namespace === '/core/eventsub';
});

for (const item of items2) {
if (item.name === 'useTunneling' || item.name === 'domain' || item.name === 'appToken' || item.name === 'secret') {
await queryRunner.query(`UPDATE "settings" SET "namespace"='/services/twitch' WHERE "id"='${item.id}'`);
} else {
await queryRunner.query(`UPDATE "settings" SET "namespace"='/services/twitch', "name"='eventSub${item.name.charAt(0).toUpperCase() + item.name.slice(1)}' WHERE "id"='${item.id}'`);
}

}
}

public async down(queryRunner: QueryRunner): Promise<void> {
console.log('Please revert you db from backup.');
}

}

0 comments on commit c2d42bc

Please sign in to comment.