Files
medical-mall/docs/sql/10_schema/user/ak_user_labels_v1.sql

34 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- =====================================================================================
-- Schema: 用户标签表
-- 位置docs/sql/10_schema/user/ak_user_labels_v1.sql
-- 对象类型Schema (DDL)
-- 版本v1
-- 说明:用户标签定义,支持逻辑删除与状态管理
-- =====================================================================================
CREATE TABLE IF NOT EXISTS public.ak_user_labels (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
color TEXT NULL,
remark TEXT NULL,
status INT NOT NULL DEFAULT 1,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
deleted_at TIMESTAMPTZ NULL,
CONSTRAINT ak_user_labels_name_length CHECK (char_length(name) >= 1)
);
CREATE UNIQUE INDEX IF NOT EXISTS ak_user_labels_name_uniq_active
ON public.ak_user_labels (name)
WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS ak_user_labels_status_idx
ON public.ak_user_labels (status)
WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS ak_user_labels_created_at_idx
ON public.ak_user_labels (created_at DESC);