diff --git a/server/setup/scriptsPg/1.22.0.ts b/server/setup/scriptsPg/1.22.0.ts index e6ddcf750..7ca68a530 100644 --- a/server/setup/scriptsPg/1.22.0.ts +++ b/server/setup/scriptsPg/1.22.0.ts @@ -1,3 +1,4 @@ +import { build } from "@server/build"; import { db } from "@server/db/pg/driver"; import { APP_PATH } from "@server/lib/consts"; import { sql } from "drizzle-orm"; @@ -201,6 +202,23 @@ export default async function migration() { await db.execute( sql`ALTER TABLE "roles" ALTER COLUMN "sshSudoMode" SET DEFAULT 'full';` ); + + const licenseKeyCountQuery = await db.execute( + sql`SELECT COUNT(*)::int as count FROM "licenseKey";` + ); + const licenseKeyCount = licenseKeyCountQuery.rows[0] as { + count: number; + }; + + if ( + build === "oss" || + (build === "enterprise" && licenseKeyCount.count === 0) + ) { + await db.execute( + sql`UPDATE "roles" SET "sshSudoMode" = 'full' WHERE "sshSudoMode" = 'none';` + ); + } + await db.execute( sql`ALTER TABLE "targets" ALTER COLUMN "resourceId" DROP NOT NULL;` ); diff --git a/server/setup/scriptsSqlite/1.22.0.ts b/server/setup/scriptsSqlite/1.22.0.ts index 16a124ef9..853693eee 100644 --- a/server/setup/scriptsSqlite/1.22.0.ts +++ b/server/setup/scriptsSqlite/1.22.0.ts @@ -1,3 +1,4 @@ +import { build } from "@server/build"; import { APP_PATH } from "@server/lib/consts"; import Database from "better-sqlite3"; import fs from "fs"; @@ -343,6 +344,19 @@ export default async function migration() { `ALTER TABLE 'roles' RENAME COLUMN "sshSudoModeNew" TO "sshSudoMode";` ).run(); + const licenseKeyCount = db + .prepare(`SELECT COUNT(*) as count FROM 'licenseKey';`) + .get() as { count: number }; + + if ( + build === "oss" || + (build === "enterprise" && licenseKeyCount.count === 0) + ) { + db.prepare( + `UPDATE 'roles' SET "sshSudoMode" = 'full' WHERE "sshSudoMode" = 'none';` + ).run(); + } + db.prepare( ` CREATE TABLE '__new_targets' (