修改商详情页UI
This commit is contained in:
73
sql/20260603_footprint_soft_delete_and_product_status.sql
Normal file
73
sql/20260603_footprint_soft_delete_and_product_status.sql
Normal file
@@ -0,0 +1,73 @@
|
||||
-- 足迹软删除兼容补丁
|
||||
-- 说明:
|
||||
-- 1. 商品上下架状态直接复用 public.ml_products.status
|
||||
-- 1 = 上架
|
||||
-- 2 = 下架
|
||||
-- 3 = 草稿
|
||||
-- 4 = 删除
|
||||
-- 2. 足迹表兼容两种历史命名:
|
||||
-- public.ml_user_footprints
|
||||
-- public.ml_browse_history
|
||||
|
||||
DO $$
|
||||
DECLARE
|
||||
target_table text;
|
||||
BEGIN
|
||||
FOREACH target_table IN ARRAY ARRAY['ml_user_footprints', 'ml_browse_history']
|
||||
LOOP
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = target_table
|
||||
) THEN
|
||||
EXECUTE format(
|
||||
'ALTER TABLE public.%I ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ',
|
||||
target_table
|
||||
);
|
||||
|
||||
EXECUTE format(
|
||||
'COMMENT ON COLUMN public.%I.deleted_at IS %L',
|
||||
target_table,
|
||||
'软删除时间,NULL 表示有效足迹记录'
|
||||
);
|
||||
|
||||
EXECUTE format(
|
||||
'COMMENT ON COLUMN public.%I.updated_at IS %L',
|
||||
target_table,
|
||||
'最后浏览时间,足迹列表按该字段倒序展示'
|
||||
);
|
||||
|
||||
EXECUTE format(
|
||||
'CREATE INDEX IF NOT EXISTS %I ON public.%I (user_id, updated_at DESC) WHERE deleted_at IS NULL',
|
||||
'idx_' || target_table || '_user_active',
|
||||
target_table
|
||||
);
|
||||
|
||||
EXECUTE format(
|
||||
'CREATE INDEX IF NOT EXISTS %I ON public.%I (user_id, product_id) WHERE deleted_at IS NULL',
|
||||
'idx_' || target_table || '_product_active',
|
||||
target_table
|
||||
);
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM pg_policies
|
||||
WHERE schemaname = 'public'
|
||||
AND tablename = target_table
|
||||
AND policyname = 'Users can update their own footprints'
|
||||
) THEN
|
||||
EXECUTE format(
|
||||
'DROP POLICY "Users can update their own footprints" ON public.%I',
|
||||
target_table
|
||||
);
|
||||
END IF;
|
||||
|
||||
EXECUTE format(
|
||||
'CREATE POLICY "Users can update their own footprints" ON public.%I FOR UPDATE USING (auth.uid() = user_id) WITH CHECK (auth.uid() = user_id)',
|
||||
target_table
|
||||
);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END
|
||||
$$;
|
||||
Reference in New Issue
Block a user