create_metadata_version_history_table.sql 1.4 KB

12345678910111213141516171819202122232425262728
  1. -- ================================================================
  2. -- 创建 metadata_version_history 表脚本
  3. -- 用于存储元数据版本变更历史(PG审计表)
  4. -- ================================================================
  5. CREATE TABLE IF NOT EXISTS public.metadata_version_history (
  6. id BIGSERIAL PRIMARY KEY,
  7. meta_id BIGINT NOT NULL, -- Neo4j DataMeta 节点ID
  8. change_source VARCHAR(50) NOT NULL DEFAULT 'ddl',
  9. before_snapshot JSONB NOT NULL,
  10. after_snapshot JSONB NOT NULL,
  11. created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  12. created_by VARCHAR(100)
  13. );
  14. CREATE INDEX IF NOT EXISTS idx_metadata_version_history_meta_id
  15. ON public.metadata_version_history(meta_id);
  16. CREATE INDEX IF NOT EXISTS idx_metadata_version_history_created_at
  17. ON public.metadata_version_history(created_at DESC);
  18. COMMENT ON TABLE public.metadata_version_history IS '元数据版本变更历史表(保存变更前后快照)';
  19. COMMENT ON COLUMN public.metadata_version_history.meta_id IS 'Neo4j DataMeta 节点ID';
  20. COMMENT ON COLUMN public.metadata_version_history.change_source IS '变更来源:ddl等';
  21. COMMENT ON COLUMN public.metadata_version_history.before_snapshot IS '变更前快照(jsonb)';
  22. COMMENT ON COLUMN public.metadata_version_history.after_snapshot IS '变更后快照(jsonb)';
  23. COMMENT ON COLUMN public.metadata_version_history.created_by IS '创建人';