修改商详情页UI
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE public.ml_user_favorites
|
||||
ALTER COLUMN target_id TYPE TEXT USING target_id::text;
|
||||
|
||||
ALTER TABLE public.ml_user_favorites
|
||||
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;
|
||||
|
||||
UPDATE public.ml_user_favorites
|
||||
SET updated_at = COALESCE(updated_at, created_at, now())
|
||||
WHERE updated_at IS NULL;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.table_constraints
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'ml_user_favorites'
|
||||
AND constraint_name = 'chk_ml_favorite_type'
|
||||
) THEN
|
||||
ALTER TABLE public.ml_user_favorites DROP CONSTRAINT chk_ml_favorite_type;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE public.ml_user_favorites
|
||||
ADD CONSTRAINT chk_ml_favorite_type CHECK (target_type IN (1, 2, 3));
|
||||
|
||||
ALTER TABLE public.ml_user_favorites
|
||||
DROP CONSTRAINT IF EXISTS ml_user_favorites_user_id_target_type_target_id_key;
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS uq_ml_user_favorites_user_target_active
|
||||
ON public.ml_user_favorites(user_id, target_type, target_id)
|
||||
WHERE deleted_at IS NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ml_user_favorites_user_deleted_created
|
||||
ON public.ml_user_favorites(user_id, deleted_at, created_at DESC);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_ml_user_favorites_target_deleted
|
||||
ON public.ml_user_favorites(target_type, target_id, deleted_at);
|
||||
|
||||
COMMENT ON COLUMN public.ml_user_favorites.target_type IS '1=商品 2=店铺 3=服务';
|
||||
COMMENT ON COLUMN public.ml_user_favorites.target_id IS '收藏目标ID,兼容商品UUID、店铺UUID、服务文本ID';
|
||||
COMMENT ON COLUMN public.ml_user_favorites.updated_at IS '更新时间';
|
||||
COMMENT ON COLUMN public.ml_user_favorites.deleted_at IS '软删除时间,NULL为有效收藏';
|
||||
|
||||
ALTER TABLE public.ml_user_favorites ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS ml_user_favorites_select_policy ON public.ml_user_favorites;
|
||||
CREATE POLICY ml_user_favorites_select_policy ON public.ml_user_favorites
|
||||
FOR SELECT
|
||||
USING (
|
||||
deleted_at IS NULL
|
||||
AND auth.uid() = (SELECT auth_id FROM public.ak_users WHERE id = user_id)
|
||||
);
|
||||
|
||||
DROP POLICY IF EXISTS ml_user_favorites_insert_policy ON public.ml_user_favorites;
|
||||
CREATE POLICY ml_user_favorites_insert_policy ON public.ml_user_favorites
|
||||
FOR INSERT
|
||||
WITH CHECK (
|
||||
auth.uid() = (SELECT auth_id FROM public.ak_users WHERE id = user_id)
|
||||
);
|
||||
|
||||
DROP POLICY IF EXISTS ml_user_favorites_update_policy ON public.ml_user_favorites;
|
||||
CREATE POLICY ml_user_favorites_update_policy ON public.ml_user_favorites
|
||||
FOR UPDATE
|
||||
USING (
|
||||
auth.uid() = (SELECT auth_id FROM public.ak_users WHERE id = user_id)
|
||||
)
|
||||
WITH CHECK (
|
||||
auth.uid() = (SELECT auth_id FROM public.ak_users WHERE id = user_id)
|
||||
);
|
||||
|
||||
DROP POLICY IF EXISTS ml_user_favorites_delete_policy ON public.ml_user_favorites;
|
||||
CREATE POLICY ml_user_favorites_delete_policy ON public.ml_user_favorites
|
||||
FOR DELETE
|
||||
USING (
|
||||
auth.uid() = (SELECT auth_id FROM public.ak_users WHERE id = user_id)
|
||||
);
|
||||
|
||||
ALTER TABLE public.hss_service_catalog ENABLE ROW LEVEL SECURITY;
|
||||
|
||||
DROP POLICY IF EXISTS hss_service_catalog_public_select ON public.hss_service_catalog;
|
||||
CREATE POLICY hss_service_catalog_public_select ON public.hss_service_catalog
|
||||
FOR SELECT
|
||||
USING (deleted_at IS NULL AND status = 1);
|
||||
|
||||
DROP POLICY IF EXISTS hss_service_catalog_authenticated_select_all_active_record ON public.hss_service_catalog;
|
||||
CREATE POLICY hss_service_catalog_authenticated_select_all_active_record ON public.hss_service_catalog
|
||||
FOR SELECT TO authenticated
|
||||
USING (deleted_at IS NULL);
|
||||
|
||||
COMMIT;
|
||||
14
mall_sql/migrations/20260603_review_public_profiles.sql
Normal file
14
mall_sql/migrations/20260603_review_public_profiles.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- 为商品评价提供最小公开用户资料视图,避免客户端直接访问 auth.users 或整表 ak_users。
|
||||
|
||||
create or replace view public.ak_user_public_profiles as
|
||||
select
|
||||
id,
|
||||
coalesce(nullif(username, ''), '匿名用户') as username,
|
||||
coalesce(avatar_url, '') as avatar_url
|
||||
from public.ak_users;
|
||||
|
||||
comment on view public.ak_user_public_profiles is '商品评价等前台展示使用的最小公开用户资料视图';
|
||||
|
||||
grant select on public.ak_user_public_profiles to anon;
|
||||
grant select on public.ak_user_public_profiles to authenticated;
|
||||
grant select on public.ak_user_public_profiles to service_role;
|
||||
Reference in New Issue
Block a user