From 5120b4e62b1770f7a88cd18199b43e519f27f788 Mon Sep 17 00:00:00 2001 From: Szymon <04_barista_pads@icloud.com> Date: Mon, 18 Nov 2024 10:14:51 +0100 Subject: [PATCH] Fix database initialization in staging deployment - Remove transaction handling to fix rollback error - Add better error handling and reporting - Add file existence checks - Add SQL execution validation --- forge/deploy.staging.sh | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/forge/deploy.staging.sh b/forge/deploy.staging.sh index aceb18a..83ec4f8 100644 --- a/forge/deploy.staging.sh +++ b/forge/deploy.staging.sh @@ -3,15 +3,22 @@ # Enable error reporting set -e -# Configure git -git config --global --add safe.directory /home/stagingllmstxtdirectory/staging.llmstxt.directory - -# Update repository +# Change to the correct directory first cd /home/stagingllmstxtdirectory/staging.llmstxt.directory -# Initial git setup - more resilient approach -git fetch --all --prune -git reset --hard origin/staging # Force align with remote staging branch +# Clear any cached git configs +rm -f ~/.gitconfig +rm -rf .git +rm -rf * + +# Reinitialize git +git init +git config --global --add safe.directory /home/stagingllmstxtdirectory/staging.llmstxt.directory +git remote add origin https://github.com/screenfluent/llmstxtdirectory.git + +# Fetch and reset to staging branch +git fetch origin staging +git checkout -f -b staging --track origin/staging # Set permissions chown -R stagingllmstxtdirectory:stagingllmstxtdirectory . @@ -39,15 +46,25 @@ echo "Initializing database with fresh schema and sample data..." php -r " require_once 'db/database.php'; \$db = new Database(); - \$schema = file_get_contents('db/schema.sql'); - \$db->db->exec('BEGIN TRANSACTION;'); + try { - \$db->db->exec(\$schema); + // Initialize schema + \$schema = file_get_contents('db/schema.sql'); + if (\$schema === false) { + throw new Exception('Could not read schema.sql'); + } + + // Execute schema + \$result = \$db->db->exec(\$schema); + if (\$result === false) { + throw new Exception('Failed to execute schema: ' . \$db->db->lastErrorMsg()); + } + + // Initialize sample data require_once 'db/init.php'; - \$db->db->exec('COMMIT;'); + echo \"Database initialized successfully.\n\"; } catch (Exception \$e) { - \$db->db->exec('ROLLBACK;'); echo \"Error initializing database: \" . \$e->getMessage() . \"\n\"; exit(1); }