add
This commit is contained in:
46
infra/postgres/sql/03_create_table.sql
Normal file
46
infra/postgres/sql/03_create_table.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
-- =========================================================
|
||||
-- trading_records.sql (PostgreSQL 17.4+)
|
||||
-- =========================================================
|
||||
\pset pager off
|
||||
\timing on
|
||||
\c postgres;
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS "moddatetime" SCHEMA public;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
RAISE NOTICE '🚀============ 数据库表部署开始 ============🚀';
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = 'cn_futures_trading_records'
|
||||
) THEN
|
||||
CREATE TABLE cn_futures_trading_records (
|
||||
id UUID DEFAULT gen_random_uuid() PRIMARY KEY, -- id
|
||||
payload JSONB NOT NULL, -- 数据
|
||||
deleted BOOLEAN NOT NULL DEFAULT FALSE, -- 删除状态
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 记录创建时间
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP -- 记录修改时间
|
||||
);
|
||||
|
||||
-- 3 触发器:自动刷新 updated_at
|
||||
CREATE TRIGGER trg_cn_futures_trading_records_updated_at
|
||||
BEFORE UPDATE ON cn_futures_trading_records
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION moddatetime(updated_at);
|
||||
|
||||
RAISE NOTICE 'cn_futures_trading_records 表已创建';
|
||||
ELSE
|
||||
RAISE NOTICE 'cn_futures_trading_records 表已存在,跳过';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
RAISE NOTICE '============ 数据库表部署完成 ============';
|
||||
END $$;
|
||||
Reference in New Issue
Block a user