fix: add calendar_events.active, expand seed coverage, and refresh local init script
This commit is contained in:
+19
-19
@@ -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)
|
||||
-- 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
|
||||
('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!"
|
||||
+3
-1
@@ -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 (
|
||||
|
||||
+32
-5
@@ -186,16 +186,16 @@ export async function initSchema() {
|
||||
);
|
||||
`);
|
||||
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS calendar_events (
|
||||
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
|
||||
);
|
||||
`);
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user