Skip to content

fix(tailordb): exclude external namespaces from truncate and seedPlugin#1199

Open
toiroakr wants to merge 6 commits into
mainfrom
fix/seed-plugin
Open

fix(tailordb): exclude external namespaces from truncate and seedPlugin#1199
toiroakr wants to merge 6 commits into
mainfrom
fix/seed-plugin

Conversation

@toiroakr
Copy link
Copy Markdown
Contributor

@toiroakr toiroakr commented May 20, 2026

Summary

  • tailor-sdk tailordb truncate --all now skips namespaces declared with { external: true }, so it only truncates namespaces the current app actually owns. Documented in docs/cli/tailordb.md and the CLI option description.
  • tailor-sdk tailordb truncate --namespace <name> now rejects an external namespace with a dedicated error pointing the user to the owning app, instead of the generic "not found in config" message.
  • The generated seed/exec.mjs skips the all-namespace truncate path when the app owns zero TailorDB namespaces (e.g. a shell app that only references shared DBs via external: true), so running its seed:reset no longer wipes a sibling app's data.
  • The generated seed/exec.mjs now starts with an @generated header to discourage hand-edits, since the entire file is regenerated on every sdk generate.
  • docs/configuration.md and docs/generator/builtin.md now spell out that destructive operations (tailordb truncate, seedPlugin seed:reset) exclude external resources by design.
  • Introduced extractOwnedNamespaces for destructive operations; extractAllNamespaces once again returns every configured namespace (including external) so non-destructive callers like tailordb query keep working when only external namespaces are referenced.

toiroakr added 3 commits May 20, 2026 11:29
- extractAllNamespaces() now skips namespaces declared with
  { external: true }, so `tailordb truncate --all` no longer
  truncates tables owned by a sibling app.
- The exec.mjs generated by seedPlugin skips the all-namespace
  truncate path when the current app owns zero TailorDB
  namespaces, so an external-only app's `seed:reset` no longer
  wipes the owning app's data.
- The generated exec.mjs now starts with an @generated header so
  human developers and AI assistants recognize it as a regenerated
  artifact and avoid hand-edits.
`tailordb truncate --namespace <name>` on a namespace declared with
`{ external: true }` now throws a dedicated error explaining that
the app does not own the namespace, instead of the generic
"not found in config" error.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

🦋 Changeset detected

Latest commit: 9abae21

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@tailor-platform/sdk Patch
@tailor-platform/create-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

⚡ pkg.pr.new

@tailor-platform/sdk

pnpm add https://pkg.pr.new/@tailor-platform/sdk@9abae21
pnpm dlx https://pkg.pr.new/@tailor-platform/sdk@9abae21 --help

@tailor-platform/create-sdk

pnpm add https://pkg.pr.new/@tailor-platform/create-sdk@9abae21
pnpm dlx https://pkg.pr.new/@tailor-platform/create-sdk@9abae21 my-app

commit: 9abae21

@github-actions

This comment has been minimized.

@toiroakr toiroakr marked this pull request as ready for review May 20, 2026 05:13
@toiroakr toiroakr requested a review from remiposo as a code owner May 20, 2026 05:13
@claude
Copy link
Copy Markdown

claude Bot commented May 20, 2026

📖 Docs Consistency Check

⚠️ Inconsistencies Found

File Issue Suggested Fix
packages/sdk/docs/cli/tailordb.md --all flag description doesn't mention external namespace exclusion Update line 86 to clarify: "Truncate all tables in all owned namespaces (excludes external namespaces)"
packages/sdk/docs/cli/tailordb.md Notes section missing external namespace behavior Add note after line 124: "External namespaces (declared with `{ external: true }`) are excluded from truncation. Use `--namespace` to see a clear error message when attempting to truncate an external namespace."
packages/sdk/docs/configuration.md External resources section doesn't mention truncate behavior Add bullet point after line 91: "Destructive operations like `truncate` automatically exclude external resources to prevent accidental data loss in shared resources"
packages/sdk/docs/generator/builtin.md Seed plugin `--truncate` option doesn't mention external namespace exclusion Add note after line 219: "The `--truncate` option automatically excludes external namespaces to prevent accidental data loss in shared resources."

Details

1. CLI Truncate Command (`packages/sdk/docs/cli/tailordb.md`)

Current documentation (line 86):
```markdown
| `--all` | `-a` | Truncate all tables in all namespaces | No | `false` | - |
```

Implementation behavior (from PR changes):

  • `packages/sdk/src/cli/shared/config.ts:14-15` - The `extractAllNamespaces` function now filters out namespaces with `external: true`
  • `packages/sdk/src/cli/commands/tailordb/truncate.ts:132-135` - When targeting a specific namespace, it rejects external namespaces with a dedicated error

What's wrong:
The `--all` flag description says it truncates "all namespaces" but after this PR it only truncates owned (non-external) namespaces.

Recommended fix:
Update the description to: `"Truncate all tables in all owned namespaces (excludes external namespaces)"`

Additionally, add a note in the "Notes" section (after line 124):
```markdown

  • External namespaces (declared with `{ external: true }`) are excluded from truncation. Use `--namespace ` on an external namespace to see a clear error message.
    ```

2. Configuration Documentation (`packages/sdk/docs/configuration.md`)

Current documentation (lines 85-91):
```markdown
When using external resources:

  • The resource itself is not deployed by this project
  • The resource must be deployed and available before referencing it
  • You can combine external resources with locally-defined resources
    ```

Implementation behavior:
External namespaces are now excluded from destructive operations like `truncate` to prevent accidental data loss.

What's wrong:
The documentation explains what external resources are but doesn't mention their behavior with destructive operations.

Recommended fix:
Add a bullet point:
```markdown

  • Destructive operations like `truncate` automatically exclude external resources to prevent accidental data loss in shared resources
    ```

3. Seed Plugin Documentation (`packages/sdk/docs/generator/builtin.md`)

Current documentation (line 219):
```bash
node seed/exec.mjs -m admin --truncate --yes
```

Implementation behavior:

  • The `--truncate` option in the generated `exec.mjs` now uses the same `truncate` function that excludes external namespaces
  • The generated file now includes an `@generated` header warning (line 1-5 of the template)

What's wrong:
The documentation shows the `--truncate` option but doesn't mention that it excludes external namespaces.

Recommended fix:
Add a note after the usage examples:
```markdown
Note: The `--truncate` option automatically excludes external namespaces to prevent accidental data loss in shared resources. If your app only references external namespaces and owns no TailorDB namespaces, truncate will be skipped with a message.
```

Recommended Actions

  1. Update `packages/sdk/docs/cli/tailordb.md`:

    • Change the `--all` flag description on line 86
    • Add external namespace behavior note in the Notes section after line 124
  2. Update `packages/sdk/docs/configuration.md`:

    • Add a bullet point about truncate behavior in the "When using external resources" section after line 91
  3. Update `packages/sdk/docs/generator/builtin.md`:

    • Add a note about external namespace exclusion after the seed plugin usage examples (after line 219)

@toiroakr toiroakr assigned toiroakr and unassigned remiposo May 20, 2026
@toiroakr toiroakr changed the title fix(seed): exclude external namespaces from truncate and seedPlugin fix(tailordb): exclude external namespaces from truncate and seedPlugin May 20, 2026
@toiroakr toiroakr requested a review from Copilot May 20, 2026 05:28
@github-actions

This comment has been minimized.

This comment was marked as outdated.

@github-actions

This comment has been minimized.

This comment was marked as outdated.

@github-actions
Copy link
Copy Markdown

Code Metrics Report (packages/sdk)

main (6ff3617) #1199 (fa7d26f) +/-
Coverage 62.3% 62.3% +0.0%
Code to Test Ratio 1:0.4 1:0.4 -0.1
Details
  |                    | main (6ff3617) | #1199 (fa7d26f) |  +/-  |
  |--------------------|----------------|-----------------|-------|
+ | Coverage           |          62.3% |           62.3% | +0.0% |
  |   Files            |            364 |             364 |     0 |
  |   Lines            |          12773 |           12782 |    +9 |
+ |   Covered          |           7960 |            7971 |   +11 |
- | Code to Test Ratio |          1:0.4 |           1:0.4 |  -0.1 |
  |   Code             |          83913 |           83929 |   +16 |
  |   Test             |          35136 |           35136 |     0 |

Code coverage of files in pull request scope (37.8% → 43.2%)

Files Coverage +/- Status
packages/sdk/src/cli/commands/tailordb/truncate.ts 74.2% +4.4% modified
packages/sdk/src/cli/shared/config.ts 100.0% 0.0% modified
packages/sdk/src/plugin/builtin/seed/index.ts 1.5% 0.0% modified

SDK Configure Bundle Size

main (6ff3617) #1199 (fa7d26f) +/-
configure-index-size 18KB 18KB 0KB
dependency-chunks-size 33.52KB 33.52KB 0KB
total-bundle-size 51.51KB 51.51KB 0KB

Runtime Performance

main (6ff3617) #1199 (fa7d26f) +/-
Generate Median 2,981ms 2,879ms -102ms
Generate Max 3,099ms 2,916ms -183ms
Apply Build Median 3,012ms 2,855ms -157ms
Apply Build Max 3,044ms 2,930ms -114ms

Type Performance (instantiations)

main (6ff3617) #1199 (fa7d26f) +/-
tailordb-basic 35,130 35,130 0
tailordb-optional 3,841 3,841 0
tailordb-relation 7,428 7,428 0
tailordb-validate 2,566 2,566 0
tailordb-hooks 5,767 5,767 0
tailordb-object 12,136 12,136 0
tailordb-enum 2,462 2,462 0
resolver-basic 9,424 9,424 0
resolver-nested 26,111 26,111 0
resolver-array 18,187 18,187 0
executor-schedule 4,234 4,234 0
executor-webhook 873 873 0
executor-record 8,166 8,166 0
executor-resolver 4,369 4,369 0
executor-operation-function 869 869 0
executor-operation-gql 869 869 0
executor-operation-webhook 888 888 0
executor-operation-workflow 1,714 1,714 0

Reported by octocov

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

packages/sdk/src/cli/commands/tailordb/truncate.ts:103

  • When config.db contains only external namespaces, this branch logs "No namespaces found in config file." even though namespaces are present but intentionally excluded. This is misleading—consider changing the warning to explicitly say no owned namespaces were found (and optionally mention that external namespaces are excluded).
  const namespaces = extractOwnedNamespaces(config);

  // Handle --all flag
  if (hasAll) {
    if (namespaces.length === 0) {
      logger.warn("No namespaces found in config file.");
      return;

@toiroakr toiroakr assigned remiposo and unassigned toiroakr May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants