diff --git a/package.json b/package.json index 9dd3b22..9d623a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tinybirdco/sdk", - "version": "0.0.75", + "version": "0.0.76", "description": "TypeScript SDK for Tinybird Forward - define datasources and pipes as TypeScript", "type": "module", "main": "./dist/index.js", diff --git a/src/generator/datasource.test.ts b/src/generator/datasource.test.ts index 06b6561..5c2ec8c 100644 --- a/src/generator/datasource.test.ts +++ b/src/generator/datasource.test.ts @@ -109,6 +109,18 @@ describe('Datasource Generator', () => { expect(result.content).toContain(' SELECT id'); }); + it('includes backfill skip when provided', () => { + const ds = defineDatasource('test_ds', { + schema: { + id: t.string(), + }, + backfill: 'skip', + }); + + const result = generateDatasource(ds); + expect(result.content).toContain('BACKFILL skip'); + }); + it("includes indexes block when provided", () => { const ds = defineDatasource("test_ds", { schema: { diff --git a/src/generator/datasource.ts b/src/generator/datasource.ts index a0d8ed4..1fbbd2e 100644 --- a/src/generator/datasource.ts +++ b/src/generator/datasource.ts @@ -346,6 +346,11 @@ export function generateDatasource( parts.push(indexes); } + if (datasource.options.backfill === "skip") { + parts.push(""); + parts.push("BACKFILL skip"); + } + // Add Kafka configuration if present if (datasource.options.kafka) { parts.push(""); diff --git a/src/schema/datasource.test.ts b/src/schema/datasource.test.ts index bca9594..21a1e31 100644 --- a/src/schema/datasource.test.ts +++ b/src/schema/datasource.test.ts @@ -170,6 +170,15 @@ describe("Datasource Schema", () => { ]); }); + it("accepts backfill skip configuration", () => { + const ds = defineDatasource("events_rollup", { + schema: { id: t.string() }, + backfill: "skip", + }); + + expect(ds.options.backfill).toBe("skip"); + }); + it("validates datasource index fields", () => { expect(() => defineDatasource("events", { diff --git a/src/schema/datasource.ts b/src/schema/datasource.ts index 5cc393d..d854bcd 100644 --- a/src/schema/datasource.ts +++ b/src/schema/datasource.ts @@ -144,6 +144,8 @@ export interface DatasourceOptions { forwardQuery?: string; /** Secondary indexes for MergeTree-family engines */ indexes?: readonly DatasourceIndex[]; + /** Skip backfilling data when creating a datasource targeted by a materialized view */ + backfill?: "skip"; /** Kafka ingestion configuration */ kafka?: KafkaConfig; /** S3 ingestion configuration */