From bf55be2978b3c313d48efa5a12c1fc3bda816932 Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Fri, 29 Dec 2023 23:56:25 +0200 Subject: [PATCH 1/2] Add proxyUrls column to UserSettings model --- src/db/migrations/.snapshot-postgres.json | 9 +++++++++ src/db/migrations/Migration20231229214215.ts | 13 +++++++++++++ src/db/models/UserSettings.ts | 5 +++++ src/routes/users/settings.ts | 2 ++ 4 files changed, 29 insertions(+) create mode 100644 src/db/migrations/Migration20231229214215.ts diff --git a/src/db/migrations/.snapshot-postgres.json b/src/db/migrations/.snapshot-postgres.json index b4204ac..7588bcf 100644 --- a/src/db/migrations/.snapshot-postgres.json +++ b/src/db/migrations/.snapshot-postgres.json @@ -483,6 +483,15 @@ "primary": false, "nullable": true, "mappedType": "string" + }, + "proxy_urls": { + "name": "proxy_urls", + "type": "text[]", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "array" } }, "name": "user_settings", diff --git a/src/db/migrations/Migration20231229214215.ts b/src/db/migrations/Migration20231229214215.ts new file mode 100644 index 0000000..d5149db --- /dev/null +++ b/src/db/migrations/Migration20231229214215.ts @@ -0,0 +1,13 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20231229214215 extends Migration { + + async up(): Promise { + this.addSql('alter table "user_settings" add column "proxy_urls" text[] null;'); + } + + async down(): Promise { + this.addSql('alter table "user_settings" drop column "proxy_urls";'); + } + +} diff --git a/src/db/models/UserSettings.ts b/src/db/models/UserSettings.ts index 4014255..f08caa0 100644 --- a/src/db/models/UserSettings.ts +++ b/src/db/models/UserSettings.ts @@ -13,6 +13,9 @@ export class UserSettings { @Property({ name: 'default_subtitle_language', nullable: true }) defaultSubtitleLanguage?: string | null; + + @Property({ name: 'proxy_urls', nullable: true, type: 'text[]' }) + proxyUrls?: string[] | null; } export interface UserSettingsDTO { @@ -20,6 +23,7 @@ export interface UserSettingsDTO { applicationTheme?: string | null; applicationLanguage?: string | null; defaultSubtitleLanguage?: string | null; + proxyUrls?: string[] | null; } export function formatUserSettings( @@ -30,5 +34,6 @@ export function formatUserSettings( applicationTheme: userSettings.applicationTheme, applicationLanguage: userSettings.applicationLanguage, defaultSubtitleLanguage: userSettings.defaultSubtitleLanguage, + proxyUrls: userSettings.proxyUrls, }; } diff --git a/src/routes/users/settings.ts b/src/routes/users/settings.ts index de315ee..6a11d03 100644 --- a/src/routes/users/settings.ts +++ b/src/routes/users/settings.ts @@ -41,6 +41,7 @@ export const userSettingsRouter = makeRouter((app) => { applicationLanguage: z.string().nullable().optional(), applicationTheme: z.string().nullable().optional(), defaultSubtitleLanguage: z.string().nullable().optional(), + proxyUrls: z.string().array().nullable().optional(), }), }, }, @@ -64,6 +65,7 @@ export const userSettingsRouter = makeRouter((app) => { settings.defaultSubtitleLanguage = body.defaultSubtitleLanguage; if (body.applicationTheme !== undefined) settings.applicationTheme = body.applicationTheme; + if (body.proxyUrls !== undefined) settings.proxyUrls = body.proxyUrls; await em.persistAndFlush(settings); return formatUserSettings(settings); From b2e0841d0b4f5f58ebbf6092ab5a762a39aad56f Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:46:46 +0200 Subject: [PATCH 2/2] Swap to using ArrayType --- src/db/models/UserSettings.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/db/models/UserSettings.ts b/src/db/models/UserSettings.ts index f08caa0..14911b4 100644 --- a/src/db/models/UserSettings.ts +++ b/src/db/models/UserSettings.ts @@ -1,4 +1,4 @@ -import { Entity, PrimaryKey, Property } from '@mikro-orm/core'; +import { ArrayType, Entity, PrimaryKey, Property } from '@mikro-orm/core'; @Entity({ tableName: 'user_settings' }) export class UserSettings { @@ -14,7 +14,7 @@ export class UserSettings { @Property({ name: 'default_subtitle_language', nullable: true }) defaultSubtitleLanguage?: string | null; - @Property({ name: 'proxy_urls', nullable: true, type: 'text[]' }) + @Property({ name: 'proxy_urls', type: ArrayType, nullable: true }) proxyUrls?: string[] | null; }