mirror of
https://github.com/spacebarchat/server.git
synced 2024-09-20 09:41:35 +02:00
Fix nullables, fix user settings hanging stuff
This commit is contained in:
parent
95108eedf0
commit
6d9ea1a7bc
@ -19,9 +19,9 @@ make_migration() {
|
|||||||
mkdir "src/util/migrations/$2" 2>/dev/null
|
mkdir "src/util/migrations/$2" 2>/dev/null
|
||||||
# npm run build clean logerrors pretty-errors
|
# npm run build clean logerrors pretty-errors
|
||||||
THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
|
THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
|
||||||
THREADS=1 DATABASE="$1" DB_MIGRATE=a npx typeorm-ts-node-commonjs migration:generate "src/migrations/$2/$FILENAME" -d src/util/util/Database.ts -p
|
THREADS=1 DATABASE="$1" DB_MIGRATE=a npx typeorm-ts-node-commonjs migration:generate "src/util/migrations/$2/$FILENAME" -d src/util/util/Database.ts -p
|
||||||
npm run build clean logerrors pretty-errors
|
#npm run build clean logerrors pretty-errors
|
||||||
THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
|
#THREADS=1 DATABASE="$1" DB_MIGRATE=a npm run start:bundle
|
||||||
}
|
}
|
||||||
|
|
||||||
npm i sqlite3
|
npm i sqlite3
|
||||||
|
@ -105,7 +105,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
if (!user.settings) { //settings may not exist after updating...
|
if (!user.settings) { //settings may not exist after updating...
|
||||||
user.settings = new UserSettings();
|
user.settings = new UserSettings();
|
||||||
user.settings.id = user.id;
|
user.settings.id = user.id;
|
||||||
await user.settings.save();
|
//await (user.settings as UserSettings).save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!identify.intents) identify.intents = "30064771071";
|
if (!identify.intents) identify.intents = "30064771071";
|
||||||
|
@ -97,7 +97,7 @@ export class User extends BaseClass {
|
|||||||
@Column()
|
@Column()
|
||||||
bot: boolean = false; // if user is bot
|
bot: boolean = false; // if user is bot
|
||||||
|
|
||||||
@Column()
|
@Column({ nullable: true })
|
||||||
bio: string; // short description of the user (max 190 chars -> should be configurable)
|
bio: string; // short description of the user (max 190 chars -> should be configurable)
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
@ -106,7 +106,7 @@ export class User extends BaseClass {
|
|||||||
@Column({ select: false })
|
@Column({ select: false })
|
||||||
nsfw_allowed: boolean = true; // if the user can do age-restricted actions (NSFW channels/guilds/commands) // TODO: depending on age
|
nsfw_allowed: boolean = true; // if the user can do age-restricted actions (NSFW channels/guilds/commands) // TODO: depending on age
|
||||||
|
|
||||||
@Column({ select: false })
|
@Column({ select: false, nullable: true })
|
||||||
mfa_enabled: boolean; // if multi factor authentication is enabled
|
mfa_enabled: boolean; // if multi factor authentication is enabled
|
||||||
|
|
||||||
@Column({ select: false, nullable: true })
|
@Column({ select: false, nullable: true })
|
||||||
@ -281,8 +281,8 @@ export class User extends BaseClass {
|
|||||||
settings: { ...new UserSettings(), locale: language }
|
settings: { ...new UserSettings(), locale: language }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//await (user.settings as UserSettings).save();
|
||||||
await user.save();
|
await user.save();
|
||||||
await user.settings.save();
|
|
||||||
|
|
||||||
setImmediate(async () => {
|
setImmediate(async () => {
|
||||||
if (Config.get().guild.autoJoin.enabled) {
|
if (Config.get().guild.autoJoin.enabled) {
|
||||||
|
30
src/util/migrations/mariadb/1660549252130-fix_nullables.ts
Normal file
30
src/util/migrations/mariadb/1660549252130-fix_nullables.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class fixNullables1660549252130 implements MigrationInterface {
|
||||||
|
name = 'fixNullables1660549252130'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
DROP INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\`
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE \`users\` CHANGE \`bio\` \`bio\` varchar(255) NULL
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NOT NULL
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE \`users\` CHANGE \`bio\` \`bio\` varchar(255) NOT NULL
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE UNIQUE INDEX \`IDX_76ba283779c8441fd5ff819c8c\` ON \`users\` (\`settingsId\`)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/util/migrations/postgres/1660549242936-fix_nullables.ts
Normal file
30
src/util/migrations/postgres/1660549242936-fix_nullables.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class fixNullables1660549242936 implements MigrationInterface {
|
||||||
|
name = 'fixNullables1660549242936'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "users"
|
||||||
|
ALTER COLUMN "bio" DROP NOT NULL
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "users"
|
||||||
|
ALTER COLUMN "mfa_enabled" DROP NOT NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "users"
|
||||||
|
ALTER COLUMN "mfa_enabled"
|
||||||
|
SET NOT NULL
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "users"
|
||||||
|
ALTER COLUMN "bio"
|
||||||
|
SET NOT NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
240
src/util/migrations/sqlite/1660549233583-fix_nullables.ts
Normal file
240
src/util/migrations/sqlite/1660549233583-fix_nullables.ts
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class fixNullables1660549233583 implements MigrationInterface {
|
||||||
|
name = 'fixNullables1660549233583'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE TABLE "temporary_users" (
|
||||||
|
"id" varchar PRIMARY KEY NOT NULL,
|
||||||
|
"username" varchar NOT NULL,
|
||||||
|
"discriminator" varchar NOT NULL,
|
||||||
|
"avatar" varchar,
|
||||||
|
"accent_color" integer,
|
||||||
|
"banner" varchar,
|
||||||
|
"phone" varchar,
|
||||||
|
"desktop" boolean NOT NULL,
|
||||||
|
"mobile" boolean NOT NULL,
|
||||||
|
"premium" boolean NOT NULL,
|
||||||
|
"premium_type" integer NOT NULL,
|
||||||
|
"bot" boolean NOT NULL,
|
||||||
|
"bio" varchar,
|
||||||
|
"system" boolean NOT NULL,
|
||||||
|
"nsfw_allowed" boolean NOT NULL,
|
||||||
|
"mfa_enabled" boolean,
|
||||||
|
"totp_secret" varchar,
|
||||||
|
"totp_last_ticket" varchar,
|
||||||
|
"created_at" datetime NOT NULL,
|
||||||
|
"premium_since" datetime,
|
||||||
|
"verified" boolean NOT NULL,
|
||||||
|
"disabled" boolean NOT NULL,
|
||||||
|
"deleted" boolean NOT NULL,
|
||||||
|
"email" varchar,
|
||||||
|
"flags" varchar NOT NULL,
|
||||||
|
"public_flags" integer NOT NULL,
|
||||||
|
"rights" bigint NOT NULL,
|
||||||
|
"data" text NOT NULL,
|
||||||
|
"fingerprints" text NOT NULL,
|
||||||
|
"extended_settings" text NOT NULL,
|
||||||
|
"notes" text NOT NULL,
|
||||||
|
"settingsId" varchar,
|
||||||
|
CONSTRAINT "UQ_b1dd13b6ed980004a795ca184a6" UNIQUE ("settingsId"),
|
||||||
|
CONSTRAINT "FK_76ba283779c8441fd5ff819c8cf" FOREIGN KEY ("settingsId") REFERENCES "user_settings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
INSERT INTO "temporary_users"(
|
||||||
|
"id",
|
||||||
|
"username",
|
||||||
|
"discriminator",
|
||||||
|
"avatar",
|
||||||
|
"accent_color",
|
||||||
|
"banner",
|
||||||
|
"phone",
|
||||||
|
"desktop",
|
||||||
|
"mobile",
|
||||||
|
"premium",
|
||||||
|
"premium_type",
|
||||||
|
"bot",
|
||||||
|
"bio",
|
||||||
|
"system",
|
||||||
|
"nsfw_allowed",
|
||||||
|
"mfa_enabled",
|
||||||
|
"totp_secret",
|
||||||
|
"totp_last_ticket",
|
||||||
|
"created_at",
|
||||||
|
"premium_since",
|
||||||
|
"verified",
|
||||||
|
"disabled",
|
||||||
|
"deleted",
|
||||||
|
"email",
|
||||||
|
"flags",
|
||||||
|
"public_flags",
|
||||||
|
"rights",
|
||||||
|
"data",
|
||||||
|
"fingerprints",
|
||||||
|
"extended_settings",
|
||||||
|
"notes",
|
||||||
|
"settingsId"
|
||||||
|
)
|
||||||
|
SELECT "id",
|
||||||
|
"username",
|
||||||
|
"discriminator",
|
||||||
|
"avatar",
|
||||||
|
"accent_color",
|
||||||
|
"banner",
|
||||||
|
"phone",
|
||||||
|
"desktop",
|
||||||
|
"mobile",
|
||||||
|
"premium",
|
||||||
|
"premium_type",
|
||||||
|
"bot",
|
||||||
|
"bio",
|
||||||
|
"system",
|
||||||
|
"nsfw_allowed",
|
||||||
|
"mfa_enabled",
|
||||||
|
"totp_secret",
|
||||||
|
"totp_last_ticket",
|
||||||
|
"created_at",
|
||||||
|
"premium_since",
|
||||||
|
"verified",
|
||||||
|
"disabled",
|
||||||
|
"deleted",
|
||||||
|
"email",
|
||||||
|
"flags",
|
||||||
|
"public_flags",
|
||||||
|
"rights",
|
||||||
|
"data",
|
||||||
|
"fingerprints",
|
||||||
|
"extended_settings",
|
||||||
|
"notes",
|
||||||
|
"settingsId"
|
||||||
|
FROM "users"
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
DROP TABLE "users"
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "temporary_users"
|
||||||
|
RENAME TO "users"
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`
|
||||||
|
ALTER TABLE "users"
|
||||||
|
RENAME TO "temporary_users"
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE TABLE "users" (
|
||||||
|
"id" varchar PRIMARY KEY NOT NULL,
|
||||||
|
"username" varchar NOT NULL,
|
||||||
|
"discriminator" varchar NOT NULL,
|
||||||
|
"avatar" varchar,
|
||||||
|
"accent_color" integer,
|
||||||
|
"banner" varchar,
|
||||||
|
"phone" varchar,
|
||||||
|
"desktop" boolean NOT NULL,
|
||||||
|
"mobile" boolean NOT NULL,
|
||||||
|
"premium" boolean NOT NULL,
|
||||||
|
"premium_type" integer NOT NULL,
|
||||||
|
"bot" boolean NOT NULL,
|
||||||
|
"bio" varchar NOT NULL,
|
||||||
|
"system" boolean NOT NULL,
|
||||||
|
"nsfw_allowed" boolean NOT NULL,
|
||||||
|
"mfa_enabled" boolean NOT NULL,
|
||||||
|
"totp_secret" varchar,
|
||||||
|
"totp_last_ticket" varchar,
|
||||||
|
"created_at" datetime NOT NULL,
|
||||||
|
"premium_since" datetime,
|
||||||
|
"verified" boolean NOT NULL,
|
||||||
|
"disabled" boolean NOT NULL,
|
||||||
|
"deleted" boolean NOT NULL,
|
||||||
|
"email" varchar,
|
||||||
|
"flags" varchar NOT NULL,
|
||||||
|
"public_flags" integer NOT NULL,
|
||||||
|
"rights" bigint NOT NULL,
|
||||||
|
"data" text NOT NULL,
|
||||||
|
"fingerprints" text NOT NULL,
|
||||||
|
"extended_settings" text NOT NULL,
|
||||||
|
"notes" text NOT NULL,
|
||||||
|
"settingsId" varchar,
|
||||||
|
CONSTRAINT "UQ_b1dd13b6ed980004a795ca184a6" UNIQUE ("settingsId"),
|
||||||
|
CONSTRAINT "FK_76ba283779c8441fd5ff819c8cf" FOREIGN KEY ("settingsId") REFERENCES "user_settings" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
INSERT INTO "users"(
|
||||||
|
"id",
|
||||||
|
"username",
|
||||||
|
"discriminator",
|
||||||
|
"avatar",
|
||||||
|
"accent_color",
|
||||||
|
"banner",
|
||||||
|
"phone",
|
||||||
|
"desktop",
|
||||||
|
"mobile",
|
||||||
|
"premium",
|
||||||
|
"premium_type",
|
||||||
|
"bot",
|
||||||
|
"bio",
|
||||||
|
"system",
|
||||||
|
"nsfw_allowed",
|
||||||
|
"mfa_enabled",
|
||||||
|
"totp_secret",
|
||||||
|
"totp_last_ticket",
|
||||||
|
"created_at",
|
||||||
|
"premium_since",
|
||||||
|
"verified",
|
||||||
|
"disabled",
|
||||||
|
"deleted",
|
||||||
|
"email",
|
||||||
|
"flags",
|
||||||
|
"public_flags",
|
||||||
|
"rights",
|
||||||
|
"data",
|
||||||
|
"fingerprints",
|
||||||
|
"extended_settings",
|
||||||
|
"notes",
|
||||||
|
"settingsId"
|
||||||
|
)
|
||||||
|
SELECT "id",
|
||||||
|
"username",
|
||||||
|
"discriminator",
|
||||||
|
"avatar",
|
||||||
|
"accent_color",
|
||||||
|
"banner",
|
||||||
|
"phone",
|
||||||
|
"desktop",
|
||||||
|
"mobile",
|
||||||
|
"premium",
|
||||||
|
"premium_type",
|
||||||
|
"bot",
|
||||||
|
"bio",
|
||||||
|
"system",
|
||||||
|
"nsfw_allowed",
|
||||||
|
"mfa_enabled",
|
||||||
|
"totp_secret",
|
||||||
|
"totp_last_ticket",
|
||||||
|
"created_at",
|
||||||
|
"premium_since",
|
||||||
|
"verified",
|
||||||
|
"disabled",
|
||||||
|
"deleted",
|
||||||
|
"email",
|
||||||
|
"flags",
|
||||||
|
"public_flags",
|
||||||
|
"rights",
|
||||||
|
"data",
|
||||||
|
"fingerprints",
|
||||||
|
"extended_settings",
|
||||||
|
"notes",
|
||||||
|
"settingsId"
|
||||||
|
FROM "temporary_users"
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
DROP TABLE "temporary_users"
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user