-- ============================================ -- 此文件由 Meoo Cloud 自动生成,请勿修改 -- This file is auto-generated by Meoo Cloud, DO NOT MODIFY -- ============================================ -- 系统配置表 CREATE TABLE IF NOT EXISTS system_configs ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), config_key VARCHAR(100) UNIQUE NOT NULL, config_value JSONB NOT NULL, config_group VARCHAR(50), description TEXT, updated_by UUID, updated_at TIMESTAMPTZ DEFAULT NOW() ); -- 操作日志表 CREATE TABLE IF NOT EXISTS operation_logs ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), operator_id UUID, operator_name VARCHAR(100), operator_role VARCHAR(20), operation_type VARCHAR(50), target_table VARCHAR(50), target_id VARCHAR(50), old_value JSONB, new_value JSONB, ip_address VARCHAR(50), trace_id VARCHAR(100), created_at TIMESTAMPTZ DEFAULT NOW() ); -- 消息通知表 CREATE TABLE IF NOT EXISTS notifications ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID, notify_type VARCHAR(50), title VARCHAR(200), content TEXT, is_read BOOLEAN DEFAULT false, related_order_code VARCHAR(50), created_at TIMESTAMPTZ DEFAULT NOW() ); -- 插入默认系统配置 INSERT INTO system_configs (config_key, config_value, config_group, description) VALUES ('loss_threshold_default', '{"value": 5.0}', 'inventory', '默认损耗阈值'), ('order_abnormal_threshold', '{"value": 0.3}', 'order', '订单异常识别阈值'), ('budget_warning_1', '{"value": 0.8}', 'customer', '预算预警阈值1'), ('budget_warning_2', '{"value": 0.95}', 'customer', '预算预警阈值2'), ('supplier_rating_weights', '{"ontime": 0.3, "quality": 0.3, "price": 0.2, "loss": 0.1, "exception": 0.1}', 'supplier', '供应商评分权重'), ('ai_purchase_tolerance', '{"value": 0.05}', 'ai', 'AI采购容错区间'), ('cost_allocation_method', '{"default": "amount"}', 'cost', '成本分摊方式'); -- 启用RLS ALTER TABLE system_configs ENABLE ROW LEVEL SECURITY; ALTER TABLE operation_logs ENABLE ROW LEVEL SECURITY; ALTER TABLE notifications ENABLE ROW LEVEL SECURITY; -- 匿名访问策略 CREATE POLICY anon_select_system_configs ON system_configs FOR SELECT USING (true); CREATE POLICY anon_select_operation_logs ON operation_logs FOR SELECT USING (true); CREATE POLICY anon_insert_operation_logs ON operation_logs FOR INSERT WITH CHECK (true); CREATE POLICY anon_select_notifications ON notifications FOR SELECT USING (true); CREATE POLICY anon_insert_notifications ON notifications FOR INSERT WITH CHECK (true); CREATE POLICY anon_update_notifications ON notifications FOR UPDATE USING (true);