From 1fca25a8b239083fe6a3f6b51c9bf16a3d4f5a3c Mon Sep 17 00:00:00 2001 From: sup39 Date: Tue, 23 Jan 2024 03:53:53 +0900 Subject: [PATCH] refactor: rename meta columns --- neko/revert.sql | 10 +++++-- packages/backend-rs/src/model/entity/meta.rs | 8 +++--- .../1705944717480-rename-meta-columns.js | 27 +++++++++++++++++++ packages/backend/src/misc/fetch-meta.ts | 4 +-- packages/backend/src/models/entities/meta.ts | 6 ++--- packages/backend/src/server/api/endpoints.ts | 4 +-- .../api/endpoints/admin/accounts/hosted.ts | 2 +- .../src/server/api/endpoints/admin/meta.ts | 6 ++--- .../server/api/endpoints/admin/update-meta.ts | 6 ++--- .../src/server/api/endpoints/custom-motd.ts | 2 +- .../backend/src/server/api/endpoints/meta.ts | 2 +- packages/backend/src/server/nodeinfo.ts | 2 +- .../backend/src/services/drive/add-file.ts | 2 +- packages/backend/src/services/drive/s3.ts | 6 ++--- 14 files changed, 60 insertions(+), 27 deletions(-) create mode 100644 packages/backend/migration-neko/1705944717480-rename-meta-columns.js diff --git a/neko/revert.sql b/neko/revert.sql index 5f915953f..016155747 100644 --- a/neko/revert.sql +++ b/neko/revert.sql @@ -1,16 +1,22 @@ BEGIN; DELETE FROM "migrations" WHERE name IN ( + 'RenameMetaColumns1705944717480', + 'RemoveNativeUtilsMigration1705877093218', 'DropTimeZone1705691683091', 'AddReplyMuting1704851359889', 'EmojimodEnumRelabel1699658378432', 'Vervis1699302371683', 'Pgroonga1698420787202', 'TruncateChartTables1694921638251', - 'EmojiModerator1692825433698', - 'RemoveNativeUtilsMigration1705877093218' + 'EmojiModerator1692825433698' ); +-- rename-meta-columns +ALTER TABLE "meta" RENAME COLUMN "tosUrl" TO "ToSUrl"; +ALTER TABLE "meta" RENAME COLUMN "objectStorageUseSsl" TO "objectStorageUseSSL"; +ALTER TABLE "meta" RENAME COLUMN "customMotd" TO "customMOTD"; + -- remove-native-utils-migration CREATE TABLE "seaql_migrations" ( version character varying NOT NULL, diff --git a/packages/backend-rs/src/model/entity/meta.rs b/packages/backend-rs/src/model/entity/meta.rs index 3c14ecde0..8b4f3e230 100644 --- a/packages/backend-rs/src/model/entity/meta.rs +++ b/packages/backend-rs/src/model/entity/meta.rs @@ -70,8 +70,8 @@ pub struct Model { pub sw_private_key: Option, #[sea_orm(column_name = "pinnedUsers")] pub pinned_users: Vec, - #[sea_orm(column_name = "ToSUrl")] - pub to_s_url: Option, + #[sea_orm(column_name = "tosUrl")] + pub tos_url: Option, #[sea_orm(column_name = "repositoryUrl")] pub repository_url: String, #[sea_orm(column_name = "feedbackUrl")] @@ -94,7 +94,7 @@ pub struct Model { pub object_storage_secret_key: Option, #[sea_orm(column_name = "objectStoragePort")] pub object_storage_port: Option, - #[sea_orm(column_name = "objectStorageUseSSL")] + #[sea_orm(column_name = "objectStorageUseSsl")] pub object_storage_use_ssl: bool, #[sea_orm(column_name = "proxyAccountId")] pub proxy_account_id: Option, @@ -140,7 +140,7 @@ pub struct Model { pub enable_ip_logging: bool, #[sea_orm(column_name = "enableActiveEmailValidation")] pub enable_active_email_validation: bool, - #[sea_orm(column_name = "customMOTD")] + #[sea_orm(column_name = "customMotd")] pub custom_motd: Vec, #[sea_orm(column_name = "customSplashIcons")] pub custom_splash_icons: Vec, diff --git a/packages/backend/migration-neko/1705944717480-rename-meta-columns.js b/packages/backend/migration-neko/1705944717480-rename-meta-columns.js new file mode 100644 index 000000000..37d3b3578 --- /dev/null +++ b/packages/backend/migration-neko/1705944717480-rename-meta-columns.js @@ -0,0 +1,27 @@ +export class RenameMetaColumns1705944717480 { + name = "RenameMetaColumns1705944717480"; + + async up(queryRunner) { + await queryRunner.query( + `ALTER TABLE "meta" RENAME COLUMN "customMOTD" TO "customMotd"`, + ); + await queryRunner.query( + `ALTER TABLE "meta" RENAME COLUMN "objectStorageUseSSL" TO "objectStorageUseSsl"`, + ); + await queryRunner.query( + `ALTER TABLE "meta" RENAME COLUMN "ToSUrl" TO "tosUrl"`, + ); + } + + async down(queryRunner) { + await queryRunner.query( + `ALTER TABLE "meta" RENAME COLUMN "tosUrl" TO "ToSUrl"`, + ); + await queryRunner.query( + `ALTER TABLE "meta" RENAME COLUMN "objectStorageUseSsl" TO "objectStorageUseSSL"`, + ); + await queryRunner.query( + `ALTER TABLE "meta" RENAME COLUMN "customMotd" TO "customMOTD"`, + ); + } +} diff --git a/packages/backend/src/misc/fetch-meta.ts b/packages/backend/src/misc/fetch-meta.ts index b3a5e30ae..fdc978b5a 100644 --- a/packages/backend/src/misc/fetch-meta.ts +++ b/packages/backend/src/misc/fetch-meta.ts @@ -5,8 +5,8 @@ let cache: Meta; export function metaToPugArgs(meta: Meta): object { let motd = ["Loading..."]; - if (meta.customMOTD.length > 0) { - motd = meta.customMOTD; + if (meta.customMotd.length > 0) { + motd = meta.customMotd; } let splashIconUrl = meta.iconUrl; if (meta.customSplashIcons.length > 0) { diff --git a/packages/backend/src/models/entities/meta.ts b/packages/backend/src/models/entities/meta.ts index 763d25b83..0f1d09f2c 100644 --- a/packages/backend/src/models/entities/meta.ts +++ b/packages/backend/src/models/entities/meta.ts @@ -98,7 +98,7 @@ export class Meta { array: true, default: "{}", }) - public customMOTD: string[]; + public customMotd: string[]; @Column("varchar", { length: 256, @@ -359,7 +359,7 @@ export class Meta { length: 512, nullable: true, }) - public ToSUrl: string | null; + public tosUrl: string | null; @Column("jsonb", { default: [], @@ -448,7 +448,7 @@ export class Meta { @Column("boolean", { default: true, }) - public objectStorageUseSSL: boolean; + public objectStorageUseSsl: boolean; @Column("boolean", { default: true, diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts index 0c5e41a2f..715337130 100644 --- a/packages/backend/src/server/api/endpoints.ts +++ b/packages/backend/src/server/api/endpoints.ts @@ -294,7 +294,7 @@ import * as ep___pages_update from "./endpoints/pages/update.js"; import * as ep___ping from "./endpoints/ping.js"; import * as ep___recommendedInstances from "./endpoints/recommended-instances.js"; import * as ep___pinnedUsers from "./endpoints/pinned-users.js"; -import * as ep___customMOTD from "./endpoints/custom-motd.js"; +import * as ep___customMotd from "./endpoints/custom-motd.js"; import * as ep___customSplashIcons from "./endpoints/custom-splash-icons.js"; import * as ep___latestVersion from "./endpoints/latest-version.js"; import * as ep___patrons from "./endpoints/patrons.js"; @@ -657,7 +657,7 @@ const eps = [ ["reply-mute/create", ep___reply_mute_create], ["reply-mute/delete", ep___reply_mute_delete], ["reply-mute/list", ep___reply_mute_list], - ["custom-motd", ep___customMOTD], + ["custom-motd", ep___customMotd], ["custom-splash-icons", ep___customSplashIcons], ["latest-version", ep___latestVersion], ["patrons", ep___patrons], diff --git a/packages/backend/src/server/api/endpoints/admin/accounts/hosted.ts b/packages/backend/src/server/api/endpoints/admin/accounts/hosted.ts index 601cd9500..fd4ad9401 100644 --- a/packages/backend/src/server/api/endpoints/admin/accounts/hosted.ts +++ b/packages/backend/src/server/api/endpoints/admin/accounts/hosted.ts @@ -89,7 +89,7 @@ export default define(meta, paramDef, async (ps, me) => { set.objectStorageSecretKey = config.objectStorage.secretKey; } if (typeof config.objectStorage.useSsl === "boolean") { - set.objectStorageUseSSL = config.objectStorage.useSsl; + set.objectStorageUseSsl = config.objectStorage.useSsl; } if (typeof config.objectStorage.connnectOverProxy === "boolean") { set.objectStorageUseProxy = config.objectStorage.connnectOverProxy; diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index 474b82e38..e3cb3a09d 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -471,7 +471,7 @@ export default define(meta, paramDef, async () => { uri: config.url, description: instance.description, langs: instance.langs, - tosUrl: instance.ToSUrl, + tosUrl: instance.tosUrl, moreUrls: instance.moreUrls, repositoryUrl: instance.repositoryUrl, feedbackUrl: instance.feedbackUrl, @@ -509,7 +509,7 @@ export default define(meta, paramDef, async () => { defaultReaction: instance.defaultReaction, recommendedInstances: instance.recommendedInstances, pinnedUsers: instance.pinnedUsers, - customMOTD: instance.customMOTD, + customMOTD: instance.customMotd, customSplashIcons: instance.customSplashIcons, hiddenTags: instance.hiddenTags, blockedHosts: instance.blockedHosts, @@ -541,7 +541,7 @@ export default define(meta, paramDef, async () => { objectStoragePort: instance.objectStoragePort, objectStorageAccessKey: instance.objectStorageAccessKey, objectStorageSecretKey: instance.objectStorageSecretKey, - objectStorageUseSSL: instance.objectStorageUseSSL, + objectStorageUseSSL: instance.objectStorageUseSsl, objectStorageUseProxy: instance.objectStorageUseProxy, objectStorageSetPublicRead: instance.objectStorageSetPublicRead, objectStorageS3ForcePathStyle: instance.objectStorageS3ForcePathStyle, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 955a1d95d..f0e831924 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -220,7 +220,7 @@ export default define(meta, paramDef, async (ps, me) => { } if (Array.isArray(ps.customMOTD)) { - set.customMOTD = ps.customMOTD.filter(Boolean); + set.customMotd = ps.customMOTD.filter(Boolean); } if (Array.isArray(ps.customSplashIcons)) { @@ -431,7 +431,7 @@ export default define(meta, paramDef, async (ps, me) => { } if (ps.tosUrl !== undefined) { - set.ToSUrl = ps.tosUrl; + set.tosUrl = ps.tosUrl; } if (ps.moreUrls !== undefined) { @@ -487,7 +487,7 @@ export default define(meta, paramDef, async (ps, me) => { } if (ps.objectStorageUseSSL !== undefined) { - set.objectStorageUseSSL = ps.objectStorageUseSSL; + set.objectStorageUseSsl = ps.objectStorageUseSSL; } if (ps.objectStorageUseProxy !== undefined) { diff --git a/packages/backend/src/server/api/endpoints/custom-motd.ts b/packages/backend/src/server/api/endpoints/custom-motd.ts index d61b31fed..2939355b9 100644 --- a/packages/backend/src/server/api/endpoints/custom-motd.ts +++ b/packages/backend/src/server/api/endpoints/custom-motd.ts @@ -28,6 +28,6 @@ export const paramDef = { export default define(meta, paramDef, async () => { const meta = await fetchMeta(); - const motd = await Promise.all(meta.customMOTD.map((x) => x)); + const motd = await Promise.all(meta.customMotd.map((x) => x)); return motd; }); diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 977d57a3c..e0e839671 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -425,7 +425,7 @@ export default define(meta, paramDef, async (ps, me) => { uri: config.url, description: instance.description, langs: instance.langs, - tosUrl: instance.ToSUrl, + tosUrl: instance.tosUrl, moreUrls: instance.moreUrls, repositoryUrl: instance.repositoryUrl, feedbackUrl: instance.feedbackUrl, diff --git a/packages/backend/src/server/nodeinfo.ts b/packages/backend/src/server/nodeinfo.ts index b7be19755..82288428c 100644 --- a/packages/backend/src/server/nodeinfo.ts +++ b/packages/backend/src/server/nodeinfo.ts @@ -74,7 +74,7 @@ const nodeinfo2 = async () => { email: meta.maintainerEmail, }, langs: meta.langs, - tosUrl: meta.ToSUrl, + tosUrl: meta.tosUrl, repositoryUrl: meta.repositoryUrl, feedbackUrl: meta.feedbackUrl, disableRegistration: meta.disableRegistration, diff --git a/packages/backend/src/services/drive/add-file.ts b/packages/backend/src/services/drive/add-file.ts index 78a354d21..3071e0abf 100644 --- a/packages/backend/src/services/drive/add-file.ts +++ b/packages/backend/src/services/drive/add-file.ts @@ -99,7 +99,7 @@ async function save( const baseUrl = new URL( meta.objectStorageBaseUrl ?? `/${meta.objectStorageBucket}`, - `${meta.objectStorageUseSSL ? "https" : "http"}://${ + `${meta.objectStorageUseSsl ? "https" : "http"}://${ meta.objectStorageEndpoint }${meta.objectStoragePort ? `:${meta.objectStoragePort}` : ""}`, ); diff --git a/packages/backend/src/services/drive/s3.ts b/packages/backend/src/services/drive/s3.ts index d01f89cbb..2ff3f077e 100644 --- a/packages/backend/src/services/drive/s3.ts +++ b/packages/backend/src/services/drive/s3.ts @@ -6,10 +6,10 @@ import { getAgentByUrl } from "@/misc/fetch.js"; export function getS3(meta: Meta) { const u = meta.objectStorageEndpoint != null - ? `${meta.objectStorageUseSSL ? "https://" : "http://"}${ + ? `${meta.objectStorageUseSsl ? "https://" : "http://"}${ meta.objectStorageEndpoint }` - : `${meta.objectStorageUseSSL ? "https://" : "http://"}example.net`; + : `${meta.objectStorageUseSsl ? "https://" : "http://"}example.net`; try { return new S3({ @@ -17,7 +17,7 @@ export function getS3(meta: Meta) { accessKeyId: meta.objectStorageAccessKey!, secretAccessKey: meta.objectStorageSecretKey!, region: meta.objectStorageRegion || undefined, - sslEnabled: meta.objectStorageUseSSL, + sslEnabled: meta.objectStorageUseSsl, s3ForcePathStyle: !meta.objectStorageEndpoint // AWS with endPoint omitted ? false : meta.objectStorageS3ForcePathStyle,