From e9af96c474adc6b07474be93c0cb57c8509ba0f4 Mon Sep 17 00:00:00 2001 From: gnzjgo Date: Mon, 23 Mar 2026 17:52:03 +0100 Subject: [PATCH 1/3] feat: add --last-partition flag to branch creation (#135) Amp-Thread-ID: https://ampcode.com/threads/T-019d1b0d-6dca-7013-a8f8-af75363aae7d Co-authored-by: Amp --- src/api/branches.ts | 16 +++++++++++++--- src/cli/commands/build.ts | 5 ++++- src/cli/commands/dev.ts | 5 ++++- src/cli/index.ts | 4 ++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/api/branches.ts b/src/api/branches.ts index 9c6368c..1b198de 100644 --- a/src/api/branches.ts +++ b/src/api/branches.ts @@ -143,12 +143,21 @@ async function pollJob( * @param name - Branch name to create * @returns The created branch with token */ +export interface CreateBranchOptions { + /** Copy the last partition of production data into the branch */ + lastPartition?: boolean; +} + export async function createBranch( config: BranchApiConfig, - name: string + name: string, + options?: CreateBranchOptions ): Promise { const url = new URL("/v1/environments", config.baseUrl); url.searchParams.set("name", name); + if (options?.lastPartition) { + url.searchParams.set("last_partition", "1"); + } const response = await tinybirdFetch(url.toString(), { method: "POST", @@ -325,7 +334,8 @@ export async function branchExists( */ export async function getOrCreateBranch( config: BranchApiConfig, - name: string + name: string, + options?: CreateBranchOptions ): Promise { // First try to get the existing branch try { @@ -334,7 +344,7 @@ export async function getOrCreateBranch( } catch (error) { // If it's a 404, create the branch if (error instanceof BranchApiError && error.status === 404) { - const branch = await createBranch(config, name); + const branch = await createBranch(config, name, options); return { ...branch, wasCreated: true }; } throw error; diff --git a/src/cli/commands/build.ts b/src/cli/commands/build.ts index 0a9d3ee..24a364b 100644 --- a/src/cli/commands/build.ts +++ b/src/cli/commands/build.ts @@ -27,6 +27,8 @@ export interface BuildCommandOptions { tokenOverride?: string; /** Override the devMode from config */ devModeOverride?: DevMode; + /** Copy the last partition of production data when creating a branch */ + lastPartition?: boolean; } /** @@ -225,7 +227,8 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise void; /** Override the devMode from config */ devModeOverride?: DevMode; + /** Copy the last partition of production data when creating a branch */ + lastPartition?: boolean; } /** @@ -241,7 +243,8 @@ export async function runDev( baseUrl: config.baseUrl, token: config.token, }, - branchName + branchName, + { lastPartition: options.lastPartition } ); if (!tinybirdBranch.token) { diff --git a/src/cli/index.ts b/src/cli/index.ts index 191b444..fa5a24a 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -270,6 +270,7 @@ function createCli(): Command { .option("--debug", "Show debug output including API requests/responses") .option("--local", "Use local Tinybird container") .option("--branch", "Use Tinybird cloud with branches") + .option("--last-partition", "Copy the last partition of production data when creating a branch") .action(async (options) => { if (options.debug) { process.env.TINYBIRD_DEBUG = "1"; @@ -286,6 +287,7 @@ function createCli(): Command { const result = await runBuild({ dryRun: options.dryRun, devModeOverride, + lastPartition: options.lastPartition, }); const { build, deploy, branchInfo } = result; @@ -677,6 +679,7 @@ function createCli(): Command { .description("Watch for changes and sync with Tinybird") .option("--local", "Use local Tinybird container") .option("--branch", "Use Tinybird cloud with branches") + .option("--last-partition", "Copy the last partition of production data when creating a branch") .action(async (options) => { // Determine devMode override let devModeOverride: DevMode | undefined; @@ -689,6 +692,7 @@ function createCli(): Command { try { const controller = await runDev({ devModeOverride, + lastPartition: options.lastPartition, onLoginComplete: (info) => { console.log("\nAuthentication successful!"); if (info.workspaceName) { From c4efc38de9d89b7ebfb06b5efb65748b7263aeee Mon Sep 17 00:00:00 2001 From: gnzjgo Date: Mon, 23 Mar 2026 19:01:23 +0100 Subject: [PATCH 2/3] feat: add debug logging to createBranch Amp-Thread-ID: https://ampcode.com/threads/T-019d1b0d-6dca-7013-a8f8-af75363aae7d Co-authored-by: Amp --- src/api/branches.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/api/branches.ts b/src/api/branches.ts index 1b198de..774d12c 100644 --- a/src/api/branches.ts +++ b/src/api/branches.ts @@ -159,6 +159,11 @@ export async function createBranch( url.searchParams.set("last_partition", "1"); } + const debug = !!process.env.TINYBIRD_DEBUG; + if (debug) { + console.log(`[debug] POST ${url.toString()}`); + } + const response = await tinybirdFetch(url.toString(), { method: "POST", headers: { From bc64afc46652bdceb4d5fee7817e8e67c7399a84 Mon Sep 17 00:00:00 2001 From: gnzjgo Date: Mon, 23 Mar 2026 19:04:38 +0100 Subject: [PATCH 3/3] chore: bump version to 0.0.63 Amp-Thread-ID: https://ampcode.com/threads/T-019d1b0d-6dca-7013-a8f8-af75363aae7d Co-authored-by: Amp --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index efa750e..11c6799 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tinybirdco/sdk", - "version": "0.0.62", + "version": "0.0.63", "description": "TypeScript SDK for Tinybird Forward - define datasources and pipes as TypeScript", "type": "module", "main": "./dist/index.js",