🚀 Apply missing DB schema changes for qr_code and company_id

This commit is contained in:
Hamza-Ayed
2026-04-22 01:37:53 +03:00
parent 4cfa65364e
commit 31022da057
2 changed files with 49 additions and 3 deletions

42
db-fix.sh Normal file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
echo "🛠️ Applying manual schema updates to PostgreSQL..."
DOCKER_CMD="docker compose"
if ! docker compose version > /dev/null 2>&1; then
DOCKER_CMD="docker-compose"
fi
DB_CONTAINER=$($DOCKER_CMD ps -q db)
if [ -z "$DB_CONTAINER" ]; then
echo "❌ Database container is not running!"
exit 1
fi
if [ -f ".env" ]; then
source .env
else
echo "⚠️ .env file not found. Using default values..."
DB_USER="musadaq_user"
DB_NAME="musadaq_db"
fi
echo "📦 Database container found. Executing ALTER statements..."
docker exec -i $DB_CONTAINER psql -U $DB_USER -d $DB_NAME <<EOF
-- Add missing columns to User
ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "company_id" uuid;
-- Add missing columns to Invoice
ALTER TABLE "invoices" ADD COLUMN IF NOT EXISTS "qr_code" text;
ALTER TABLE "invoices" ADD COLUMN IF NOT EXISTS "ai_confidence_score" numeric(4,3);
-- Add missing columns to Company
ALTER TABLE "companies" ADD COLUMN IF NOT EXISTS "certificate_path" varchar(255);
ALTER TABLE "companies" ADD COLUMN IF NOT EXISTS "certificate_password_encrypted" varchar(500);
EOF
echo "✅ Schema updates applied successfully!"

View File

@@ -61,9 +61,13 @@ ssh $SERVER_USER@$SERVER_IP << EOF
\$DOCKER_CMD down --remove-orphans || true \$DOCKER_CMD down --remove-orphans || true
echo "🏗️ Rebuilding and starting production containers using \$DOCKER_CMD..." echo "🏗️ Rebuilding and starting production containers using \$DOCKER_CMD..."
\$DOCKER_CMD up -d --build \$DOCKER_CMD build
\$DOCKER_CMD up -d
echo "🗄️ Running database migrations..." echo "🗄️ Applying manual database schema fixes..."
bash db-fix.sh
echo "🗄️ Running TypeORM migrations (if any)..."
\$DOCKER_CMD exec -T api npm run migration:run:prod \$DOCKER_CMD exec -T api npm run migration:run:prod
else else
echo "❌ Error: docker-compose.yml not found!" echo "❌ Error: docker-compose.yml not found!"