Repository navigation
Add mock database command to init.sh - #33
Conversation
Adds `./init.sh dev mock` (and menu option 5), which drops/recreates a separate `liberteis-mock-db` schema in the existing MySQL container and seeds it with a manager user, a normal user, 3 spaces, 3 categories, 3 events and 3 bookings via the existing service layer. The real liberteis-db database is never touched. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
|
@claude Please apart from auto generated admin user, could you put admin@mock.local with password MockPass123! too? |
Adds admin@mock.local / MockPass123! (type adminUser) to the mock database seed, alongside the manager and normal users, per PR review feedback. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
|
Added in 055eade: seeds Generated by Claude Code |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Mock setup can alter real credentials and permissions, and the seed currently fails on its multi-statement query.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Adds a development-only mock MySQL database workflow with reset and seed support.
Changes:
- Adds
scripts/mockSeed.jsandnpm run mock. - Adds
./init.sh dev mockand interactive menu option 5. - Seeds mock users, spaces, categories, events, and bookings.
| File | Review findings |
|---|---|
scripts/mockSeed.js |
Moderate (4 votes): Separate the GRANT and FLUSH PRIVILEGES queries or enable multiple statements. |
package.json |
No findings. |
init.sh |
Moderate (1 vote): Avoid overwriting real database credentials with mock host settings. Critical (1 vote): Do not run real-database permission changes during mock setup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- init.sh: drop grant_mysql_permissions from run_dev_mock — it ran against the real liberteis-db schema/user using real creds, which broke the "never touches the real database" guarantee and could reset the real app user's password. mockSeed.js already grants access on the mock schema itself, as root, so this was redundant. - scripts/mockSeed.js: split the GRANT/FLUSH PRIVILEGES query into two separate queries — mysql2/promise connections have multipleStatements disabled by default, so the combined query aborted every mock reset before seeding could run. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
|
@claude we should, on the login screen, if mock mode is active, show like 3 buttons or something to auto login as admin, manager or user, could we get that? |
- scripts/mockSeed.js writes a mockMode=true config row while seeding. - The config value flows to the frontend through the existing public GET /api/config/ endpoint and configStore (no auth required, so it's readable pre-login). - LoginView.vue conditionally shows three buttons (admin/manager/user) that fill in the mock credentials and submit the login form when mockMode is enabled; hidden otherwise. - Added the new label/button strings to all three locales (en/es/gl). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
|
Added in 468c174:
Generated by Claude Code |
- scripts/mockSeed.js: dbCreateTables() always bootstraps the real admin@lolcat.host account using the production password hash from data/secrets/adminaccount.key. Delete that account right after table creation so the disposable mock database never carries production credential material. - init.sh: run_dev_mock previously only created and seeded the mock schema without ever starting the app against it, so mockMode/the quick-login buttons were unreachable. It now exports MYSQL_DATABASE=liberteis-mock-db and DOTENV_CONFIG_PATH before running `npm run dev`, so the app actually serves the seeded mock data. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
- db/dbController.js: createAdminUser() awaited only the dynamic import()/then() callback, not the addUser() promise it returned from inside the callback, so dbCreateTables() could resolve before the admin row's INSERT finished. That race let scripts/mockSeed.js's new admin-cleanup step run before the real admin@lolcat.host account existed, intermittently leaving the production admin's credentials in the disposable mock database. - scripts/mockSeed.js: isoInDays() set the booking date using local wall-clock hours/minutes but serialized it with toISOString() (UTC), so on any host not running in UTC the seeded bookings landed at the wrong time (or day) relative to what the script intended. Reuses the same local-time formatting bookingsService.js already uses for every other booking write. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
|
Ran a self-review pass on the full diff (3 parallel subagents: correctness, altitude/conventions, cleanup). Two real bugs found and fixed in b0f51a6:
One design-level concern I'm not fixing unilaterally — your call: Generated by Claude Code |
|
on production, that will never happen because it's not on dev mode, on my opinion. maybe we can think about a better way to do it, but, definitely we should avoid that getting into production |
Addresses PR feedback: an admin could previously PUT /api/config
{key:"mockMode", value:"true"} on a real deployment, which would
surface the mock quick-login buttons (with their hardcoded
credentials, always present in the client bundle) on the real login
page. mockMode is now a reserved key rejected by POST/PUT/DELETE
/api/config regardless of caller — it can only be written the way
scripts/mockSeed.js already does, by calling configService directly
and bypassing this router entirely, which only happens when someone
runs `./init.sh dev mock`.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
|
Agreed — added a hard block in f86da4d: Generated by Claude Code |


Summary
./init.sh dev mock(and a new interactive menu option 5) which drops and re-creates a separateliberteis-mock-dbschema inside the existingliberteis-dbMySQL container.userService,spacesService,categoriesService,eventsService,bookingsService) so hashing/validation stay consistent with the app.scripts/mockSeed.js(also runnable vianpm run mockonceDOTENV_CONFIG_PATHpoints at a mock creds file), which refuses to run unless its targetMYSQL_DATABASEis exactlyliberteis-mock-db— a safety check so it can never run against the real database.liberteis-dbschema/credentials/admin account are never touched.Test plan
bash -n init.sh— syntax check passesnode --check scripts/mockSeed.js— syntax check passesnpx prettier --check scripts/mockSeed.js package.json— formatting passes./init.sh dev mockagainst a running dev stack: verifyliberteis-mock-dbis created with seeded users/spaces/categories/events/bookings, and thatliberteis-db(the real schema) is untouched./init.sh dev mocka second time: verify it drops and cleanly recreates the mock schema with no leftover/duplicate rows🤖 Generated with Claude Code
https://claude.ai/code/session_01TUMfbRLzi9LqT3CaGo25gM
Generated by Claude Code