From 72bbe22f4e6ba88f0fc8e85946bf7f7d1e5f42d0 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Mon, 20 Apr 2026 10:42:26 +0200 Subject: [PATCH] fix(pangolin): create migration tables before data transfer to prevent role loss The previous migration fix attempted to INSERT INTO 'userOrgRoles' before that table existed (it is new in 1.17.1). The error was silently ignored, so no role data was migrated. When drizzle-kit then dropped roleId from userOrgs, all user-role associations were permanently lost. - CREATE TABLE IF NOT EXISTS for userOrgRoles before migrating data - Same treatment for userInviteRoles (also new in 1.17.1) Fixes community-scripts/ProxmoxVE#13857 --- ct/pangolin.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ct/pangolin.sh b/ct/pangolin.sh index 68be7ca19..765649083 100644 --- a/ct/pangolin.sh +++ b/ct/pangolin.sh @@ -76,8 +76,23 @@ function update_script() { if [[ -f "$DB" ]]; then sqlite3 "$DB" "ALTER TABLE 'orgs' ADD COLUMN 'settingsLogRetentionDaysConnection' integer DEFAULT 0 NOT NULL;" 2>/dev/null || true sqlite3 "$DB" "ALTER TABLE 'clientSitesAssociationsCache' ADD COLUMN 'isJitMode' integer DEFAULT 0 NOT NULL;" 2>/dev/null || true - # Migrate roleId from userOrgs → userOrgRoles before the column is dropped + + # Create new role-mapping tables and migrate data before drizzle-kit + # drops the roleId columns from userOrgs and userInvites. + sqlite3 "$DB" "CREATE TABLE IF NOT EXISTS 'userOrgRoles' ( + 'userId' text NOT NULL REFERENCES 'user'('id') ON DELETE CASCADE, + 'orgId' text NOT NULL REFERENCES 'orgs'('orgId') ON DELETE CASCADE, + 'roleId' integer NOT NULL REFERENCES 'roles'('roleId') ON DELETE CASCADE, + UNIQUE('userId', 'orgId', 'roleId') + );" 2>/dev/null || true sqlite3 "$DB" "INSERT OR IGNORE INTO 'userOrgRoles' (userId, orgId, roleId) SELECT userId, orgId, roleId FROM 'userOrgs' WHERE roleId IS NOT NULL;" 2>/dev/null || true + + sqlite3 "$DB" "CREATE TABLE IF NOT EXISTS 'userInviteRoles' ( + 'inviteId' text NOT NULL REFERENCES 'userInvites'('inviteId') ON DELETE CASCADE, + 'roleId' integer NOT NULL REFERENCES 'roles'('roleId') ON DELETE CASCADE, + PRIMARY KEY('inviteId', 'roleId') + );" 2>/dev/null || true + sqlite3 "$DB" "INSERT OR IGNORE INTO 'userInviteRoles' (inviteId, roleId) SELECT inviteId, roleId FROM 'userInvites' WHERE roleId IS NOT NULL;" 2>/dev/null || true fi ENVIRONMENT=prod $STD npx drizzle-kit push --force --config drizzle.sqlite.config.ts