Skip to content

fix: complete removal of leftover role_level column (#1527)#1530

Open
ignacionelson wants to merge 1 commit into
projectsend:developfrom
ignacionelson:fix/remove-role-level-leftover
Open

fix: complete removal of leftover role_level column (#1527)#1530
ignacionelson wants to merge 1 commit into
projectsend:developfrom
ignacionelson:fix/remove-role-level-leftover

Conversation

@ignacionelson
Copy link
Copy Markdown
Collaborator

Summary

  • Adds database upgrade 2025101501 that completes the removal of the role_level column from tbl_role_permissions
  • Migration 2025092004 was supposed to drop this column, but the ALTER TABLE was wrapped in a try/catch that silently swallowed failures
  • On upgrades from older versions (e.g. r14xx), the column survives as NOT NULL without a default, and the old unique key stays on (role_level, permission) instead of (role_id, permission)

This causes:

SQLSTATE[HY000]: General error: 1364
Field 'role_level' doesn't have a default value

when saving role permissions, since the application code only inserts (role_id, permission, granted).

What the upgrade does

  1. Checks if role_level column still exists (idempotent — no-op if already removed)
  2. Ensures role_id column exists and migrates data if needed
  3. Removes orphan rows where role_id is NULL
  4. Deduplicates (role_id, permission) rows
  5. Drops all indexes that reference role_level
  6. Drops the role_level column (re-throws on failure — this must succeed)
  7. Ensures the correct unique key exists on (role_id, permission)

Test plan

  • Fresh install: upgrade runs without errors (column doesn't exist, early return)
  • Upgrade from r14xx with leftover role_level: column is dropped, permissions work
  • Upgrade from recent version where 2025092004 already succeeded: idempotent no-op

Fixes #1527

…ions

Migration 2025092004 was supposed to drop role_level and re-key the
table to (role_id, permission), but the ALTER TABLE was wrapped in a
try/catch that silently swallowed failures. On upgrades from older
versions (e.g. r14xx), the column and old unique key survive, causing:

  SQLSTATE[HY000]: General error: 1364
  Field 'role_level' doesn't have a default value

This adds an idempotent upgrade that checks for the column, deduplicates
rows, drops old indexes, removes role_level, and ensures the correct
unique key on (role_id, permission).

Fixes projectsend#1527
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: Role permissions error caused by role_level column

1 participant