From 6121c76d97de8bcff8437454afa6adfe2fcc4b52 Mon Sep 17 00:00:00 2001 From: muken Date: Sun, 28 Jun 2026 22:21:08 -0500 Subject: [PATCH] fix: add calendar_events.active, expand seed coverage, and refresh local init script --- init-db-local.sh | 44 ++++++++++++++++++++++---------------------- init-db.sh | 4 +++- src/lib/schema.ts | 47 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 62 insertions(+), 33 deletions(-) diff --git a/init-db-local.sh b/init-db-local.sh index b52efc4..a48cdbe 100755 --- a/init-db-local.sh +++ b/init-db-local.sh @@ -1,14 +1,8 @@ #!/bin/bash - -# Database initialization script for La Huasca (local version) -# This script creates the necessary tables and seeds initial data - -set -e # Exit on any error +set -e echo "Initializing La Huasca database (local version)..." -# Execute the schema directly -echo "Executing database schema..." sudo -u postgres psql -d lahuasca << 'EOF' -- Create all tables CREATE TABLE IF NOT EXISTS users ( @@ -171,7 +165,9 @@ CREATE TABLE IF NOT EXISTS calendar_events ( title VARCHAR(255) NOT NULL, type VARCHAR(100) NOT NULL, description TEXT, - color VARCHAR(20) NOT NULL + color VARCHAR(20) NOT NULL, + active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS user_sessions ( @@ -181,31 +177,37 @@ CREATE TABLE IF NOT EXISTS user_sessions ( created_at TIMESTAMP DEFAULT NOW() ); --- Add missing columns if they don't exist +CREATE TABLE IF NOT EXISTS availability ( + id SERIAL PRIMARY KEY, + room_id INTEGER REFERENCES rooms(id) ON DELETE CASCADE, + date DATE NOT NULL, + status VARCHAR(20) NOT NULL DEFAULT 'available' CHECK (status IN ('available', 'booked', 'maintenance')), + price NUMERIC(10,2), + created_at TIMESTAMP DEFAULT NOW(), + UNIQUE(room_id, date) +); + +-- Add missing columns ALTER TABLE rooms ADD COLUMN IF NOT EXISTS featured_photo VARCHAR(500); ALTER TABLE users ADD COLUMN IF NOT EXISTS comments_disabled BOOLEAN DEFAULT FALSE; ALTER TABLE users ADD COLUMN IF NOT EXISTS first_name VARCHAR(100); ALTER TABLE users ADD COLUMN IF NOT EXISTS last_name VARCHAR(100); --- Insert initial data --- Default admin user (password: admin) -INSERT INTO users (username, password_hash, role) VALUES +-- Seed initial data +INSERT INTO users (username, password_hash, role) VALUES ('admin', '$2a$10$8K1p/a0dhrxiowP.dnkgNORTWgdEDHn5L2/xjpEWuC.QQv4rKO9jO', 'admin') ON CONFLICT (username) DO NOTHING; --- Default config values -INSERT INTO config (key, value) VALUES +INSERT INTO config (key, value) VALUES ('wifi_password', 'LaHuascaGuest2026'), ('tagline', 'Hotel · Restaurant · Andean Highlands') ON CONFLICT (key) DO NOTHING; --- Sample offers -INSERT INTO offers (title, description, active, sort_order) VALUES - ('Summer Wine Weekend', 'Complimentary wine tasting with every two-night stay.', true, 1), - ('Sunset Dinner', 'Three-course menu on the terrace every Friday.', true, 2) +INSERT INTO offers (title, description) VALUES + ('Summer Wine Weekend', 'Complimentary wine tasting with every two-night stay.'), + ('Sunset Dinner', 'Three-course menu on the terrace every Friday.') ON CONFLICT DO NOTHING; --- Sample benefits INSERT INTO benefits (text) VALUES ('Priority booking for peak weekends'), ('Late checkout on availability'), @@ -214,8 +216,6 @@ INSERT INTO benefits (text) VALUES ON CONFLICT DO NOTHING; EOF -# Verify that the tables were created echo "Verifying database tables..." sudo -u postgres psql -d lahuasca -c "\dt" - -echo "Database initialization completed successfully!" \ No newline at end of file +echo "Database initialization completed successfully!" diff --git a/init-db.sh b/init-db.sh index a85c50d..75b085f 100755 --- a/init-db.sh +++ b/init-db.sh @@ -180,7 +180,9 @@ CREATE TABLE IF NOT EXISTS calendar_events ( title VARCHAR(255) NOT NULL, type VARCHAR(100) NOT NULL, description TEXT, - color VARCHAR(20) NOT NULL + color VARCHAR(20) NOT NULL, + active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT NOW() ); CREATE TABLE IF NOT EXISTS user_sessions ( diff --git a/src/lib/schema.ts b/src/lib/schema.ts index feeb09b..152357a 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -186,16 +186,16 @@ export async function initSchema() { ); `); - await db.query(` - CREATE TABLE IF NOT EXISTS calendar_events ( - id SERIAL PRIMARY KEY, - date DATE NOT NULL UNIQUE, - title VARCHAR(255) NOT NULL, - type VARCHAR(100) NOT NULL, - description TEXT, - color VARCHAR(20) NOT NULL - ); - `); + await db.query(`CREATE TABLE IF NOT EXISTS calendar_events ( + id SERIAL PRIMARY KEY, + date DATE NOT NULL UNIQUE, + title VARCHAR(255) NOT NULL, + type VARCHAR(100) NOT NULL, + description TEXT, + color VARCHAR(20) NOT NULL, + active BOOLEAN DEFAULT TRUE, + created_at TIMESTAMP DEFAULT NOW() + );`); await db.query(` CREATE TABLE IF NOT EXISTS user_sessions ( @@ -314,6 +314,33 @@ export async function seed() { if (configTaglineRows.length === 0) { await db.query(`INSERT INTO config (key, value) VALUES ($1, $2)`, ['tagline', tagline]); } + + const { rows: calendarRows } = await db.query(`SELECT id FROM calendar_events`); + if (calendarRows.length === 0) { + await db.query( + `INSERT INTO calendar_events (date, title, type, description, color, active) VALUES ($1, $2, $3, $4, $5, $6)`, + ['2026-06-30', 'Welcome Dinner', 'event', 'Andean tasting menu', '#b45309', true] + ); + } + + const { rows: socialRows } = await db.query(`SELECT id FROM social_events`); + if (socialRows.length === 0) { + await db.query( + `INSERT INTO social_events (name, description, price, date, photos, featured_photo, active, sort_order) VALUES ($1, $2, $3, $4, '{}', null, $5, $6)`, + ['Sunset Tasting', 'Local wines on the terrace.', 'USD 35', '2026-07-04', true, 1] + ); + } + + const { rows: socialReservationRows } = await db.query(`SELECT id FROM social_event_reservations`); + if (socialReservationRows.length === 0) { + const { rows: adminIdRows } = await db.query(`SELECT id FROM users WHERE username = 'admin'`); + if (adminIdRows.length > 0) { + await db.query( + `INSERT INTO social_event_reservations (user_id, social_event_id, guests, notes, status) SELECT $1, id, $2, $3, $4 FROM social_events LIMIT 1`, + [adminIdRows[0].id, 2, 'Anniversary', 'confirmed'] + ); + } + } } export async function resetDatabase() {