Skip to content

Commit

Permalink
Fix database initialization in staging deployment
Browse files Browse the repository at this point in the history
- Remove transaction handling to fix rollback error
- Add better error handling and reporting
- Add file existence checks
- Add SQL execution validation
  • Loading branch information
screenfluent committed Nov 18, 2024
1 parent 89ef435 commit 5120b4e
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions forge/deploy.staging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 5120b4e

Please sign in to comment.