Dataset RLS Maintenance
Use this skill when a Foundry or account-governance task needs to remove, retire, repair, or redo rows that were previously imported incorrectly under the current user's database access.
Boundaries
- This skill is a workflow coordinator only.
- Do not call Supabase directly, parse raw credentials, bypass RLS, or write private database delete logic inside the skill.
- Do not delete rows from a broad filter such as only
state_code=0.
- Do not operate on rows that are not visible to the current authenticated user.
- Do not delete public/shared/canonical support rows. Treat them as protected unless the maintenance plan explicitly proves current-user ownership and policy allows the operation.
- If the CLI maintenance command is missing, record it as a CLI gap and stop before any database mutation.
Required Inputs
- A frozen maintenance scope manifest with task id, source import run id when available, dataset ids, versions, table/type, intended operation, and reason.
- Current account guard: user id or account identity expected by the task.
- Existing import artifacts when the redo starts from a Foundry workspace.
- The replacement source manifest or seed manifest when the operation includes redo.
- Explicit operator approval for any commit path.
CLI Surface
For the narrow "clear my current account so I can re-import" workflow, use the implemented command:
tiangong-lca dataset maintenance clear-account \
--out-dir ./dataset-maintenance/account-clear \
--json
tiangong-lca dataset maintenance clear-account \
--out-dir ./dataset-maintenance/account-clear \
--commit \
--confirm <current-account-email> \
--json
This command deletes only rows visible to the current authenticated user and filtered by that user's user_id
through RLS. It covers authorable dataset tables in reference-safe delete order:
lifecyclemodels, processes, flows, sources, and contacts.
It does not delete unitgroups or flowproperties, because those are treated as protected support data by default.
Use --state-code <n> only when the operator asks for a narrower cleanup. Omit it when the operator explicitly
asks to clear all current-account data for re-import.
For row-level delete, retirement, repair, or redo workflows, the owning command family remains:
tiangong-lca dataset maintenance plan \
--scope ./maintenance-scope.json \
--operation <delete|retire|redo-import|repair-references> \
--out-dir ./dataset-maintenance \
--json
tiangong-lca dataset maintenance apply \
--plan ./dataset-maintenance/maintenance-plan.json \
--commit \
--json
tiangong-lca dataset maintenance verify \
--plan ./dataset-maintenance/maintenance-plan.json \
--out-dir ./dataset-maintenance/verify \
--json
Until the row-level plan/apply/verify commands are implemented, the skill may plan and document the required artifacts,
but must not substitute ad hoc SQL, REST deletes, or Foundry-local database code.
Workflow
- Run
tiangong-lca auth status --json, then require tiangong-lca auth doctor-auth --json to pass before any account snapshot or mutation. If login is required, stop and ask the human to run auth login in a trusted terminal. Never request a password, authorization code, token, or legacy API key; use a separate private session file per account/project/client.
- Freeze the maintenance scope manifest before any remote action. Include dataset type/table, id, version, expected owner, state code, import run id, source package or evidence task id, and operation reason for every target row.
- Capture the current-user visible remote snapshot through the CLI. The snapshot must prove which rows are visible under RLS and which requested rows are missing, protected, public/shared, or owned by someone else.
- Build a reference impact report before delete or redo. Processes, lifecyclemodels, flows, sources, contacts, and support rows must be checked for inbound and outbound references at the same scope.
- Classify every target row into one of:
delete_candidate, retire_candidate, rewrite_reference, redo_candidate, skip_missing, protected, or blocked.
- Produce
maintenance-plan.json and dry-run-report.json. The plan must include row-level actions, order of operations, dependency blockers, expected post-state, and rollback notes.
- Require explicit approval before
apply --commit. Approval must name the plan file, operation, current user/account, row counts, and whether redo rows are ready.
- Execute only through the CLI maintenance command or existing public CLI save-draft/publish paths named by the approved plan.
- Run readback verification after any commit. Verification must re-fetch affected rows and references and compare them against the plan.
- For redo, start a fresh Foundry import or source-evidence task from the corrected source manifest after cleanup is verified. Do not reuse stale
.foundry artifacts as proof of the new run.
Required Artifacts
maintenance-scope.json
rls-visible-snapshot.json
protected-rows.jsonl
reference-impact-report.json
maintenance-plan.json
dry-run-report.json
approval-record.json
commit-report.json
readback-verify-report.json
redo-source-manifest.json when redo is part of the task
Stop Conditions
- The current account guard does not match the remote session.
- Any target row is not visible under current-user RLS.
- A target row is public/shared/canonical support data without an explicit policy exception.
- Inbound references would dangle after deletion.
- Replacement rows are not validated when the operation is redo.
- The task asks for direct SQL, REST delete, service-role access, or any RLS bypass.
1---2name: dataset-rls-maintenance3description: Orchestrate current-user RLS-scoped TianGong dataset cleanup, delete, retirement, and redo workflows through CLI maintenance plans, explicit approvals, and readback verification.4---56# Dataset RLS Maintenance78Use this skill when a Foundry or account-governance task needs to remove, retire, repair, or redo rows that were previously imported incorrectly under the current user's database access.910## Boundaries1112- This skill is a workflow coordinator only.13- Do not call Supabase directly, parse raw credentials, bypass RLS, or write private database delete logic inside the skill.14- Do not delete rows from a broad filter such as only `state_code=0`.15- Do not operate on rows that are not visible to the current authenticated user.16- Do not delete public/shared/canonical support rows. Treat them as protected unless the maintenance plan explicitly proves current-user ownership and policy allows the operation.17- If the CLI maintenance command is missing, record it as a CLI gap and stop before any database mutation.1819## Required Inputs2021- A frozen maintenance scope manifest with task id, source import run id when available, dataset ids, versions, table/type, intended operation, and reason.22- Current account guard: user id or account identity expected by the task.23- Existing import artifacts when the redo starts from a Foundry workspace.24- The replacement source manifest or seed manifest when the operation includes redo.25- Explicit operator approval for any commit path.2627## CLI Surface2829For the narrow "clear my current account so I can re-import" workflow, use the implemented command:3031```bash32tiangong-lca dataset maintenance clear-account \33 --out-dir ./dataset-maintenance/account-clear \34 --json3536tiangong-lca dataset maintenance clear-account \37 --out-dir ./dataset-maintenance/account-clear \38 --commit \39 --confirm <current-account-email> \40 --json41```4243This command deletes only rows visible to the current authenticated user and filtered by that user's `user_id`44through RLS. It covers authorable dataset tables in reference-safe delete order:45`lifecyclemodels`, `processes`, `flows`, `sources`, and `contacts`.46It does not delete `unitgroups` or `flowproperties`, because those are treated as protected support data by default.4748Use `--state-code <n>` only when the operator asks for a narrower cleanup. Omit it when the operator explicitly49asks to clear all current-account data for re-import.5051For row-level delete, retirement, repair, or redo workflows, the owning command family remains:5253```bash54tiangong-lca dataset maintenance plan \55 --scope ./maintenance-scope.json \56 --operation <delete|retire|redo-import|repair-references> \57 --out-dir ./dataset-maintenance \58 --json5960tiangong-lca dataset maintenance apply \61 --plan ./dataset-maintenance/maintenance-plan.json \62 --commit \63 --json6465tiangong-lca dataset maintenance verify \66 --plan ./dataset-maintenance/maintenance-plan.json \67 --out-dir ./dataset-maintenance/verify \68 --json69```7071Until the row-level plan/apply/verify commands are implemented, the skill may plan and document the required artifacts,72but must not substitute ad hoc SQL, REST deletes, or Foundry-local database code.7374## Workflow75761. Run `tiangong-lca auth status --json`, then require `tiangong-lca auth doctor-auth --json` to pass before any account snapshot or mutation. If login is required, stop and ask the human to run `auth login` in a trusted terminal. Never request a password, authorization code, token, or legacy API key; use a separate private session file per account/project/client.772. Freeze the maintenance scope manifest before any remote action. Include dataset type/table, id, version, expected owner, state code, import run id, source package or evidence task id, and operation reason for every target row.783. Capture the current-user visible remote snapshot through the CLI. The snapshot must prove which rows are visible under RLS and which requested rows are missing, protected, public/shared, or owned by someone else.794. Build a reference impact report before delete or redo. Processes, lifecyclemodels, flows, sources, contacts, and support rows must be checked for inbound and outbound references at the same scope.805. Classify every target row into one of: `delete_candidate`, `retire_candidate`, `rewrite_reference`, `redo_candidate`, `skip_missing`, `protected`, or `blocked`.816. Produce `maintenance-plan.json` and `dry-run-report.json`. The plan must include row-level actions, order of operations, dependency blockers, expected post-state, and rollback notes.827. Require explicit approval before `apply --commit`. Approval must name the plan file, operation, current user/account, row counts, and whether redo rows are ready.838. Execute only through the CLI maintenance command or existing public CLI save-draft/publish paths named by the approved plan.849. Run readback verification after any commit. Verification must re-fetch affected rows and references and compare them against the plan.8510. For redo, start a fresh Foundry import or source-evidence task from the corrected source manifest after cleanup is verified. Do not reuse stale `.foundry` artifacts as proof of the new run.8687## Required Artifacts8889- `maintenance-scope.json`90- `rls-visible-snapshot.json`91- `protected-rows.jsonl`92- `reference-impact-report.json`93- `maintenance-plan.json`94- `dry-run-report.json`95- `approval-record.json`96- `commit-report.json`97- `readback-verify-report.json`98- `redo-source-manifest.json` when redo is part of the task99100## Stop Conditions101102- The current account guard does not match the remote session.103- Any target row is not visible under current-user RLS.104- A target row is public/shared/canonical support data without an explicit policy exception.105- Inbound references would dangle after deletion.106- Replacement rows are not validated when the operation is redo.107- The task asks for direct SQL, REST delete, service-role access, or any RLS bypass.