Files
Neo-ZQYY/db/etl_feiqiu/scripts/create_test_db.sql

33 lines
1.4 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.
-- =============================================================================
-- 创建测试数据库 test_etl_feiqiu
-- 结构与生产 etl_feiqiu 完全一致(六层 schemameta/ods/dwd/core/dws/app
-- 用途:开发和测试环境,避免影响生产数据
-- =============================================================================
-- 1. 创建数据库(需要以超级用户或有 CREATEDB 权限的角色执行)
-- 如果数据库已存在,先手动 DROP 或跳过此步
CREATE DATABASE test_etl_feiqiu
WITH ENCODING = 'UTF8'
LC_COLLATE = 'zh_CN.UTF-8'
LC_CTYPE = 'zh_CN.UTF-8'
TEMPLATE = template0;
-- 2. 连接到 test_etl_feiqiu 后,依次执行以下脚本初始化六层 schema
-- 每个脚本包含 CREATE SCHEMA IF NOT EXISTS + 该层所有表定义
--
-- 在 psql 中执行:
-- \c test_etl_feiqiu
-- \i ../schemas/meta.sql
-- \i ../schemas/ods.sql
-- \i ../schemas/dwd.sql
-- \i ../schemas/core.sql
-- \i ../schemas/dws.sql
-- \i ../schemas/app.sql
--
-- 3. 如需加载种子数据,执行 seeds 目录下的脚本:
-- \i ../seeds/*.sql
-- 注意事项:
-- - 生产 schema 变更后需同步在测试库执行相同的迁移脚本Requirements 9.4
-- - 迁移脚本位于 ../migrations/ 目录,按日期前缀顺序执行
-- - app schema 的 RLS 策略在测试库中同样生效,测试时需设置 app.current_site_id