style(db): 对齐 ICP 范围匹配 SQL 缩进,并注明手工挂载资产的语句顺序依赖
#53 引入 icp 范围匹配时,三处覆盖度 CTE 里新增的 OR 分支混进了 tab 缩进, 与同一 JOIN 条件内其它分支(纯空格)不一致。统一改回空格,SQL 语义未变 (git diff -w 无差异)。 AttachAssetsToTask 里 UPDATE assets 会先触发 trg_assets_task_links 写入 source='system',随后的显式 INSERT 才把来源改成 'manual'。加注释说明这层 顺序依赖,避免后续调换两条语句导致人工挂载的来源静默退化成 system。
This commit is contained in:
1 parent
6b44a94ec7
commit
3eca390089
3 files changed
+23
-19
No files matched your search
@@ -288,6 +288,10 @@ FROM assets WHERE id=ANY($2::bigint[])`, taskID, assetIDs).Scan(&found, &existin
|
|||||||
if found != len(assetIDs) {
|
if found != len(assetIDs) {
|
||||||
return mutation, ErrTaskAssetAssetNotFound
|
return mutation, ErrTaskAssetAssetNotFound
|
||||||
}
|
}
|
||||||
|
// Order matters: this UPDATE fires trg_assets_task_links, which creates the
|
||||||
|
// link rows with the generic source='system'. The INSERT below must stay
|
||||||
|
// after it so the operator-authored 'manual' provenance wins; swapping the
|
||||||
|
// two statements silently degrades every manual attach back to 'system'.
|
||||||
if _, err := tx.Exec(`
|
if _, err := tx.Exec(`
|
||||||
UPDATE assets
|
UPDATE assets
|
||||||
SET task_ids=CASE WHEN $1=ANY(task_ids) THEN task_ids ELSE array_append(task_ids,$1) END
|
SET task_ids=CASE WHEN $1=ANY(task_ids) THEN task_ids ELSE array_append(task_ids,$1) END
|
||||||
|
|||||||
+12
-12
@@ -29,12 +29,12 @@ target AS (
|
|||||||
JOIN task_scope ts ON (
|
JOIN task_scope ts ON (
|
||||||
(ts.kind='company' AND a.company_id = ts.company_id)
|
(ts.kind='company' AND a.company_id = ts.company_id)
|
||||||
OR (ts.kind='root_domain' AND a.root_domain = ts.domain)
|
OR (ts.kind='root_domain' AND a.root_domain = ts.domain)
|
||||||
OR (ts.kind='subdomain' AND a.domain = ts.domain)
|
OR (ts.kind='subdomain' AND a.domain = ts.domain)
|
||||||
OR (ts.kind IN ('ip','cidr') AND a.ip IS NOT NULL AND a.ip !~ '[^0-9a-fA-F:.]' AND ts.net >>= a.ip::inet)
|
OR (ts.kind IN ('ip','cidr') AND a.ip IS NOT NULL AND a.ip !~ '[^0-9a-fA-F:.]' AND ts.net >>= a.ip::inet)
|
||||||
OR (ts.kind='icp' AND (
|
OR (ts.kind='icp' AND (
|
||||||
lower(regexp_replace(COALESCE(a.icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
lower(regexp_replace(COALESCE(a.icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
||||||
OR lower(regexp_replace(COALESCE(a.app_icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
OR lower(regexp_replace(COALESCE(a.app_icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
JOIN context_tasks ctx ON ctx.task_id=ts.task_id
|
JOIN context_tasks ctx ON ctx.task_id=ts.task_id
|
||||||
UNION
|
UNION
|
||||||
@@ -179,12 +179,12 @@ context_assets AS (
|
|||||||
JOIN task_scope ts ON (
|
JOIN task_scope ts ON (
|
||||||
(ts.kind='company' AND a.company_id=ts.company_id)
|
(ts.kind='company' AND a.company_id=ts.company_id)
|
||||||
OR (ts.kind='root_domain' AND a.root_domain=ts.domain)
|
OR (ts.kind='root_domain' AND a.root_domain=ts.domain)
|
||||||
OR (ts.kind='subdomain' AND a.domain=ts.domain)
|
OR (ts.kind='subdomain' AND a.domain=ts.domain)
|
||||||
OR (ts.kind IN ('ip','cidr') AND a.ip IS NOT NULL AND a.ip !~ '[^0-9a-fA-F:.]' AND ts.net >>= a.ip::inet)
|
OR (ts.kind IN ('ip','cidr') AND a.ip IS NOT NULL AND a.ip !~ '[^0-9a-fA-F:.]' AND ts.net >>= a.ip::inet)
|
||||||
OR (ts.kind='icp' AND (
|
OR (ts.kind='icp' AND (
|
||||||
lower(regexp_replace(COALESCE(a.icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
lower(regexp_replace(COALESCE(a.icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
||||||
OR lower(regexp_replace(COALESCE(a.app_icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
OR lower(regexp_replace(COALESCE(a.app_icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
JOIN context_tasks ctx ON ctx.task_id=ts.task_id
|
JOIN context_tasks ctx ON ctx.task_id=ts.task_id
|
||||||
)
|
)
|
||||||
|
|||||||
+7
-7
@@ -308,13 +308,13 @@ target AS (
|
|||||||
JOIN task_scope ts ON ts.task_id = $1 AND (
|
JOIN task_scope ts ON ts.task_id = $1 AND (
|
||||||
(ts.kind='company' AND a.company_id = ts.company_id)
|
(ts.kind='company' AND a.company_id = ts.company_id)
|
||||||
OR (ts.kind='root_domain' AND a.root_domain = ts.domain)
|
OR (ts.kind='root_domain' AND a.root_domain = ts.domain)
|
||||||
OR (ts.kind='subdomain' AND a.domain = ts.domain)
|
OR (ts.kind='subdomain' AND a.domain = ts.domain)
|
||||||
OR (ts.kind IN ('ip','cidr') AND a.ip IS NOT NULL AND a.ip !~ '[^0-9a-fA-F:.]' AND ts.net >>= a.ip::inet)
|
OR (ts.kind IN ('ip','cidr') AND a.ip IS NOT NULL AND a.ip !~ '[^0-9a-fA-F:.]' AND ts.net >>= a.ip::inet)
|
||||||
OR (ts.kind='icp' AND (
|
OR (ts.kind='icp' AND (
|
||||||
lower(regexp_replace(COALESCE(a.icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
lower(regexp_replace(COALESCE(a.icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
||||||
OR lower(regexp_replace(COALESCE(a.app_icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
OR lower(regexp_replace(COALESCE(a.app_icp,''), '[[:space:]]+', '', 'g')) = ts.value
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
tested AS (
|
tested AS (
|
||||||
SELECT DISTINCT ea.asset_id
|
SELECT DISTINCT ea.asset_id
|
||||||
|
|||||||
Reference in new issue
Block a user