From 8fd99855bdaa4001c6974be6c31b11165ef0a14b Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Fri, 9 Feb 2024 21:23:31 +0400 Subject: [PATCH] Ghost --- .../migrations/20240202093209_ghost_user.ts | 20 ++++++++++++------- backend/src/db/schemas/models.ts | 5 +++++ backend/src/db/schemas/projects.ts | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/backend/src/db/migrations/20240202093209_ghost_user.ts b/backend/src/db/migrations/20240202093209_ghost_user.ts index 7fa23d245..72181cd83 100644 --- a/backend/src/db/migrations/20240202093209_ghost_user.ts +++ b/backend/src/db/migrations/20240202093209_ghost_user.ts @@ -1,31 +1,37 @@ import { Knex } from "knex"; -import { TableName } from "../schemas"; +import { ProjectVersion, TableName } from "../schemas"; export async function up(knex: Knex): Promise { - 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) => { t.boolean("ghost").defaultTo(false).notNullable(); }); } - if (!(await knex.schema.hasColumn(TableName.Project, "e2ee"))) { + if (!hasProjectVersionColumn) { 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 { - 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) => { t.dropColumn("ghost"); }); } - if (await knex.schema.hasColumn(TableName.Project, "e2ee")) { + if (hasProjectVersionColumn) { await knex.schema.alterTable(TableName.Project, (t) => { - t.dropColumn("e2ee"); + t.dropColumn("version"); }); } } diff --git a/backend/src/db/schemas/models.ts b/backend/src/db/schemas/models.ts index e817d6ed0..4109c516c 100644 --- a/backend/src/db/schemas/models.ts +++ b/backend/src/db/schemas/models.ts @@ -112,6 +112,11 @@ export enum SecretType { Personal = "personal" } +export enum ProjectVersion { + V1 = "v1", + V2 = "v2" +} + export enum IdentityAuthMethod { Univeral = "universal-auth" } diff --git a/backend/src/db/schemas/projects.ts b/backend/src/db/schemas/projects.ts index 8c20ca703..fceb18388 100644 --- a/backend/src/db/schemas/projects.ts +++ b/backend/src/db/schemas/projects.ts @@ -15,7 +15,7 @@ export const ProjectsSchema = z.object({ orgId: z.string().uuid(), createdAt: z.date(), updatedAt: z.date(), - e2ee: z.boolean().default(true) + version: z.string().default("v1") }); export type TProjects = z.infer;