-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(keywords): add response randomizer
- Loading branch information
Showing
9 changed files
with
232 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/database/migration/mysql/22.x/1678892044040-changeKeywordsResponses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
import { insertItemIntoTable } from '../../../insertItemIntoTable.js'; | ||
|
||
export class changeKeywordsResponses1678892044040 implements MigrationInterface { | ||
name = 'changeKeywordsResponses1678892044040'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const items = await queryRunner.query(`SELECT * from \`keyword\``); | ||
const items2 = await queryRunner.query(`SELECT * from \`keyword_responses\``); | ||
|
||
await queryRunner.query(`DELETE from \`keyword_responses\` WHERE 1=1`); | ||
await queryRunner.query(`DELETE from \`keyword\` WHERE 1=1`); | ||
|
||
await queryRunner.query(`DROP TABLE \`keyword_responses\``); | ||
await queryRunner.query(`DROP TABLE \`keyword\``); | ||
|
||
await queryRunner.query(`CREATE TABLE \`keyword\` (\`id\` varchar(36) NOT NULL, \`keyword\` varchar(255) NOT NULL, \`enabled\` tinyint NOT NULL, \`group\` varchar(255) NULL, \`areResponsesRandomized\` tinyint NOT NULL DEFAULT 0, \`responses\` json NOT NULL, INDEX \`IDX_35e3ff88225eef1d85c951e229\` (\`keyword\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); | ||
|
||
for (const item of items) { | ||
item.responses = JSON.stringify(items2.filter((o: any) => o.keywordId === item.id)); | ||
await insertItemIntoTable('keyword', { | ||
...item, | ||
}, queryRunner); | ||
} | ||
|
||
return; | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
return; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/database/migration/postgres/22.x/1678892044040-changeKeywordsResponses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
import { insertItemIntoTable } from '../../../insertItemIntoTable.js'; | ||
|
||
export class changeKeywordsResponses1678892044040 implements MigrationInterface { | ||
name = 'changeKeywordsResponses1678892044040'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const items = await queryRunner.query(`SELECT * from "keyword"`); | ||
const items2 = await queryRunner.query(`SELECT * from "keyword_responses"`); | ||
|
||
await queryRunner.query(`DELETE from "keyword_responses" WHERE 1=1`); | ||
await queryRunner.query(`DELETE from "keyword" WHERE 1=1`); | ||
|
||
await queryRunner.query(`DROP TABLE "keyword_responses"`); | ||
await queryRunner.query(`DROP TABLE "keyword"`); | ||
|
||
await queryRunner.query(`CREATE TABLE "keyword" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "areResponsesRandomized" boolean NOT NULL DEFAULT false, "keyword" character varying NOT NULL, "enabled" boolean NOT NULL, "group" character varying, "responses" json NOT NULL, CONSTRAINT "PK_affdb8c8fa5b442900cb3aa21dc" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`CREATE INDEX "IDX_35e3ff88225eef1d85c951e229" ON "keyword" ("keyword") `); | ||
|
||
for (const item of items) { | ||
item.responses = JSON.stringify(items2.filter((o: any) => o.keywordId === item.id)); | ||
await insertItemIntoTable('keyword', { | ||
...item, | ||
}, queryRunner); | ||
} | ||
|
||
return; | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
return; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/database/migration/sqlite/22.x/1678892044040-changeKeywordsResponses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
import { insertItemIntoTable } from '../../../insertItemIntoTable.js'; | ||
|
||
export class changeKeywordsResponses1678892044040 implements MigrationInterface { | ||
name = 'changeKeywordsResponses1678892044040'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
const items = await queryRunner.query(`SELECT * from "keyword"`); | ||
const items2 = await queryRunner.query(`SELECT * from "keyword_responses"`); | ||
|
||
await queryRunner.query(`DELETE from "keyword_responses" WHERE 1=1`); | ||
await queryRunner.query(`DELETE from "keyword" WHERE 1=1`); | ||
|
||
await queryRunner.query(`DROP TABLE "keyword_responses"`); | ||
await queryRunner.query(`DROP TABLE "keyword"`); | ||
|
||
await queryRunner.query(`CREATE TABLE "keyword" ("id" varchar PRIMARY KEY NOT NULL, "areResponsesRandomized" boolean NOT NULL DEFAULT (0), "keyword" varchar NOT NULL, "enabled" boolean NOT NULL, "group" varchar, "responses" text NOT NULL)`); | ||
await queryRunner.query(`CREATE INDEX "IDX_35e3ff88225eef1d85c951e229" ON "keyword" ("keyword") `); | ||
|
||
for (const item of items) { | ||
item.responses = JSON.stringify(items2.filter((o: any) => o.keywordId === item.id)); | ||
await insertItemIntoTable('keyword', { | ||
...item, | ||
}, queryRunner); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
return; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.