summary refs log tree commit diff
path: root/util/src/migrations/migrate_db_engine.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-10 19:00:50 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-10 19:00:50 +0200
commitc20d87da28b4722cec7b3e478410138c42c183a8 (patch)
tree9ff57e64c23b3d37d0a52de178fa85754abccb05 /util/src/migrations/migrate_db_engine.ts
parent:art: update migration script (diff)
downloadserver-c20d87da28b4722cec7b3e478410138c42c183a8.tar.xz
:bug: fix modify role.permissions
Diffstat (limited to 'util/src/migrations/migrate_db_engine.ts')
-rw-r--r--util/src/migrations/migrate_db_engine.ts131
1 files changed, 0 insertions, 131 deletions
diff --git a/util/src/migrations/migrate_db_engine.ts b/util/src/migrations/migrate_db_engine.ts
deleted file mode 100644

index 527e7b53..00000000 --- a/util/src/migrations/migrate_db_engine.ts +++ /dev/null
@@ -1,131 +0,0 @@ -import { config } from "dotenv"; -config(); -import { BaseEntity, createConnection, EntityTarget } from "typeorm"; -import { initDatabase } from "../util/Database"; -import "missing-native-js-functions"; -import { - Application, - Attachment, - Ban, - Channel, - ConnectedAccount, - defaultSettings, - Emoji, - Guild, - Invite, - Member, - Message, - ReadState, - Recipient, - Relationship, - Role, - Sticker, - Team, - TeamMember, - Template, - User, - VoiceState, - Webhook, -} from ".."; - -async function main() { - if (!process.env.TO) throw new Error("TO database env connection string not set"); - - // manually arrange them because of foreign key - const entities = [ - User, - Guild, - Channel, - Invite, - Role, - Ban, - Application, - Emoji, - ConnectedAccount, - Member, - ReadState, - Recipient, - Relationship, - Sticker, - Team, - TeamMember, - Template, - VoiceState, - Webhook, - Message, - Attachment, - ]; - - const newDB = await initDatabase(); - - const type = process.env.TO.includes("://") ? process.env.TO.split(":")[0]?.replace("+srv", "") : "sqlite"; - const isSqlite = type.includes("sqlite"); - - // @ts-ignore - const oldDB = await createConnection({ - type, - url: isSqlite ? undefined : process.env.TO, - database: isSqlite ? process.env.TO : undefined, - entities, - name: "old", - }); - let i = 0; - - try { - for (const e of entities) { - const entity = e as EntityTarget<any>; - const entries = await oldDB.manager.find(entity); - // @ts-ignore - console.log("migrating " + entries.length + " " + entity.name + " ..."); - - for (const entry of entries) { - console.log(i++); - - if (entry instanceof User) { - if (entry.bio == null) entry.bio = ""; - if (entry.rights == null) entry.rights = "0"; - if (entry.disabled == null) entry.disabled = false; - if (entry.fingerprints == null) entry.fingerprints = []; - if (entry.deleted == null) entry.deleted = false; - if (entry.data == null) { - entry.data = { - valid_tokens_since: new Date(0), - hash: undefined, - }; - // @ts-ignore - if (entry.user_data) { - // TODO: relationships - entry.data = { - // @ts-ignore - valid_tokens_since: entry.user_data.valid_tokens_since, // @ts-ignore - hash: entry.user_data.hash, - }; - } - } - // @ts-ignore - if (entry.settings == null) { - entry.settings = defaultSettings; - // @ts-ignore - if (entry.user_data) entry.settings = entry.user_settings; - } - } - - // try { - await newDB.manager.insert(entity, entry); - // } catch (error) { - // if (!entry.id) throw new Error("object doesn't have a unique id: " + entry); - // await newDB.manager.update(entity, { id: entry.id }, entry); - // } - } - // @ts-ignore - console.log("migrated " + entries.length + " " + entity.name); - } - } catch (error) { - console.error((error as any).message); - } - - console.log("SUCCESS migrated all data"); - await newDB.close(); -} - -main().caught();