This commit is contained in:
Daniel Hougaard
2024-02-22 05:00:39 +01:00
parent 0cecf05a5b
commit 6064c393c6
@@ -1,31 +1,37 @@
import { Knex } from "knex"; import { Knex } from "knex";
import { TableName } from "../schemas"; import { ProjectVersion, TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> { export async function up(knex: Knex): Promise<void> {
if (!(await knex.schema.hasColumn(TableName.Users, "ghost"))) { const hasGhostUserColumn = await knex.schema.hasColumn(TableName.Users, "ghost");
const hasProjectVersionColumn = await knex.schema.hasColumn(TableName.Project, "version");
if (!hasGhostUserColumn) {
await knex.schema.alterTable(TableName.Users, (t) => { await knex.schema.alterTable(TableName.Users, (t) => {
t.boolean("ghost").defaultTo(false).notNullable(); t.boolean("ghost").defaultTo(false).notNullable();
}); });
} }
if (!(await knex.schema.hasColumn(TableName.Project, "e2ee"))) { if (!hasProjectVersionColumn) {
await knex.schema.alterTable(TableName.Project, (t) => { await knex.schema.alterTable(TableName.Project, (t) => {
t.boolean("e2ee").defaultTo(true).notNullable(); t.string("version").defaultTo(ProjectVersion.V1).notNullable();
}); });
} }
} }
export async function down(knex: Knex): Promise<void> { export async function down(knex: Knex): Promise<void> {
if (await knex.schema.hasColumn(TableName.Users, "ghost")) { const hasGhostUserColumn = await knex.schema.hasColumn(TableName.Users, "ghost");
const hasProjectVersionColumn = await knex.schema.hasColumn(TableName.Project, "version");
if (hasGhostUserColumn) {
await knex.schema.alterTable(TableName.Users, (t) => { await knex.schema.alterTable(TableName.Users, (t) => {
t.dropColumn("ghost"); t.dropColumn("ghost");
}); });
} }
if (await knex.schema.hasColumn(TableName.Project, "e2ee")) { if (hasProjectVersionColumn) {
await knex.schema.alterTable(TableName.Project, (t) => { await knex.schema.alterTable(TableName.Project, (t) => {
t.dropColumn("e2ee"); t.dropColumn("version");
}); });
} }
} }