fix: add calendar_events.active, expand seed coverage, and refresh local init script

This commit is contained in:
2026-06-28 22:21:08 -05:00
parent f771ad751b
commit 6121c76d97
3 changed files with 62 additions and 33 deletions
+22 -22
View File
@@ -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!"
echo "Database initialization completed successfully!"