diff --git a/core/assertion.ts b/core/assertion.ts index 1849804a5..d402d0676 100644 --- a/core/assertion.ts +++ b/core/assertion.ts @@ -7,6 +7,7 @@ export interface AConfig { dependencies?: string | string[]; tags?: string[]; description?: string; + schema?: string; } export class Assertion { @@ -28,6 +29,9 @@ export class Assertion { if (config.description) { this.description(config.description); } + if (config.schema) { + this.schema(config.schema); + } return this; } @@ -61,6 +65,10 @@ export class Assertion { return this; } + public schema(schema: string) { + this.proto.target = this.session.target(schema, this.session.config.assertionSchema); + } + public compile() { const context = new AssertionContext(this); diff --git a/core/operation.ts b/core/operation.ts index fb8b66993..ff720042a 100644 --- a/core/operation.ts +++ b/core/operation.ts @@ -9,6 +9,7 @@ export interface OConfig { description?: string; columns?: IColumnsDescriptor; hasOutput?: boolean; + schema?: string; } export class Operation { @@ -36,6 +37,9 @@ export class Operation { if (config.columns) { this.columns(config.columns); } + if (config.schema) { + this.schema(config.schema); + } return this; } @@ -85,6 +89,10 @@ export class Operation { return this; } + public schema(schema: string) { + this.proto.target = this.session.target(schema); + } + public compile() { if ( this.proto.actionDescriptor && diff --git a/core/session.ts b/core/session.ts index 4264b651d..e30dd431a 100644 --- a/core/session.ts +++ b/core/session.ts @@ -14,7 +14,6 @@ interface IActionProto { interface ISqlxConfig extends table.TConfig, AConfig, OConfig, test.TConfig { type: "view" | "table" | "inline" | "incremental" | "assertion" | "operations" | "test"; - schema?: string; name: string; } diff --git a/core/table.ts b/core/table.ts index d2c81cf74..99cca2454 100644 --- a/core/table.ts +++ b/core/table.ts @@ -47,6 +47,7 @@ export interface TConfig { redshift?: dataform.IRedshiftOptions; bigquery?: dataform.IBigQueryOptions; sqldatawarehouse?: dataform.ISQLDataWarehouseOptions; + schema?: string; } export class Table { @@ -93,6 +94,9 @@ export class Table { if (config.columns) { this.columns(config.columns); } + if (config.schema) { + this.schema(config.schema); + } return this; } @@ -181,6 +185,10 @@ export class Table { return this; } + public schema(schema: string) { + this.proto.target = this.session.target(schema); + } + public compile() { const context = new TableContext(this); diff --git a/tests/core/core.spec.ts b/tests/core/core.spec.ts index f0c091bbc..8e8ec0a50 100644 --- a/tests/core/core.spec.ts +++ b/tests/core/core.spec.ts @@ -43,6 +43,18 @@ describe("@dataform/core", () => { }); expect(t.preOps).deep.equals(["pre_op"]); expect(t.postOps).deep.equals(["post_op"]); + + const t2 = session + .publish("my_table", { + type: "table", + schema: "test_schema" + }) + .query(_ => "SELECT 1 as one") + .compile(); + expect(t2.name).equals("my_table"); + expect((t2.target.name = "my_table")); + expect((t2.target.schema = "test_schema")); + expect(t2.type).equals("table"); }); it("config_context", () => { diff --git a/version.bzl b/version.bzl index 23b4d0376..b5e4003ad 100644 --- a/version.bzl +++ b/version.bzl @@ -1,3 +1,3 @@ # NOTE: If you change the format of this line, you must change the bash command # in /scripts/publish to extract the version string correctly. -DF_VERSION = "1.2.2" +DF_VERSION = "1.2.3"