feat(api): 开发平台、门店相关代码

This commit is contained in:
R524809
2026-09-03 16:04:44 +08:00
parent 35fcf8776e
commit ada02e9135
40 changed files with 7014 additions and 5807 deletions
+4 -4
View File
@@ -11,7 +11,7 @@ export class Database {
const client = await this.pool.connect();
try {
await client.query('BEGIN');
// atlas_app_login is NOINHERIT by design; application DML always uses the least-privileged group role.
// atlas_app_login 是 NOINHERIT 登录角色;应用 DML 必须降为最小权限的 atlas_app。
await client.query('SET LOCAL ROLE atlas_app');
const result = await work(client);
await client.query('COMMIT');
@@ -24,13 +24,13 @@ export class Database {
}
}
/** Every tenant-scoped query must run through this method. */
/** 每个带工作空间边界的业务读写都必须通过此方法执行。 */
public async workspaceTransaction<T>(
workspaceId: string,
work: (transaction: DatabaseTransaction) => Promise<T>,
): Promise<T> {
return this.transaction(async (transaction) => {
// SET LOCAL is scoped to this transaction and cannot leak a tenant id through the pool.
// SET LOCAL 仅作用于当前事务,连接归还池后不会泄漏租户 ID。
await transaction.query(
"SELECT set_config('app.workspace_id', $1, true)",
[workspaceId],
@@ -43,7 +43,7 @@ export class Database {
text: string,
values?: unknown[],
) {
// Even non-tenant reads use the restricted role; callers cannot accidentally use the login role's privileges.
// 即使不带租户上下文的查询也使用受限角色,调用方不会误用登录角色权限。
return this.transaction((transaction) =>
transaction.query<Row>(text, values),
);