Overview
BookMe uses PostgreSQL 14+ as its database. This guide covers database creation, configuration, and running migrations.
Prerequisites
PostgreSQL 14 or higher is required. Earlier versions may not support all features used by BookMe.
Ensure PostgreSQL is installed and running:
# Check PostgreSQL version
psql --version
# Check if PostgreSQL is running
pg_isready
Database Creation
Create Database
Create the bookme database using createdb: Or using psql:
Create Database User (Optional)
For production, create a dedicated database user: CREATE USER bookme WITH PASSWORD 'your-secure-password' ;
GRANT ALL PRIVILEGES ON DATABASE bookme TO bookme;
Verify Connection
Test the database connection: psql -d bookme -c "SELECT version();"
Connection String
Configure your database connection in the .env file:
Development
Production
Docker
# Using default postgres user
DB_URL = postgres://postgres:password@localhost:5432/bookme? sslmode = disable
postgres://[username]:[password]@[host]:[port]/[database]?[parameters]
Component Description Example usernameDatabase user bookmepasswordUser password your-passwordhostDatabase host localhost or db.example.comportPostgreSQL port 5432 (default)databaseDatabase name bookmeparametersQuery parameters sslmode=disable
Use sslmode=disable for local development only. Production should use sslmode=require.
Database Schema
BookMe uses SQL migrations to manage the database schema. The migrations are located in sql/schema/.
Migration Files
sql/schema/
├── 001_users.sql # Users table
├── 002_rooms.sql # Meeting rooms table
├── 003_reservations.sql # Reservations table
└── 004_populate_rooms.sql # Initial room data
Running Migrations
Using Goose (Recommended)
Install Goose
Install the Goose migration tool: go install github.com/pressly/goose/v3/cmd/goose@latest
Run Migrations
Apply all migrations: goose -dir sql/schema postgres "postgres://username:password@localhost:5432/bookme?sslmode=disable" up
Replace the connection string with your actual database credentials.
Verify Migrations
Check migration status: goose -dir sql/schema postgres "your-db-url" status
You should see all migrations marked as applied.
Manual Migration
If you prefer to apply migrations manually:
Apply Migrations in Order
Run each SQL file in sequence: \i sql / schema / 001_users . sql
\i sql / schema / 002_rooms . sql
\i sql / schema / 003_reservations . sql
\i sql / schema / 004_populate_rooms . sql
Verify Tables
List all tables: You should see:
Database Schema Overview
Users Table
Stores user information from 42 Intra OAuth:
CREATE TABLE users (
id UUID PRIMARY KEY ,
email VARCHAR ( 255 ) UNIQUE NOT NULL ,
username VARCHAR ( 100 ) NOT NULL ,
role VARCHAR ( 20 ) NOT NULL ,
created_at TIMESTAMP NOT NULL DEFAULT NOW (),
updated_at TIMESTAMP NOT NULL DEFAULT NOW ()
);
Roles:
student - Can create and cancel own reservations
staff - Can view all reservations and cancel any booking
Rooms Table
Stores available meeting rooms:
CREATE TABLE rooms (
id UUID PRIMARY KEY ,
name VARCHAR ( 100 ) UNIQUE NOT NULL ,
capacity INT NOT NULL ,
created_at TIMESTAMP NOT NULL DEFAULT NOW ()
);
Reservations Table
Stores room reservations:
CREATE TABLE reservations (
id UUID PRIMARY KEY ,
room_id UUID NOT NULL REFERENCES rooms(id),
user_id UUID NOT NULL REFERENCES users(id),
start_time TIMESTAMP NOT NULL ,
end_time TIMESTAMP NOT NULL ,
google_event_id VARCHAR ( 255 ),
created_at TIMESTAMP NOT NULL DEFAULT NOW (),
updated_at TIMESTAMP NOT NULL DEFAULT NOW ()
);
The google_event_id field stores the Google Calendar event ID when a staff member creates a reservation with Calendar sync enabled.
Goose Commands Reference
Check Migration Status
goose -dir sql/schema postgres "your-db-url" status
Apply All Pending Migrations
goose -dir sql/schema postgres "your-db-url" up
Rollback Last Migration
goose -dir sql/schema postgres "your-db-url" down
Reset Database
goose -dir sql/schema postgres "your-db-url" reset
goose reset will drop all tables. Use with caution, especially in production.
Verify Database Setup
After running migrations, verify your setup:
Check Tables
SELECT table_name FROM information_schema . tables
WHERE table_schema = 'public' ;
Expected output:
users
rooms
reservations
goose_db_version (migration tracking)
Check Initial Data
Verify that rooms were populated: SELECT id, name , capacity FROM rooms;
Test Application Connection
Start the BookMe server: Check the logs for successful database connection: INFO database connection established
Database Configuration Tips
Connection Pooling
The application uses Go’s database/sql package with SQLC, which provides built-in connection pooling.
For production deployments, consider:
Indexes : The migrations include indexes on frequently queried columns
Connection Limits : PostgreSQL default is 100 connections
Backup Strategy : Set up regular automated backups
Backup and Restore
Backup
pg_dump -U bookme -d bookme > bookme_backup.sql
Restore
psql -U bookme -d bookme < bookme_backup.sql
Troubleshooting
Connection Refused
Solution: Ensure PostgreSQL is running:
pg_isready
sudo systemctl status postgresql
Authentication Failed
password authentication failed
Solution: Check your credentials in DB_URL. Verify user exists:
Database Does Not Exist
database "bookme" does not exist
Solution: Create the database:
Migration Failed
Solution: Check which migrations are applied:
goose -dir sql/schema postgres "your-db-url" status
Rollback and retry:
goose -dir sql/schema postgres "your-db-url" down
goose -dir sql/schema postgres "your-db-url" up
Next Steps
After setting up your database:
Configure OAuth authentication
Set up email notifications
Start making API calls