From e0e0b74788ab52586d9ffe2c152d9e5518c2d4bb Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Tue, 23 Aug 2022 18:58:55 +0200 Subject: New db migration script - multiplatform, fix mariadb migrations --- .../mariadb/1660131942703-apps_nullable_team.ts | 17 --- .../mariadb/1660540527213-sync_migrations.ts | 126 ----------------- .../mariadb/1660549252130-fix_nullables.ts | 29 ---- src/util/migrations/mariadb/1661273147273-test.ts | 149 +++++++++++++++++++++ src/util/migrations/mariadb/1661273179287-test2.ts | 18 +++ src/util/util/Database.ts | 7 +- 6 files changed, 169 insertions(+), 177 deletions(-) delete mode 100644 src/util/migrations/mariadb/1660131942703-apps_nullable_team.ts delete mode 100644 src/util/migrations/mariadb/1660540527213-sync_migrations.ts delete mode 100644 src/util/migrations/mariadb/1660549252130-fix_nullables.ts create mode 100644 src/util/migrations/mariadb/1661273147273-test.ts create mode 100644 src/util/migrations/mariadb/1661273179287-test2.ts (limited to 'src') diff --git a/src/util/migrations/mariadb/1660131942703-apps_nullable_team.ts b/src/util/migrations/mariadb/1660131942703-apps_nullable_team.ts deleted file mode 100644 index c76d9af4..00000000 --- a/src/util/migrations/mariadb/1660131942703-apps_nullable_team.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class appsNullableTeam1660131942703 implements MigrationInterface { - name = "appsNullableTeam1660131942703"; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - DROP INDEX \`IDX_2ce5a55796fe4c2f77ece57a64\` ON \`applications\` - `); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - CREATE UNIQUE INDEX \`IDX_2ce5a55796fe4c2f77ece57a64\` ON \`applications\` (\`bot_user_id\`) - `); - } -} diff --git a/src/util/migrations/mariadb/1660540527213-sync_migrations.ts b/src/util/migrations/mariadb/1660540527213-sync_migrations.ts deleted file mode 100644 index 594e4472..00000000 --- a/src/util/migrations/mariadb/1660540527213-sync_migrations.ts +++ /dev/null @@ -1,126 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class syncMigrations1660540527213 implements MigrationInterface { - name = "syncMigrations1660540527213"; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` CHANGE \`settings\` \`settingsId\` text NOT NULL - `); - await queryRunner.query(` - CREATE TABLE \`user_settings\` ( - \`id\` varchar(255) NOT NULL, - \`afk_timeout\` int NULL, - \`allow_accessibility_detection\` tinyint NULL, - \`animate_emoji\` tinyint NULL, - \`animate_stickers\` int NULL, - \`contact_sync_enabled\` tinyint NULL, - \`convert_emoticons\` tinyint NULL, - \`custom_status\` text NULL, - \`default_guilds_restricted\` tinyint NULL, - \`detect_platform_accounts\` tinyint NULL, - \`developer_mode\` tinyint NULL, - \`disable_games_tab\` tinyint NULL, - \`enable_tts_command\` tinyint NULL, - \`explicit_content_filter\` int NULL, - \`friend_source_flags\` text NULL, - \`gateway_connected\` tinyint NULL, - \`gif_auto_play\` tinyint NULL, - \`guild_folders\` text NULL, - \`guild_positions\` text NULL, - \`inline_attachment_media\` tinyint NULL, - \`inline_embed_media\` tinyint NULL, - \`locale\` varchar(255) NULL, - \`message_display_compact\` tinyint NULL, - \`native_phone_integration_enabled\` tinyint NULL, - \`render_embeds\` tinyint NULL, - \`render_reactions\` tinyint NULL, - \`restricted_guilds\` text NULL, - \`show_current_game\` tinyint NULL, - \`status\` varchar(255) NULL, - \`stream_notifications_enabled\` tinyint NULL, - \`theme\` varchar(255) NULL, - \`timezone_offset\` int NULL, - PRIMARY KEY (\`id\`) - ) ENGINE = InnoDB - `); - await queryRunner.query(` - ALTER TABLE \`channels\` - ADD \`flags\` int NULL - `); - await queryRunner.query(` - ALTER TABLE \`channels\` - ADD \`default_thread_rate_limit_per_user\` int NULL - `); - await queryRunner.query(` - ALTER TABLE \`guilds\` - ADD \`premium_progress_bar_enabled\` tinyint NULL - `); - await queryRunner.query(` - ALTER TABLE \`users\` DROP COLUMN \`settingsId\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` - ADD \`settingsId\` varchar(255) NULL - `); - await queryRunner.query(` - ALTER TABLE \`users\` - ADD UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` (\`settingsId\`) - `); - await queryRunner.query(` - CREATE UNIQUE INDEX \`REL_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) - `); - await queryRunner.query(` - ALTER TABLE \`users\` - ADD CONSTRAINT \`FK_76ba283779c8441fd5ff819c8cf\` FOREIGN KEY (\`settingsId\`) REFERENCES \`user_settings\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION - `); - await queryRunner.query(` - ALTER TABLE \`invites\` - ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION - `); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` DROP FOREIGN KEY \`FK_76ba283779c8441fd5ff819c8cf\` - `); - await queryRunner.query(` - DROP INDEX \`REL_76ba283779c8441fd5ff819c8c\` ON \`users\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` DROP COLUMN \`settingsId\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` - ADD \`settingsId\` text NOT NULL - `); - await queryRunner.query(` - ALTER TABLE \`guilds\` DROP COLUMN \`premium_progress_bar_enabled\` - `); - await queryRunner.query(` - ALTER TABLE \`channels\` DROP COLUMN \`default_thread_rate_limit_per_user\` - `); - await queryRunner.query(` - ALTER TABLE \`channels\` DROP COLUMN \`flags\` - `); - await queryRunner.query(` - DROP TABLE \`user_settings\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` CHANGE \`settingsId\` \`settings\` text NOT NULL - `); - await queryRunner.query(` - ALTER TABLE \`invites\` - ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION - `); - } -} diff --git a/src/util/migrations/mariadb/1660549252130-fix_nullables.ts b/src/util/migrations/mariadb/1660549252130-fix_nullables.ts deleted file mode 100644 index d9ea2e77..00000000 --- a/src/util/migrations/mariadb/1660549252130-fix_nullables.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class fixNullables1660549252130 implements MigrationInterface { - name = "fixNullables1660549252130"; - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` - `); - await queryRunner.query(` - ALTER TABLE \`users\` CHANGE \`bio\` \`bio\` varchar(255) NULL - `); - await queryRunner.query(` - ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NULL - `); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(` - ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NOT NULL - `); - await queryRunner.query(` - ALTER TABLE \`users\` CHANGE \`bio\` \`bio\` varchar(255) NOT NULL - `); - await queryRunner.query(` - CREATE UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) - `); - } -} diff --git a/src/util/migrations/mariadb/1661273147273-test.ts b/src/util/migrations/mariadb/1661273147273-test.ts new file mode 100644 index 00000000..4e077a11 --- /dev/null +++ b/src/util/migrations/mariadb/1661273147273-test.ts @@ -0,0 +1,149 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class test1661273147273 implements MigrationInterface { + name = 'test1661273147273' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` + `); + await queryRunner.query(` + DROP INDEX \`IDX_2ce5a55796fe4c2f77ece57a64\` ON \`applications\` + `); + await queryRunner.query(` + CREATE TABLE \`plugin_config\` ( + \`key\` varchar(255) NOT NULL, + \`value\` text NULL, + PRIMARY KEY (\`key\`) + ) ENGINE = InnoDB + `); + await queryRunner.query(` + CREATE TABLE \`user_settings\` ( + \`id\` varchar(255) NOT NULL, + \`afk_timeout\` int NULL, + \`allow_accessibility_detection\` tinyint NULL, + \`animate_emoji\` tinyint NULL, + \`animate_stickers\` int NULL, + \`contact_sync_enabled\` tinyint NULL, + \`convert_emoticons\` tinyint NULL, + \`custom_status\` text NULL, + \`default_guilds_restricted\` tinyint NULL, + \`detect_platform_accounts\` tinyint NULL, + \`developer_mode\` tinyint NULL, + \`disable_games_tab\` tinyint NULL, + \`enable_tts_command\` tinyint NULL, + \`explicit_content_filter\` int NULL, + \`friend_source_flags\` text NULL, + \`gateway_connected\` tinyint NULL, + \`gif_auto_play\` tinyint NULL, + \`guild_folders\` text NULL, + \`guild_positions\` text NULL, + \`inline_attachment_media\` tinyint NULL, + \`inline_embed_media\` tinyint NULL, + \`locale\` varchar(255) NULL, + \`message_display_compact\` tinyint NULL, + \`native_phone_integration_enabled\` tinyint NULL, + \`render_embeds\` tinyint NULL, + \`render_reactions\` tinyint NULL, + \`restricted_guilds\` text NULL, + \`show_current_game\` tinyint NULL, + \`status\` varchar(255) NULL, + \`stream_notifications_enabled\` tinyint NULL, + \`theme\` varchar(255) NULL, + \`timezone_offset\` int NULL, + PRIMARY KEY (\`id\`) + ) ENGINE = InnoDB + `); + await queryRunner.query(` + ALTER TABLE \`users\` DROP COLUMN \`settings\` + `); + await queryRunner.query(` + ALTER TABLE \`users\` + ADD \`settingsId\` varchar(255) NULL + `); + await queryRunner.query(` + ALTER TABLE \`users\` + ADD UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` (\`settingsId\`) + `); + await queryRunner.query(` + ALTER TABLE \`channels\` + ADD \`flags\` int NULL + `); + await queryRunner.query(` + ALTER TABLE \`channels\` + ADD \`default_thread_rate_limit_per_user\` int NULL + `); + await queryRunner.query(` + ALTER TABLE \`guilds\` + ADD \`premium_progress_bar_enabled\` tinyint NULL + `); + await queryRunner.query(` + ALTER TABLE \`users\` CHANGE \`bio\` \`bio\` varchar(255) NULL + `); + await queryRunner.query(` + ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NULL + `); + await queryRunner.query(` + CREATE UNIQUE INDEX \`REL_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) + `); + await queryRunner.query(` + ALTER TABLE \`users\` + ADD CONSTRAINT \`FK_76ba283779c8441fd5ff819c8cf\` FOREIGN KEY (\`settingsId\`) REFERENCES \`user_settings\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION + `); + await queryRunner.query(` + ALTER TABLE \`invites\` + ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + ALTER TABLE \`invites\` DROP FOREIGN KEY \`FK_15c35422032e0b22b4ada95f48f\` + `); + await queryRunner.query(` + ALTER TABLE \`users\` DROP FOREIGN KEY \`FK_76ba283779c8441fd5ff819c8cf\` + `); + await queryRunner.query(` + DROP INDEX \`REL_76ba283779c8441fd5ff819c8c\` ON \`users\` + `); + await queryRunner.query(` + ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NOT NULL + `); + await queryRunner.query(` + ALTER TABLE \`users\` CHANGE \`bio\` \`bio\` varchar(255) NOT NULL + `); + await queryRunner.query(` + ALTER TABLE \`guilds\` DROP COLUMN \`premium_progress_bar_enabled\` + `); + await queryRunner.query(` + ALTER TABLE \`channels\` DROP COLUMN \`default_thread_rate_limit_per_user\` + `); + await queryRunner.query(` + ALTER TABLE \`channels\` DROP COLUMN \`flags\` + `); + await queryRunner.query(` + ALTER TABLE \`users\` DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` + `); + await queryRunner.query(` + ALTER TABLE \`users\` DROP COLUMN \`settingsId\` + `); + await queryRunner.query(` + ALTER TABLE \`users\` + ADD \`settings\` text NOT NULL + `); + await queryRunner.query(` + DROP TABLE \`user_settings\` + `); + await queryRunner.query(` + DROP TABLE \`plugin_config\` + `); + await queryRunner.query(` + CREATE UNIQUE INDEX \`IDX_2ce5a55796fe4c2f77ece57a64\` ON \`applications\` (\`bot_user_id\`) + `); + await queryRunner.query(` + ALTER TABLE \`invites\` + ADD CONSTRAINT \`FK_15c35422032e0b22b4ada95f48f\` FOREIGN KEY (\`inviter_id\`) REFERENCES \`users\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION + `); + } + +} diff --git a/src/util/migrations/mariadb/1661273179287-test2.ts b/src/util/migrations/mariadb/1661273179287-test2.ts new file mode 100644 index 00000000..0f77f284 --- /dev/null +++ b/src/util/migrations/mariadb/1661273179287-test2.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class test21661273179287 implements MigrationInterface { + name = 'test21661273179287' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`) + `); + } + +} diff --git a/src/util/util/Database.ts b/src/util/util/Database.ts index 8509879d..b9f8365e 100644 --- a/src/util/util/Database.ts +++ b/src/util/util/Database.ts @@ -87,7 +87,7 @@ function getDataSourceOptions(): DataSourceOptions { //entities: Object.values(Models).filter((x) => x.constructor.name !== "Object" && x.constructor.name !== "Array" && x.constructor.name !== "BigInt" && x).map(x=>x.name), entities: Object.values(Models).filter((x) => x.constructor.name == "Function" && shouldIncludeEntity(x.name)), synchronize: synchronizeInsteadOfMigrations, - logging: verboseDb, + logging: verboseDb ? "all" : false, cache: { duration: 1000 * 3 // cache all find queries for 3 seconds }, @@ -96,10 +96,7 @@ function getDataSourceOptions(): DataSourceOptions { name: "default", migrations: synchronizeInsteadOfMigrations ? [] : [path.join(__dirname, "..", "migrations", type, "*.js")], migrationsRun: !synchronizeInsteadOfMigrations, - //migrationsRun: false, - cli: { - migrationsDir: `src/migrations/${type}` - } + applicationName: `Fosscord Server`, } as DataSourceOptions; } -- cgit 1.5.1