Conversation
…1238) Tooling to rewrite stored tenantSchema/{id} documents from the legacy flat field layout into the canonical nested shape, completing the data side of the #1238 rename/restructure (Phase 1 = PR #1470 shipped the read-time coercion). - scripts/migrateTenantSchemaFirestore.ts: dry-run (writes preview JSON, no Firestore writes) or apply (backs up each doc to tenantSchemaBackup, then full-replaces with merge:false to drop stale legacy top-level keys). Uses the same coerceTenantSchema as runtime, so the data-loss fixes from #1470 apply. - coerceTenantSchema: add migration-detection helpers (tenantSchemaFirestoreDocNeedsShapeMigration / isNestedTenantSchemaDocument / STALE_LEGACY_TOP_LEVEL_TENANT_SCHEMA_KEYS). Detection also flags nested docs whose resources[] still carry legacy training fields. - package.json: migrate:tenant-schema[:dry-run] scripts; also add tsconfig-paths/register to sync:schemas so @/ imports resolve. - docs + unit tests. Does NOT run any migration. Applying is a manual, post-prod-deploy step.
Address Copilot review: `--tenant`/`--database` consumed the next argv entry without checking it exists or isn't another flag, so e.g. `--tenant --database staging` silently set tenant to "--database" and failed later with a confusing "No document tenantSchema/--database". Reject a missing value (or a value starting with `--`) up front with a clear "Missing value for <flag>" message.
feat(schema): tenantSchema Firestore shape migration (Phase 2 of #1238)
Tenant Schema Diff (development → production)This PR targets Key Differences by DocumentFull dry-run output |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a one-off Firestore migration path to rewrite tenantSchema/{tenantId} documents into the canonical nested tenant schema shape, aligning stored data with the runtime coercion logic and documenting the rollout process.
Changes:
- Introduces
scripts/migrateTenantSchemaFirestore.ts(dry-run, backups, full replace withmerge:false) to persist the coerced nested schema in Firestore. - Extends
lib/tenant/coerceTenantSchema.tswith helpers/constants to detect when a stored doc still needs a shape rewrite. - Adds unit coverage and documentation for the migration workflow; updates
package.jsonscripts to support@/path resolution in scripts.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| booking-app/tests/unit/coerce-tenant-schema-migration.unit.test.ts | Adds unit tests for new “needs shape migration” detection helpers. |
| booking-app/scripts/migrateTenantSchemaFirestore.ts | New CLI script to back up and rewrite tenant schemas into the canonical nested shape. |
| booking-app/package.json | Adds migration scripts and enables tsconfig-paths/register for schema-related scripts. |
| booking-app/lib/tenant/coerceTenantSchema.ts | Adds stale-legacy-key detection helpers/constants for migration tooling. |
| booking-app/docs/TENANT_SCHEMA_FIRESTORE_MIGRATION.md | Documents how to run and roll out the Firestore tenant schema shape migration. |
| booking-app/docs/SCHEMA_SYNC_GUIDE.md | Links schema sync docs to the new one-time shape migration guide. |
Comment on lines
+182
to
+185
| const migrated = coerceTenantSchema(raw, tenantId); | ||
| const payload = serializeForFirestore(migrated) as Record<string, unknown>; | ||
| const unchanged = stableStringify(raw) === stableStringify(payload); | ||
|
|
Comment on lines
+16
to
+19
| import { | ||
| coerceTenantSchema, | ||
| tenantSchemaFirestoreDocNeedsShapeMigration, | ||
| } from "../lib/tenant/coerceTenantSchema"; |
2 of 11 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Schema Changes
Checklist
Screenshots / Video