Compare commits

...

1 Commits

Author SHA1 Message Date
CanbiZ (MickLesk)
72bbe22f4e 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
2026-04-20 10:42:26 +02:00

View File

@@ -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