From df045ac9f069cafab01a90236fc862fbdb115773 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Wed, 1 Jul 2026 00:07:34 +0800 Subject: [PATCH] Fix merge errors --- backend/cli.py | 9 +++++++-- .../notice/sql/mysql/init_snowflake_tenant.sql | 2 +- .../sql/postgresql/init_snowflake_tenant.sql | 2 +- backend/plugin/sql.py | 16 +++++++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/backend/cli.py b/backend/cli.py index d3678916..323d5094 100644 --- a/backend/cli.py +++ b/backend/cli.py @@ -409,7 +409,7 @@ async def install_plugin( # noqa: C901 await conn.run_sync(MappedBase.metadata.create_all) if not no_sql: - sql_file = await get_plugin_sql(plugin_name, db_type, pk_type) + sql_file = await get_plugin_sql(plugin_name, db_type, pk_type, tenant=settings.TENANT_ENABLED) if sql_file: console.info(f'正在执行插件 {plugin_name} 初始化 SQL 脚本:{sql_file}') async with async_db_session.begin() as db: @@ -551,7 +551,12 @@ async def get_sql_scripts() -> list[str]: plugins.append(PluginEntry(name=plugin, depends_on=plugin_config['plugin'].get('depends_on'))) for plugin in resolve_plugin_order(plugins): - plugin_sql = await get_plugin_sql(plugin.name, settings.DATABASE_TYPE, settings.DATABASE_PK_MODE) + plugin_sql = await get_plugin_sql( + plugin.name, + settings.DATABASE_TYPE, + settings.DATABASE_PK_MODE, + tenant=settings.TENANT_ENABLED, + ) if plugin_sql: sql_scripts.append(plugin_sql) diff --git a/backend/plugin/notice/sql/mysql/init_snowflake_tenant.sql b/backend/plugin/notice/sql/mysql/init_snowflake_tenant.sql index 7d0d1831..7a90e1ec 100644 --- a/backend/plugin/notice/sql/mysql/init_snowflake_tenant.sql +++ b/backend/plugin/notice/sql/mysql/init_snowflake_tenant.sql @@ -7,7 +7,7 @@ values (2049629108257816578, '修改', 'EditNotice', null, 0, null, 2, null, 'sys:notice:edit', 1, 0, 1, '', null, 2049629108257816576, now(), null), (2049629108257816579, '删除', 'DeleteNotice', null, 0, null, 2, null, 'sys:notice:del', 1, 0, 1, '', null, 2049629108257816576, now(), null); -insert into sys_notice (id, title, type, status, content, created_time, updated_time) +insert into sys_notice (id, title, type, status, content, created_time, updated_time, tenant_id) values (2112248797756129280, 'hahahahahaahahaha', 0, 1, '你好😄 ``` diff --git a/backend/plugin/notice/sql/postgresql/init_snowflake_tenant.sql b/backend/plugin/notice/sql/postgresql/init_snowflake_tenant.sql index 7d0d1831..7a90e1ec 100644 --- a/backend/plugin/notice/sql/postgresql/init_snowflake_tenant.sql +++ b/backend/plugin/notice/sql/postgresql/init_snowflake_tenant.sql @@ -7,7 +7,7 @@ values (2049629108257816578, '修改', 'EditNotice', null, 0, null, 2, null, 'sys:notice:edit', 1, 0, 1, '', null, 2049629108257816576, now(), null), (2049629108257816579, '删除', 'DeleteNotice', null, 0, null, 2, null, 'sys:notice:del', 1, 0, 1, '', null, 2049629108257816576, now(), null); -insert into sys_notice (id, title, type, status, content, created_time, updated_time) +insert into sys_notice (id, title, type, status, content, created_time, updated_time, tenant_id) values (2112248797756129280, 'hahahahahaahahaha', 0, 1, '你好😄 ``` diff --git a/backend/plugin/sql.py b/backend/plugin/sql.py index 24d9a583..89eaaedc 100644 --- a/backend/plugin/sql.py +++ b/backend/plugin/sql.py @@ -9,6 +9,7 @@ def build_sql_filename( pk_type: PrimaryKeyType, *, suffix: str | None = None, + tenant: bool = False, ) -> str: """ 构建插件 SQL 脚本文件名 @@ -23,10 +24,18 @@ def build_sql_filename( parts.append('snowflake') if suffix: parts.append(suffix) + if tenant: + parts.append('tenant') return f'{"_".join(parts)}.sql' -async def get_plugin_sql(plugin: str, db_type: DataBaseType, pk_type: PrimaryKeyType) -> str | None: +async def get_plugin_sql( + plugin: str, + db_type: DataBaseType, + pk_type: PrimaryKeyType, + *, + tenant: bool = False, +) -> str | None: """ 获取插件 SQL 脚本 @@ -36,6 +45,11 @@ async def get_plugin_sql(plugin: str, db_type: DataBaseType, pk_type: PrimaryKey :return: """ sql_dir = PLUGIN_DIR / plugin / 'sql' / ('mysql' if db_type == DataBaseType.mysql else 'postgresql') + if tenant: + tenant_sql_file = sql_dir / build_sql_filename('init', pk_type, tenant=True) + if await anyio.Path(tenant_sql_file).exists(): + return str(tenant_sql_file) + default_filename = build_sql_filename('init', pk_type) default_sql_file = sql_dir / default_filename return str(default_sql_file) if await anyio.Path(default_sql_file).exists() else None