fix(tailordb): exclude external namespaces from truncate and seedPlugin#1199
fix(tailordb): exclude external namespaces from truncate and seedPlugin#1199toiroakr wants to merge 6 commits into
Conversation
- 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 detectedLatest commit: 9abae21 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
⚡ pkg.pr.new@tailor-platform/sdk@tailor-platform/create-sdk
|
This comment has been minimized.
This comment has been minimized.
📖 Docs Consistency Check
|
| 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
-
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
-
Update `packages/sdk/docs/configuration.md`:
- Add a bullet point about truncate behavior in the "When using external resources" section after line 91
-
Update `packages/sdk/docs/generator/builtin.md`:
- Add a note about external namespace exclusion after the seed plugin usage examples (after line 219)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Code Metrics Report (packages/sdk)
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%)
SDK Configure Bundle Size
Runtime Performance
Type Performance (instantiations)
Reported by octocov |
There was a problem hiding this comment.
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;
Summary
tailor-sdk tailordb truncate --allnow skips namespaces declared with{ external: true }, so it only truncates namespaces the current app actually owns. Documented indocs/cli/tailordb.mdand 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.seed/exec.mjsskips the all-namespace truncate path when the app owns zero TailorDB namespaces (e.g. a shell app that only references shared DBs viaexternal: true), so running itsseed:resetno longer wipes a sibling app's data.seed/exec.mjsnow starts with an@generatedheader to discourage hand-edits, since the entire file is regenerated on everysdk generate.docs/configuration.mdanddocs/generator/builtin.mdnow spell out that destructive operations (tailordb truncate,seedPluginseed:reset) exclude external resources by design.extractOwnedNamespacesfor destructive operations;extractAllNamespacesonce again returns every configured namespace (including external) so non-destructive callers liketailordb querykeep working when only external namespaces are referenced.