Skip to content

Add mock database command to init.sh - #33

Merged
AlexDeveloperUwU merged 7 commits into
v2from
claudio/brave-planck-ngya2b
Sep 24, 2026
Merged

AlexDeveloperUwU merged 7 commits into
v2from
claudio/brave-planck-ngya2b

Conversation

@AlexDeveloperUwU

Copy link
Copy Markdown
Owner

Summary

  • Adds ./init.sh dev mock (and a new interactive menu option 5) which drops and re-creates a separate liberteis-mock-db schema inside the existing liberteis-db MySQL container.
  • Seeds the mock database with a manager user, a normal user, 3 spaces, 3 categories, 3 events and 3 bookings, all created through the existing service layer (userService, spacesService, categoriesService, eventsService, bookingsService) so hashing/validation stay consistent with the app.
  • Seeding is done by a new standalone script, scripts/mockSeed.js (also runnable via npm run mock once DOTENV_CONFIG_PATH points at a mock creds file), which refuses to run unless its target MYSQL_DATABASE is exactly liberteis-mock-db — a safety check so it can never run against the real database.
  • Re-running the command safely wipes and regenerates the mock schema; the real liberteis-db schema/credentials/admin account are never touched.

Test plan

  • bash -n init.sh — syntax check passes
  • node --check scripts/mockSeed.js — syntax check passes
  • npx prettier --check scripts/mockSeed.js package.json — formatting passes
  • ./init.sh dev mock against a running dev stack: verify liberteis-mock-db is created with seeded users/spaces/categories/events/bookings, and that liberteis-db (the real schema) is untouched
  • Re-run ./init.sh dev mock a 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

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

Copy link
Copy Markdown
Owner Author

@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

Copy link
Copy Markdown
Owner Author

Added in 055eade: seeds admin@mock.local / MockPass123! (type adminUser) alongside the manager and normal users.


Generated by Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 1 Medium severity

Open (2)
What changed in this PR

Adds a development-only mock MySQL database workflow with reset and seed support.

Changes:

  • Adds scripts/mockSeed.js and npm run mock.
  • Adds ./init.sh dev mock and 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.

Comment thread init.sh Resolved
Comment thread scripts/mockSeed.js Resolved
- 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
@AlexDeveloperUwU

Copy link
Copy Markdown
Owner Author

@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

Copy link
Copy Markdown
Owner Author

Added in 468c174:

  • mockSeed.js now writes a mockMode=true config row while seeding.
  • It's exposed to the frontend for free through the existing public GET /api/config/ endpoint / configStore (readable pre-login).
  • LoginView.vue shows three buttons (Admin / Manager / User) when mockMode is on, which fill in the mock credentials and submit — hidden entirely against the real database.
  • Added the new strings to all three locales (en/es/gl).

Generated by Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved credential-safety, startup-flow, and mock-seeding issues remain.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (2)

Comment thread scripts/mockSeed.js Resolved
Comment thread init.sh Resolved
- 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

Copy link
Copy Markdown
Owner Author

Ran a self-review pass on the full diff (3 parallel subagents: correctness, altitude/conventions, cleanup). Two real bugs found and fixed in b0f51a6:

  • db/dbController.js — createAdminUser() awaited only the import().then() wrapper, not the addUser() promise inside it, so dbCreateTables() could resolve before the admin row's INSERT finished. That race could let mockSeed.js's new admin-cleanup step run before the real admin@lolcat.host row existed, intermittently leaving the production admin's credentials in the mock database — exactly what that cleanup step was added to prevent.
  • scripts/mockSeed.js — isoInDays() mixed local-time setHours() with toISOString() (UTC) when building booking dates, so on any host not running in UTC, seeded bookings land at the wrong hour (or day). Fixed to format local time like bookingsService.js's own toMySQLDateTime().

One design-level concern I'm not fixing unilaterally — your call: mockMode is a plain row in the shared, remotely-writable config table, and the quick-login buttons + their hardcoded mock credentials ship in every client bundle, including production. Since config is writable via PUT /api/config by any admin, an admin could in principle flip mockMode on in production and the quick-login buttons (with the mock passwords, which are always present in the JS regardless of the flag) would appear on the real login page. If that's a real concern for how this gets deployed, options would be gating it behind a build-time env var instead of a DB-backed config key, or at minimum documenting that mockMode must never be set on a production deployment. Happy to implement either if you want — let me know.


Generated by Claude Code

@AlexDeveloperUwU

Copy link
Copy Markdown
Owner Author

@claude

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

Copy link
Copy Markdown
Owner Author

Agreed — added a hard block in f86da4d: mockMode is now a reserved key in routes/api/configApi.js, rejected with 403 by POST/PUT/DELETE /api/config regardless of who calls it (admin included). It can now only ever be written the way mockSeed.js already does — calling configService directly, bypassing this router entirely — which only happens when someone runs ./init.sh dev mock. So even in the worst case (an admin account on a real deployment), there's no longer any route to flip it on in production.


Generated by Claude Code

@AlexDeveloperUwU
AlexDeveloperUwU marked this pull request as ready for review September 24, 2026 19:05
@AlexDeveloperUwU
AlexDeveloperUwU merged commit a3772fa into v2 Sep 24, 2026
2 checks passed
@AlexDeveloperUwU
AlexDeveloperUwU deleted the claudio/brave-planck-ngya2b branch September 24, 2026 19:05
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.

3 participants