feat: harden bootstrap and add tests

This commit is contained in:
2026-06-28 16:43:03 -05:00
parent 01ea9e391d
commit 991e73fcff
39 changed files with 3399 additions and 459 deletions
+6 -6
View File
@@ -8,7 +8,7 @@ set -e # Exit on any error
echo "Initializing La Huasca database..."
# Get the postgres pod name
POSTGRES_POD=$(kubectl get pods -n lahuasca | grep postgres | awk '{print $1}')
POSTGRES_POD=$(kubectl get pods -n "${NAMESPACE:-lahuasca}" | grep postgres | awk '{print $1}')
if [ -z "$POSTGRES_POD" ]; then
echo "Error: Could not find postgres pod"
@@ -199,12 +199,12 @@ 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
('admin', '$2a$10$8K1p/a0dhrxiowP.dnkgNORTWgdEDHn5L2/xjpEWuC.QQv4rKO9jO', 'admin')
('admin', '${BOOTSTRAP_ADMIN_PASSWORD_HASH}', 'admin')
ON CONFLICT (username) DO NOTHING;
-- Default config values
INSERT INTO config (key, value) VALUES
('wifi_password', 'LaHuascaGuest2026'),
('wifi_password', '${WIFI_PASSWORD}'),
('tagline', 'Hotel · Restaurant · Andean Highlands')
ON CONFLICT (key) DO NOTHING;
@@ -225,14 +225,14 @@ EOF
# Copy the schema file to the postgres pod
echo "Copying schema to postgres pod..."
kubectl cp /tmp/schema.sql lahuasca/$POSTGRES_POD:/tmp/schema.sql
kubectl cp /tmp/schema.sql "${NAMESPACE:-lahuasca}/$POSTGRES_POD:/tmp/schema.sql"
# Execute the schema
echo "Executing database schema..."
kubectl exec -n lahuasca $POSTGRES_POD -- psql -U lahuasca -d lahuasca -f /tmp/schema.sql
kubectl exec -n "${NAMESPACE:-lahuasca}" "$POSTGRES_POD" -- psql -U "${POSTGRES_USER:-lahuasca}" -d "${POSTGRES_DB:-lahuasca}" -f /tmp/schema.sql
# Verify that the tables were created
echo "Verifying database tables..."
kubectl exec -n lahuasca deploy/postgres -- psql -U lahuasca -d lahuasca -c "\dt"
kubectl exec -n "${NAMESPACE:-lahuasca}" deploy/postgres -- psql -U "${POSTGRES_USER:-lahuasca}" -d "${POSTGRES_DB:-lahuasca}" -c "\dt"
echo "Database initialization completed successfully!"