1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-22 02:31:36 +02:00

Merge branch 'master' into pr/TheArcaneBrony/434

This commit is contained in:
Flam3rboy 2021-10-10 19:02:08 +02:00
commit 3c4764fbc8
3 changed files with 23 additions and 47 deletions

View File

@ -2909,6 +2909,9 @@
} }
} }
}, },
"required": [
"image"
],
"definitions": { "definitions": {
"ChannelPermissionOverwriteType": { "ChannelPermissionOverwriteType": {
"enum": [ "enum": [
@ -4744,7 +4747,7 @@
"type": "string" "type": "string"
}, },
"permissions": { "permissions": {
"type": "array" "type": "string"
}, },
"color": { "color": {
"type": "integer" "type": "integer"

View File

@ -17,7 +17,7 @@ const router: Router = Router();
export interface RoleModifySchema { export interface RoleModifySchema {
name?: string; name?: string;
permissions?: bigint; permissions?: string;
color?: number; color?: number;
hoist?: boolean; // whether the role should be displayed separately in the sidebar hoist?: boolean; // whether the role should be displayed separately in the sidebar
mentionable?: boolean; // whether the role should be mentionable mentionable?: boolean; // whether the role should be mentionable
@ -57,7 +57,7 @@ router.post("/", route({ body: "RoleModifySchema", permission: "MANAGE_ROLES" })
...body, ...body,
guild_id: guild_id, guild_id: guild_id,
managed: false, managed: false,
permissions: String(req.permission!.bitfield & (body.permissions || BigInt("0"))), permissions: String(req.permission!.bitfield & BigInt(body.permissions || "0")),
tags: undefined tags: undefined
}); });
@ -109,7 +109,7 @@ router.patch("/:role_id", route({ body: "RoleModifySchema", permission: "MANAGE_
...body, ...body,
id: role_id, id: role_id,
guild_id, guild_id,
permissions: String(req.permission!.bitfield & (body.permissions || BigInt("0"))) permissions: String(req.permission!.bitfield & BigInt(body.permissions || "0"))
}); });
await Promise.all([ await Promise.all([

View File

@ -1,15 +1,14 @@
import { config } from "dotenv"; const { config } = require("dotenv");
config(); config();
import { createConnection, EntityTarget } from "typeorm"; const { createConnection } = require("typeorm");
import { initDatabase } from "../util/Database"; const { initDatabase } = require("../../dist/util/Database");
import "missing-native-js-functions"; require("missing-native-js-functions");
import { const {
Application, Application,
Attachment, Attachment,
Ban, Ban,
Channel, Channel,
ConnectedAccount, ConnectedAccount,
defaultSettings,
Emoji, Emoji,
Guild, Guild,
Invite, Invite,
@ -26,7 +25,7 @@ import {
User, User,
VoiceState, VoiceState,
Webhook, Webhook,
} from ".."; } = require("../../dist/entities/index");
async function main() { async function main() {
if (!process.env.TO) throw new Error("TO database env connection string not set"); if (!process.env.TO) throw new Error("TO database env connection string not set");
@ -72,8 +71,7 @@ async function main() {
let i = 0; let i = 0;
try { try {
for (const e of entities) { for (const entity of entities) {
const entity = e as EntityTarget<any>;
const entries = await oldDB.manager.find(entity); const entries = await oldDB.manager.find(entity);
// @ts-ignore // @ts-ignore
@ -82,48 +80,23 @@ async function main() {
for (const entry of entries) { for (const entry of entries) {
console.log(i++); console.log(i++);
if (entry instanceof User) { try {
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); await newDB.manager.insert(entity, entry);
// } catch (error) { } catch (error) {
// if (!entry.id) throw new Error("object doesn't have a unique id: " + entry); try {
// await newDB.manager.update(entity, { id: entry.id }, entry); if (!entry.id) throw new Error("object doesn't have a unique id: " + entry);
// } await newDB.manager.update(entity, { id: entry.id }, entry);
} catch (error) {
console.error("couldn't migrate " + i + " " + entity.name, error);
}
}
} }
// @ts-ignore // @ts-ignore
console.log("migrated " + entries.length + " " + entity.name); console.log("migrated " + entries.length + " " + entity.name);
} }
} catch (error) { } catch (error) {
console.error((error as any).message); console.error(error.message);
} }
console.log("SUCCESS migrated all data"); console.log("SUCCESS migrated all data");