littleshop/manual-variant-weight-migration.sql
sysadmin 586d491b83 Add database force upgrade script with config preservation
This commit adds scripts to handle production database migrations that
failed due to schema inconsistencies. The force upgrade script preserves
critical configuration data while recreating the database structure.

Features:
- Exports and preserves SystemSettings (wallet addresses, API keys)
- Preserves Users (admin accounts with passwords)
- Preserves BotRegistrations (Telegram bot configuration)
- Creates timestamped backups before any changes
- Automatic rollback on failure
- Manual SQL migration script as fallback option

Usage:
  bash force-upgrade-production-db.sh

This is safe to use when product catalog data is not critical and
configuration/wallet data must be preserved.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-28 17:15:53 +01:00

25 lines
1.1 KiB
SQL

-- 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);