refactor(sdk): unify TailorDB deploy pipeline on snapshot schema#1184
refactor(sdk): unify TailorDB deploy pipeline on snapshot schema#1184toiroakr wants to merge 3 commits into
Conversation
Route the deploy plan/apply phases through SnapshotType — the same canonical shape used by tailordb migrate — so all comparisons and plan inputs share one normalized representation. Decimal scale is now normalized to the platform default (6) at the snapshot boundary (createSnapshotType, loadSnapshot, convertRemoteFieldsToSnapshot), replacing the per-comparison getEffectiveScale workaround. This consolidates schema normalization in one place (preventing recurrences like the decimal scale drift fixed in #1155) and prepares for a future tailordb migration sync command.
⚡ pkg.pr.new@tailor-platform/sdk@tailor-platform/create-sdk
|
🦋 Changeset detectedLatest commit: fab80e8 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 |
This comment has been minimized.
This comment has been minimized.
…ries
Address review feedback on the deploy-via-snapshot refactor:
- SnapshotPermissionOperand: replace the collapsing `| unknown` with a
proper discriminated union (SnapshotFieldRefOperand |
SnapshotValueOperand) and rewrite protoOperand / protoGqlOperand /
convertOperandToProto as exhaustive switches with `satisfies never`
and explicit throws. The GQL path now rejects non-`{ user }`
field-refs, matching the parser's Zod schema.
- TailorDBSnapshotType.pluralForm is now required at the type level;
legacy snapshots are backfilled via normalizeSnapshotType at the load
boundary instead of per-consumer fallbacks.
- Centralize normalizeSnapshotField / normalizeSnapshotType at every
snapshot construction boundary and add idempotent defense-in-depth
normalize at the entries of compareSnapshots and
compareRemoteWithSnapshot, so callers building literals never produce
silent false drift.
- Rename SnapshotType to TailorDBSnapshotType to disambiguate against
generic "snapshot type" reading and align with TailorDBType.
- Rewrite snapshot tests to exercise the normalization path through
createSnapshotFromLocalTypes / loadSnapshot, and add pluralForm to
all TailorDBSnapshotType literals (required by the new contract).
- Reword the changeset around the user-visible effect: tailor deploy
no longer shows spurious drift on decimal fields without an
explicit scale.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Unifies the tailor deploy TailorDB pipeline on the canonical TailorDBSnapshotType shape that tailordb migrate already uses. Field normalization (notably defaulting decimal scale to 6) is now centralized at snapshot construction (createSnapshotType, loadSnapshot, convertRemoteFieldsToSnapshot) with idempotent defense-in-depth normalization at compare entry points. The permission operand surface is tightened into a proper discriminated union with an exported isSnapshotFieldRefOperand guard, and SnapshotType is renamed to TailorDBSnapshotType with pluralForm required (legacy snapshots are backfilled at load time).
Changes:
- Centralize snapshot normalization (decimal
scale,pluralFormbackfill) and add safety-net normalization incompareSnapshots/compareRemoteWithSnapshot. - Pre-convert each
TailorDBServiceto a snapshot-shapedTailorDBDeployInputonce inplanTailorDB, passed viacontext.tailorDBInputsfor downstream plan/apply consumers; permission-operand helpers become exhaustive switches. - Rename
SnapshotType→TailorDBSnapshotType, makepluralFormrequired, and rewrite tests / type-manifest generation to consume the snapshot shape.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
packages/sdk/src/cli/lib.ts |
Re-export rename from SnapshotType to TailorDBSnapshotType. |
packages/sdk/src/cli/commands/tailordb/migrate/snapshot.ts |
Adds normalizeSnapshotField / normalizeSnapshotType, splits operand union, makes pluralForm required, normalizes at create/load/compare boundaries. |
packages/sdk/src/cli/commands/tailordb/migrate/snapshot.test.ts |
Adds pluralForm to every literal snapshot and rewrites the decimal-scale tests to flow through createSnapshotFromLocalTypes / loadSnapshot. |
packages/sdk/src/cli/commands/tailordb/migrate/snapshot-manifest.ts / .test.ts |
Switches to TailorDBSnapshotType, drops pluralForm fallback, uses isSnapshotFieldRefOperand. |
packages/sdk/src/cli/commands/tailordb/migrate/template-generator.test.ts, db-types-generator.ts / .test.ts |
Type rename and pluralForm additions in fixtures. |
packages/sdk/src/cli/commands/deploy/tailordb/index.ts |
Introduces TailorDBDeployInput, threads snapshot-shaped types through plan/apply, and rewires manifest/permission builders to snapshot types. |
packages/sdk/src/cli/commands/deploy/tailordb/index.test.ts, deploy.test.ts |
Adds tailorDBInputs to plan-context fixtures. |
.changeset/unify-tailordb-deploy-on-snapshot.md |
Patch-level changeset for the decimal-scale fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| getMigrationFilePath, | ||
| type SchemaSnapshot, | ||
| type SnapshotType, | ||
| type TailorDBSnapshotType, |
…napshot # Conflicts: # packages/sdk/src/cli/commands/deploy/tailordb/index.ts
Code Metrics Report (packages/sdk)
Details | | main (b2bd4aa) | #1184 (74c861c) | +/- |
|--------------------|----------------|-----------------|-------|
+ | Coverage | 62.3% | 62.5% | +0.2% |
| Files | 364 | 364 | 0 |
| Lines | 12773 | 12792 | +19 |
+ | Covered | 7967 | 8007 | +40 |
+ | Code to Test Ratio | 1:0.4 | 1:0.4 | +0.0 |
| Code | 83913 | 83980 | +67 |
+ | Test | 35136 | 35202 | +66 |Code coverage of files in pull request scope (59.4% → 61.5%)
SDK Configure Bundle Size
Runtime Performance
Type Performance (instantiations)
Reported by octocov |
📖 Docs Consistency Check✅ No inconsistencies found between documentation and implementation. Checked areas:
Summary: This PR fixes a bug where |
Summary
tailor deployTailorDB plan and apply phases throughTailorDBSnapshotType— the same canonical shape used bytailordb migrate— so the entire pipeline operates on one normalized schema representation.scaledefaulting to the platform value6) to the snapshot construction boundary (createSnapshotType,loadSnapshot,convertRemoteFieldsToSnapshot) and add idempotent defense-in-depth normalize at the entries ofcompareSnapshots/compareRemoteWithSnapshotso callers assembling literals never produce silent false drift.SnapshotPermissionOperandis now a proper discriminated union (SnapshotFieldRefOperand | SnapshotValueOperand) with an exportedisSnapshotFieldRefOperandtype guard;protoOperand/protoGqlOperand/convertOperandToProtoare exhaustive switches withsatisfies neverand explicit throws. The GQL path rejects non-{ user }field-refs, matching the parser's Zod schema.TailorDBSnapshotType.pluralFormis required at the type level; legacy snapshots are backfilled vianormalizeSnapshotTypeat the load boundary instead of per-consumer fallbacks.SnapshotType→TailorDBSnapshotTypeto disambiguate against generic "snapshot type" reading and align withTailorDBType.planTailorDBand pass them viacontext.tailorDBInputssoapplyTailorDBand downstream plan helpers consume the same canonical input.createSnapshotFromLocalTypes/loadSnapshotinstead of pre-normalized literals.tailor deployno longer shows spurious drift on decimal fields without an explicitscale. The@tailor-platform/sdk/clisubpath now exports the type asTailorDBSnapshotType(previouslySnapshotType), andpluralFormis required on the type; neither change has known consumers (no in-tree or docs references to the old name or to constructing the type directly).Motivation
tailordb migration synccommand without further plumbing.