Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tailordb-migration-sync-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tailor-platform/sdk": minor
---

Add `tailor-sdk tailordb migration sync <number>`. The new subcommand reconstructs the TailorDB schema snapshot at the given migration number (e.g. `0` for the baseline) and brings the remote in line with it without requiring a `git checkout`. Useful for recovering from drift introduced by an unintended `deploy --no-schema-check`. After syncing, run `tailor-sdk deploy` to catch up the remaining migrations from the working tree.
1 change: 1 addition & 0 deletions packages/sdk/docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Commands for managing TailorDB tables, data, and schema migrations.
| [tailordb migration generate](./cli/tailordb.md#tailordb-migration-generate) | Generate migration files by detecting schema differences between current local types and the previous migration snapshot. |
| [tailordb migration set](./cli/tailordb.md#tailordb-migration-set) | Set migration checkpoint to a specific number. |
| [tailordb migration status](./cli/tailordb.md#tailordb-migration-status) | Show the current migration status for TailorDB namespaces, including applied and pending migrations. |
| [tailordb migration sync](./cli/tailordb.md#tailordb-migration-sync) | Sync remote TailorDB schema to a specific migration snapshot (recovery from --no-schema-check drift). |
| [tailordb erd export](./cli/tailordb.md#tailordb-erd-export) | Export Liam ERD dist from applied TailorDB schema. |
| [tailordb erd serve](./cli/tailordb.md#tailordb-erd-serve) | Generate and serve ERD locally (liam build + serve dist). (beta) |
| [tailordb erd deploy](./cli/tailordb.md#tailordb-erd-deploy) | Deploy ERD static website for TailorDB namespace(s). |
Expand Down
54 changes: 54 additions & 0 deletions packages/sdk/docs/cli/tailordb.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ tailor-sdk tailordb [command]
See [Global Options](../cli-reference.md#global-options) for options available to all commands.

<!-- politty:command:tailordb:global-options-link:end -->

<!-- politty:command:tailordb truncate:heading:start -->

### tailordb truncate
Expand Down Expand Up @@ -156,6 +157,7 @@ tailor-sdk tailordb migration [command]
| [`tailordb migration generate`](#tailordb-migration-generate) | Generate migration files by detecting schema differences between current local types and the previous migration snapshot. |
| [`tailordb migration set`](#tailordb-migration-set) | Set migration checkpoint to a specific number. |
| [`tailordb migration status`](#tailordb-migration-status) | Show the current migration status for TailorDB namespaces, including applied and pending migrations. |
| [`tailordb migration sync`](#tailordb-migration-sync) | Sync remote TailorDB schema to a specific migration snapshot (recovery from --no-schema-check drift). |

<!-- politty:command:tailordb migration:subcommands:end -->

Expand Down Expand Up @@ -296,6 +298,58 @@ See [Global Options](../cli-reference.md#global-options) for options available t

<!-- politty:command:tailordb migration status:global-options-link:end -->

<!-- politty:command:tailordb migration sync:heading:start -->

#### tailordb migration sync

<!-- politty:command:tailordb migration sync:heading:end -->

<!-- politty:command:tailordb migration sync:description:start -->

Sync remote TailorDB schema to a specific migration snapshot (recovery from --no-schema-check drift).

<!-- politty:command:tailordb migration sync:description:end -->

<!-- politty:command:tailordb migration sync:usage:start -->

**Usage**

```
tailor-sdk tailordb migration sync [options] <number>
```

<!-- politty:command:tailordb migration sync:usage:end -->

<!-- politty:command:tailordb migration sync:arguments:start -->

**Arguments**

| Argument | Description | Required |
| -------- | --------------------------------------------- | -------- |
| `number` | Migration number to sync to (e.g., 0001 or 1) | Yes |

<!-- politty:command:tailordb migration sync:arguments:end -->

<!-- politty:command:tailordb migration sync:options:start -->

**Options**

| Option | Alias | Description | Required | Default | Env |
| ------------------------------- | ----- | ----------------------------------------------------------------- | -------- | -------------------- | --------------------------------- |
| `--workspace-id <WORKSPACE_ID>` | `-w` | Workspace ID | No | - | `TAILOR_PLATFORM_WORKSPACE_ID` |
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
| `--config <CONFIG>` | `-c` | Path to SDK config file | No | `"tailor.config.ts"` | `TAILOR_PLATFORM_SDK_CONFIG_PATH` |
| `--yes` | `-y` | Skip confirmation prompts | No | `false` | - |
| `--namespace <NAMESPACE>` | `-n` | Target TailorDB namespace (required if multiple namespaces exist) | No | - | - |

<!-- politty:command:tailordb migration sync:options:end -->

<!-- politty:command:tailordb migration sync:global-options-link:start -->

See [Global Options](../cli-reference.md#global-options) for options available to all commands.

<!-- politty:command:tailordb migration sync:global-options-link:end -->

**See also:** For migration concepts, configuration, workflow, and troubleshooting, see the [TailorDB Migrations guide](../services/tailordb-migration.md).

<!-- politty:command:tailordb erd:heading:start -->
Expand Down
20 changes: 19 additions & 1 deletion packages/sdk/src/cli/commands/tailordb/migrate/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { generateCommand, migrationCommand, setCommand, statusCommand } from "./index";
import { generateCommand, migrationCommand, setCommand, statusCommand, syncCommand } from "./index";

describe("migration CLI commands", () => {
describe("migrationCommand", () => {
Expand All @@ -19,6 +19,10 @@ describe("migration CLI commands", () => {
it("should have status subcommand", () => {
expect(migrationCommand.subCommands).toHaveProperty("status");
});

it("should have sync subcommand", () => {
expect(migrationCommand.subCommands).toHaveProperty("sync");
});
});

describe("generateCommand", () => {
Expand Down Expand Up @@ -59,4 +63,18 @@ describe("migration CLI commands", () => {
expect(shape).toHaveProperty("namespace");
});
});

describe("syncCommand", () => {
it("should have correct meta information", () => {
expect(syncCommand.name).toBe("sync");
expect(syncCommand.description).toContain("migration snapshot");
});

it("should have required args schema", () => {
const shape = syncCommand.args.shape;
expect(shape).toHaveProperty("number");
expect(shape).toHaveProperty("namespace");
expect(shape).toHaveProperty("yes");
});
});
});
5 changes: 5 additions & 0 deletions packages/sdk/src/cli/commands/tailordb/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* - generate: Generate migration files from schema differences
* - set: Set migration checkpoint to a specific number
* - status: Show migration status for TailorDB namespaces
* - sync: Sync remote TailorDB schema to a specific migration snapshot
*/

import { defineCommand } from "politty";
import { generateCommand } from "./generate";
import { setCommand } from "./set";
import { statusCommand } from "./status";
import { syncCommand } from "./sync";

export const migrationCommand = defineCommand({
name: "migration",
Expand All @@ -19,6 +21,7 @@ export const migrationCommand = defineCommand({
generate: generateCommand,
set: setCommand,
status: statusCommand,
sync: syncCommand,
},
});

Expand All @@ -28,3 +31,5 @@ export { setCommand } from "./set";
export type { SetOptions } from "./set";
export { statusCommand } from "./status";
export type { StatusOptions } from "./status";
export { syncCommand } from "./sync";
export type { SyncOptions } from "./sync";
Loading
Loading