fix: move user_profiles migration from app-level to core package#672
Open
mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
Open
fix: move user_profiles migration from app-level to core package#672mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
Conversation
The user_profiles table was introduced in upstream PRs SonicJs-Org#508/SonicJs-Org#510 as an app-level migration (my-sonicjs-app/migrations/018_user_profiles.sql), but PR SonicJs-Org#512 added raw SQL queries against it in the core package (admin-users.ts) without a corresponding core migration. This caused 500 errors on the user edit page for any app using @sonicjs-cms/core that hadn't independently applied the app-level migration. - Add core migration 032_user_profiles.sql (IF NOT EXISTS for idempotency) - Add auto-detection in MigrationService for existing tables - Un-skip E2E test 38-user-profile-edit.spec.ts (5 tests) - Add 8 unit tests for user profile query logic on edit/update routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
user_profilestable migration is missing from the core package (packages/core/), causing 500 errors on the admin user edit page (/admin/users/:id/edit) and user update (PUT /admin/users/:id) for any app consuming@sonicjs-cms/core.Root Cause
The table was introduced across three PRs:
user_profilesas an app-level migration (my-sonicjs-app/migrations/018_user_profiles.sql)user_profilesin core (packages/core/src/routes/admin-users.ts) — without adding a core migrationThis means
packages/coredepends on a table it never creates. The E2E test for this feature was permanently skipped with this comment acknowledging the gap:Affected Code Paths
All in
packages/core/src/routes/admin-users.ts:SELECT ... FROM user_profiles WHERE user_id = ?SELECT id FROM user_profiles WHERE user_id = ?UPDATE user_profiles SET ... WHERE user_id = ?INSERT INTO user_profiles (...) VALUES (...)Changes
Core Migration
packages/core/migrations/032_user_profiles.sql— creates theuser_profilestable with the same schema as the app-level migrationCREATE TABLE IF NOT EXISTS/CREATE INDEX IF NOT EXISTS/CREATE TRIGGER IF NOT EXISTSfor idempotency — safe for databases that already have the table from the app-level migrationMigration Auto-Detection
packages/core/src/services/migrations.ts(autoDetectAppliedMigrations()) that checks for existinguser_profilestable and marks migration 032 as applied if foundE2E Tests Un-skipped
test.describe.skip()fromtests/e2e/38-user-profile-edit.spec.tstest.skip()guards inside each test are preserved (runtime safety nets for setup failures, unrelated to migration)Unit Tests Added
packages/core/src/__tests__/routes/admin-users-profile.test.ts— 8 tests covering:Testing
Unit Tests
npx vitest run src/__tests__/routes/admin-users-profile.test.ts)E2E Tests
Technical Details
Files Changed
packages/core/migrations/032_user_profiles.sqlpackages/core/src/services/migrations.tspackages/core/src/db/migrations-bundle.tsnpm run buildto include migration 032tests/e2e/38-user-profile-edit.spec.tstest.describe.skip, kept individual guardspackages/core/src/__tests__/routes/admin-users-profile.test.tsTable Schema
Performance
No performance impact — this migration only runs once during bootstrap. The
IF NOT EXISTSguards make it a no-op for databases that already have the table.Breaking Changes
None. This is additive — it creates a table that was already expected to exist.
Migration Notes
MigrationService.autoDetectAppliedMigrations()will detect the existing table and mark migration 032 as applied without re-running it.Known Issues
None.
Checklist