🚀 Apply missing DB schema changes for qr_code and company_id
This commit is contained in:
42
db-fix.sh
Normal file
42
db-fix.sh
Normal 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!"
|
||||
@@ -61,9 +61,13 @@ ssh $SERVER_USER@$SERVER_IP << EOF
|
||||
\$DOCKER_CMD down --remove-orphans || true
|
||||
|
||||
echo "🏗️ Rebuilding and starting production containers using \$DOCKER_CMD..."
|
||||
\$DOCKER_CMD up -d --build
|
||||
|
||||
echo "🗄️ Running database migrations..."
|
||||
\$DOCKER_CMD build
|
||||
\$DOCKER_CMD up -d
|
||||
|
||||
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
|
||||
else
|
||||
echo "❌ Error: docker-compose.yml not found!"
|
||||
|
||||
Reference in New Issue
Block a user