This guide explains how to initialize the database with dummy data for testing.
-
Spring Boot Auto-Creates Tables: The Spring Boot services automatically create database tables using JPA/Hibernate when they start.
-
Run After Services Start: The dummy data script must be run AFTER all services have started and created their tables.
-
User Passwords: User passwords are hashed using BCrypt. Admin users should be created via API using
setup-admin-user.ps1to ensure correct password hashing. -
Merged File Structure: All dummy data is now in
init-dummy-data.sql(merged file). Separate files (init-dummy-data-catalog.sql,init-dummy-data-policy.sql) are convenience extracts.
init-dummy-data.sql- Merged file containing all sections:- Section 1: Catalog data (resources, amenities) for
catalog_db - Section 2: Policy data (booking policies) for
policy_db - Section 3: Admin user approval for
user_db(user created via API)
- Section 1: Catalog data (resources, amenities) for
init-dummy-data-catalog.sql- Section 1 extract (convenience)init-dummy-data-policy.sql- Section 2 extract (convenience)setup-admin-user.ps1- Unified admin user script (create/approve/fix)init-dummy-data-all.ps1- Automated script to run all initialization
Run the automated PowerShell script that handles everything:
powershell -ExecutionPolicy Bypass -File init-dummy-data-all.ps1This script will:
- Copy SQL files to the container
- Insert catalog data (resources)
- Insert policy data (booking policies)
- Create and approve admin user via API
Since each section targets a different database, run them separately:
1. Catalog Data (catalog_db):
docker cp init-dummy-data-catalog.sql library-postgres:/tmp/init-dummy-data-catalog.sql
docker exec -i library-postgres psql -U postgres -d catalog_db -f /tmp/init-dummy-data-catalog.sql2. Policy Data (policy_db):
docker cp init-dummy-data-policy.sql library-postgres:/tmp/init-dummy-data-policy.sql
docker exec -i library-postgres psql -U postgres -d policy_db -f /tmp/init-dummy-data-policy.sql3. Admin User (user_db - via API):
powershell -ExecutionPolicy Bypass -File setup-admin-user.ps1-
Wait for all services to start:
docker compose ps
Ensure all services show "Up" status.
-
Wait a few seconds for Spring Boot to create tables.
-
Extract and run each section from
init-dummy-data.sql:- Copy Section 1 and run in
catalog_db - Copy Section 2 and run in
policy_db - Use
setup-admin-user.ps1for Section 3
- Copy Section 1 and run in
- Resources: 18 total (6 study rooms, 6 computer stations, 6 seats) + amenities
- Policies: 4 default booking policies (Student, Faculty, Admin, Peak Hours)
- Admin User: 1 hardcoded admin (username:
admin1, password:12345678a) - Bookings: Created dynamically by users through the application
- Notifications: Created dynamically by the system
After running the script, verify data was inserted:
# Check resources
docker exec library-postgres psql -U postgres -d catalog_db -c "SELECT COUNT(*) FROM resources;"
# Check policies
docker exec library-postgres psql -U postgres -d policy_db -c "SELECT COUNT(*) FROM booking_policies;"
# Check admin user
docker exec library-postgres psql -U postgres -d user_db -c "SELECT username, email, role, pending_approval FROM users WHERE username = 'admin1';"The setup-admin-user.ps1 script is a unified tool that replaces multiple admin scripts:
# Full setup (create new or approve existing)
.\setup-admin-user.ps1
# Only approve existing user
.\setup-admin-user.ps1 -ApproveOnly
# Force recreate (delete and create new)
.\setup-admin-user.ps1 -Recreate- "relation does not exist": Services haven't created tables yet. Wait a few more seconds and try again.
- "duplicate key": Data already exists. The scripts use
ON CONFLICT DO NOTHINGandIF NOT EXISTSto prevent duplicates. - Connection refused: PostgreSQL container isn't running. Start it with
docker compose up -d postgres. - "User service is unavailable": Auth service can't reach user service. Check service health with
docker compose psand ensureuser-serviceis healthy.