浏览代码

fix: remove sync_orders and sync_customers from auto_create_store_sync_config function #51

Claude 5 月之前
父节点
当前提交
8ee82ee324
共有 1 个文件被更改,包括 42 次插入0 次删除
  1. 42 0
      supabase/migrations/20251031_193000_fix_auto_create_store_sync_config.sql

+ 42 - 0
supabase/migrations/20251031_193000_fix_auto_create_store_sync_config.sql

@@ -0,0 +1,42 @@
+-- Migration: Fix auto_create_store_sync_config Function
+-- Description: Remove references to dropped sync_orders and sync_customers columns
+-- Date: 2025-10-31
+-- Related Issue: #51
+
+-- ============================================================================
+-- Fix auto_create_store_sync_config Function
+-- ============================================================================
+
+-- This function is automatically triggered when a new store is inserted
+-- It was still trying to insert into sync_orders and sync_customers columns
+-- which were dropped in migration 20251031_160300_drop_customer_order_cache.sql
+
+CREATE OR REPLACE FUNCTION auto_create_store_sync_config()
+RETURNS TRIGGER AS $$
+BEGIN
+  -- Only create config for platforms that support scheduled sync
+  IF NEW.platform_name IN ('woocommerce', 'shoprenter', 'shopify') THEN
+    INSERT INTO store_sync_config (
+      store_id,
+      enabled,
+      sync_frequency,
+      sync_products
+    )
+    VALUES (
+      NEW.id,
+      true,
+      'hourly',
+      true
+    )
+    ON CONFLICT (store_id) DO NOTHING;
+  END IF;
+
+  RETURN NEW;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;
+
+-- Log migration completion
+DO $$
+BEGIN
+  RAISE NOTICE 'Fixed auto_create_store_sync_config function - removed sync_orders and sync_customers columns';
+END $$;