mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 20:52:42 +01:00
added vanity db migration
This commit is contained in:
parent
4b811d3b51
commit
587e0a7120
@ -9,7 +9,7 @@
|
|||||||
"start": "node scripts/build.js && node dist/bundle/src/start.js",
|
"start": "node scripts/build.js && node dist/bundle/src/start.js",
|
||||||
"start:bundle": "node dist/bundle/src/start.js",
|
"start:bundle": "node dist/bundle/src/start.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"migrate": "node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run"
|
"migrate": "cd ../util/ && npm i && node --require ts-node/register node_modules/typeorm/cli.js -f ../util/ormconfig.json migration:run"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
17
util/src/migrations/1633881705509-VanityInvite.ts
Normal file
17
util/src/migrations/1633881705509-VanityInvite.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class VanityInvite1633881705509 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
try {
|
||||||
|
await queryRunner.query(`ALTER TABLE "emojis" DROP COLUMN vanity_url_code`);
|
||||||
|
await queryRunner.query(`ALTER TABLE "emojis" DROP CONSTRAINT FK_c2c1809d79eb120ea0cb8d342ad`);
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "emojis" ADD vanity_url_code varchar`);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "emojis" ADD CONSTRAINT FK_c2c1809d79eb120ea0cb8d342ad FOREIGN KEY ("vanity_url_code") REFERENCES "invites"("code") ON DELETE NO ACTION ON UPDATE NO ACTION`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { config } from "dotenv";
|
import { config } from "dotenv";
|
||||||
config();
|
config();
|
||||||
import { BaseEntity, createConnection, EntityTarget } from "typeorm";
|
import { createConnection, EntityTarget } from "typeorm";
|
||||||
import { initDatabase } from "../util/Database";
|
import { initDatabase } from "../util/Database";
|
||||||
import "missing-native-js-functions";
|
import "missing-native-js-functions";
|
||||||
import {
|
import {
|
||||||
@ -15,7 +15,6 @@ import {
|
|||||||
Invite,
|
Invite,
|
||||||
Member,
|
Member,
|
||||||
Message,
|
Message,
|
||||||
RateLimit,
|
|
||||||
ReadState,
|
ReadState,
|
||||||
Recipient,
|
Recipient,
|
||||||
Relationship,
|
Relationship,
|
||||||
@ -30,9 +29,9 @@ import {
|
|||||||
} from "..";
|
} from "..";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!process.env.FROM) throw new Error("FROM database env connection string not set");
|
if (!process.env.TO) throw new Error("TO database env connection string not set");
|
||||||
|
|
||||||
// manually arrange them because of foreign key
|
// manually arrange them because of foreign keys
|
||||||
const entities = [
|
const entities = [
|
||||||
User,
|
User,
|
||||||
Guild,
|
Guild,
|
||||||
@ -57,12 +56,12 @@ async function main() {
|
|||||||
Attachment,
|
Attachment,
|
||||||
];
|
];
|
||||||
|
|
||||||
const newDB = await initDatabase();
|
const oldDB = await initDatabase();
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const oldDB = await createConnection({
|
const newDB = await createConnection({
|
||||||
type: process.env.FROM.split(":")[0]?.replace("+srv", ""),
|
type: process.env.TO.split(":")[0]?.replace("+srv", ""),
|
||||||
url: process.env.FROM,
|
url: process.env.TO,
|
||||||
entities,
|
entities,
|
||||||
name: "old",
|
name: "old",
|
||||||
});
|
});
|
||||||
@ -73,13 +72,12 @@ async function main() {
|
|||||||
const entity = e as EntityTarget<any>;
|
const entity = e as EntityTarget<any>;
|
||||||
const entries = await oldDB.manager.find(entity);
|
const entries = await oldDB.manager.find(entity);
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
console.log("migrated " + entries.length + " " + entity.name);
|
console.log("migrating " + entries.length + " " + entity.name + " ...");
|
||||||
|
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
console.log(i++);
|
console.log(i++);
|
||||||
|
|
||||||
if (entry instanceof User) {
|
if (entry instanceof User) {
|
||||||
console.log("instance of User");
|
|
||||||
if (entry.bio == null) entry.bio = "";
|
if (entry.bio == null) entry.bio = "";
|
||||||
if (entry.rights == null) entry.rights = "0";
|
if (entry.rights == null) entry.rights = "0";
|
||||||
if (entry.disabled == null) entry.disabled = false;
|
if (entry.disabled == null) entry.disabled = false;
|
||||||
@ -115,8 +113,9 @@ async function main() {
|
|||||||
// await newDB.manager.update(entity, { id: entry.id }, entry);
|
// await newDB.manager.update(entity, { id: entry.id }, entry);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
console.log("migrated all " + entity.name);
|
console.log("migrating " + entries.length + " " + entity.name + " ...");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error((error as any).message);
|
console.error((error as any).message);
|
||||||
|
Loading…
Reference in New Issue
Block a user