feat: 完成 issue #30 ② PostgreSQL 关系表 schema(模板/模型/用户/权限)
This commit is contained in:
@@ -114,3 +114,41 @@ def generate_grant_ddl(
|
||||
f"GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA {schema} TO {role_name};"
|
||||
)
|
||||
return grants
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 模板配置资产加载(issue #30:换行业只改 config/postgres.template.yaml)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def load_postgres_config(path: str) -> dict:
|
||||
"""加载模板配置资产(config/postgres.template.yaml)。"""
|
||||
import yaml
|
||||
|
||||
with open(path, "r", encoding="utf-8") as fh:
|
||||
return yaml.safe_load(fh) or {}
|
||||
|
||||
|
||||
def generate_from_config(
|
||||
path: str,
|
||||
naming: Optional[TemplateNaming] = None,
|
||||
) -> tuple:
|
||||
"""按模板配置生成 PostgreSQL schema DDL 与授权语句。
|
||||
|
||||
Args:
|
||||
path: 模板配置资产路径(config/postgres.template.yaml)。
|
||||
naming: 模板命名器(缺省按资产 template 字段构造)。
|
||||
|
||||
Returns:
|
||||
(schema_ddl, grant_statements):DDL 文本与 GRANT 语句列表。
|
||||
"""
|
||||
raw = load_postgres_config(path)
|
||||
pg = raw.get("postgres", {}) or {}
|
||||
naming = naming or TemplateNaming(template=str(raw.get("template", "default")))
|
||||
ddl = generate_schema_ddl(
|
||||
naming,
|
||||
tables=pg.get("schema_tables") or None,
|
||||
table_columns=None, # 列定义用内核默认,避免与实现漂移
|
||||
)
|
||||
grants = generate_grant_ddl(naming, roles=pg.get("roles") or None)
|
||||
return ddl, grants
|
||||
|
||||
Reference in New Issue
Block a user