diff --git a/force-upgrade-production-db.sh b/force-upgrade-production-db.sh new file mode 100644 index 0000000..ea5d685 --- /dev/null +++ b/force-upgrade-production-db.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Force upgrade production database - WARNING: This will DELETE all data! +# Use this script when data is not critical and you need a clean migration + +set -e # Exit on error + +PRODUCTION_DB_PATH="/opt/littleshop/littleshop-production.db" +BACKUP_PATH="/opt/littleshop/backups/littleshop-production-backup-$(date +%Y%m%d_%H%M%S).db" + +echo "🔧 Force Upgrade Production Database" +echo "=====================================" +echo "" +echo "⚠️ WARNING: This will DELETE all existing data!" +echo "📍 Database: $PRODUCTION_DB_PATH" +echo "" + +# Create backups directory if it doesn't exist +mkdir -p /opt/littleshop/backups + +# Backup existing database if it exists +if [ -f "$PRODUCTION_DB_PATH" ]; then + echo "📦 Backing up existing database..." + cp "$PRODUCTION_DB_PATH" "$BACKUP_PATH" + echo "✅ Backup saved to: $BACKUP_PATH" + echo "" +fi + +# Remove old database files +echo "🗑️ Removing old database files..." +rm -f "$PRODUCTION_DB_PATH" +rm -f "${PRODUCTION_DB_PATH}-shm" +rm -f "${PRODUCTION_DB_PATH}-wal" +echo "✅ Old database files removed" +echo "" + +# Apply all migrations to create fresh database +echo "🔄 Applying all migrations..." +cd /opt/littleshop +dotnet ef database update --project LittleShop.csproj + +if [ $? -eq 0 ]; then + echo "" + echo "✅ Database successfully upgraded!" + echo "📋 All migrations applied successfully" + echo "" + echo "📊 Database info:" + echo " Path: $PRODUCTION_DB_PATH" + echo " Backup: $BACKUP_PATH" + echo "" + echo "🎉 Production database is now ready!" +else + echo "" + echo "❌ Migration failed!" + echo "🔄 Restoring from backup..." + cp "$BACKUP_PATH" "$PRODUCTION_DB_PATH" + echo "✅ Backup restored" + exit 1 +fi \ No newline at end of file diff --git a/manual-variant-weight-migration.sql b/manual-variant-weight-migration.sql new file mode 100644 index 0000000..74a5983 --- /dev/null +++ b/manual-variant-weight-migration.sql @@ -0,0 +1,25 @@ +-- Manual migration script for ProductVariant Weight and WeightUnit fields +-- Run this if automated migration fails due to missing ProductVariants table + +-- Check if ProductVariants table exists, if not create it first +CREATE TABLE IF NOT EXISTS "ProductVariants" ( + "Id" TEXT NOT NULL CONSTRAINT "PK_ProductVariants" PRIMARY KEY, + "ProductId" TEXT NOT NULL, + "Name" TEXT NOT NULL, + "VariantType" TEXT NOT NULL DEFAULT 'Standard', + "SortOrder" INTEGER NOT NULL DEFAULT 0, + "IsActive" INTEGER NOT NULL DEFAULT 1, + "StockLevel" INTEGER NOT NULL DEFAULT 0, + "CreatedAt" TEXT NOT NULL, + "UpdatedAt" TEXT NOT NULL, + CONSTRAINT "FK_ProductVariants_Products_ProductId" FOREIGN KEY ("ProductId") REFERENCES "Products" ("Id") ON DELETE CASCADE +); + +-- Add Weight column if it doesn't exist +-- SQLite doesn't have ALTER TABLE ADD COLUMN IF NOT EXISTS, so we need to check first +-- This will fail gracefully if column already exists +ALTER TABLE "ProductVariants" ADD COLUMN "Weight" TEXT NULL; +ALTER TABLE "ProductVariants" ADD COLUMN "WeightUnit" INTEGER NULL; + +-- Verify the columns were added +PRAGMA table_info(ProductVariants); \ No newline at end of file