refactor(core): Add addColumns and dropColumns to the migrations DSL (no-changelog) (#7073)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-09-01 15:19:49 +02:00
committed by GitHub
parent 51093f649d
commit 97f87ae0fc
7 changed files with 69 additions and 83 deletions

View File

@@ -1,26 +1,14 @@
import type { MigrationContext, ReversibleMigration } from '@db/types';
import { TableColumn } from 'typeorm';
export class RemoveResetPasswordColumns1690000000030 implements ReversibleMigration {
async up({ queryRunner, tablePrefix }: MigrationContext) {
await queryRunner.dropColumns(`${tablePrefix}user`, [
'resetPasswordToken',
'resetPasswordTokenExpiration',
]);
async up({ schemaBuilder: { dropColumns } }: MigrationContext) {
await dropColumns('user', ['resetPasswordToken', 'resetPasswordTokenExpiration']);
}
async down({ queryRunner, tablePrefix }: MigrationContext) {
await queryRunner.addColumns(`${tablePrefix}user`, [
new TableColumn({
name: 'resetPasswordToken',
type: 'varchar',
isNullable: true,
}),
new TableColumn({
name: 'resetPasswordTokenExpiration',
type: 'int',
isNullable: true,
}),
async down({ schemaBuilder: { addColumns, column } }: MigrationContext) {
await addColumns('user', [
column('resetPasswordToken').varchar(),
column('resetPasswordTokenExpiration').int,
]);
}
}

View File

@@ -1,35 +1,15 @@
import type { MigrationContext, ReversibleMigration } from '@/databases/types';
import { TableColumn } from 'typeorm';
export class AddMfaColumns1690000000030 implements ReversibleMigration {
async up({ queryRunner, tablePrefix }: MigrationContext) {
await queryRunner.addColumns(`${tablePrefix}user`, [
new TableColumn({
name: 'mfaEnabled',
type: 'boolean',
isNullable: false,
default: false,
}),
new TableColumn({
name: 'mfaSecret',
type: 'text',
isNullable: true,
default: null,
}),
new TableColumn({
name: 'mfaRecoveryCodes',
type: 'text',
isNullable: true,
default: null,
}),
async up({ schemaBuilder: { addColumns, column } }: MigrationContext) {
await addColumns('user', [
column('mfaEnabled').bool.notNull.default(false),
column('mfaSecret').text,
column('mfaRecoveryCodes').text,
]);
}
async down({ queryRunner, tablePrefix }: MigrationContext) {
await queryRunner.dropColumns(`${tablePrefix}user`, [
'mfaEnabled',
'mfaSecret',
'mfaRecoveryCodes',
]);
async down({ schemaBuilder: { dropColumns } }: MigrationContext) {
await dropColumns('user', ['mfaEnabled', 'mfaSecret', 'mfaRecoveryCodes']);
}
}