Skip to content

Commit 0be4e17

Browse files
committed
source versioning: fix failing tests
1 parent 1885878 commit 0be4e17

10 files changed

+33
-16
lines changed

docs/resources/source_mysql.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ resource "materialize_source_mysql" "test" {
5252

5353
### Optional
5454

55+
- `all_tables` (Boolean, Deprecated) Include all tables in the source. If `table` is specified, this will be ignored.
5556
- `cluster_name` (String) The cluster to maintain this source.
5657
- `comment` (String) Comment on an object in the database.
5758
- `database_name` (String) The identifier for the source database in Materialize. Defaults to `MZ_DATABASE` environment variable if set or `materialize` if environment variable is not set.

docs/resources/source_table_postgres.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ resource "materialize_source_table_postgres" "postgres_table_from_source" {
4747

4848
- `comment` (String) Comment on an object in the database.
4949
- `database_name` (String) The identifier for the table database in Materialize. Defaults to `MZ_DATABASE` environment variable if set or `materialize` if environment variable is not set.
50+
- `exclude_columns` (List of String) Exclude specific columns when reading data from PostgreSQL.
5051
- `ownership_role` (String) The owernship role of the object.
5152
- `region` (String) The region to use for the resource connection. If not set, the default region is used.
5253
- `schema_name` (String) The identifier for the table schema in Materialize. Defaults to `public`.

integration/sqlserver.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ resource "materialize_source_sqlserver" "sqlserver_source_all" {
5454
database_name = materialize_connection_sqlserver.sqlserver_connection.database_name
5555
}
5656

57-
exclude_columns = ["dbo.table3.data", "dbo.table1.about", "dbo.table2.about", "dbo.table5.large_text", "dbo.table5.image_data", "dbo.table5.xml_data", "dbo.table5.json_data", "dbo.table10.text_col", "dbo.table10.nvarchar_max"]
57+
exclude_columns = ["dbo.table3.data", "dbo.table1.about", "dbo.table2.about", "dbo.table5.large_text", "dbo.table5.image_data", "dbo.table5.xml_data", "dbo.table5.json_data", "dbo.table6.description", "dbo.table6.binary_data", "dbo.table10.text_col", "dbo.table10.nvarchar_max"]
5858
}
5959

6060
# SQL Server Source Table

pkg/materialize/source_mysql.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SourceMySQLBuilder struct {
1515
ignoreColumns []string
1616
textColumns []string
1717
tables []TableStruct
18+
allTables bool
1819
exposeProgress IdentifierSchemaStruct
1920
}
2021

@@ -55,6 +56,11 @@ func (b *SourceMySQLBuilder) Tables(tables []TableStruct) *SourceMySQLBuilder {
5556
return b
5657
}
5758

59+
func (b *SourceMySQLBuilder) AllTables() *SourceMySQLBuilder {
60+
b.allTables = true
61+
return b
62+
}
63+
5864
func (b *SourceMySQLBuilder) ExposeProgress(e IdentifierSchemaStruct) *SourceMySQLBuilder {
5965
b.exposeProgress = e
6066
return b
@@ -111,7 +117,9 @@ func (b *SourceMySQLBuilder) Create() error {
111117
}
112118
q.WriteString(`)`)
113119
} else {
114-
q.WriteString(` FOR ALL TABLES`)
120+
if b.allTables {
121+
q.WriteString(` FOR ALL TABLES`)
122+
}
115123
}
116124

117125
if b.exposeProgress.Name != "" {

pkg/materialize/source_mysql_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func TestSourceMySQLAllTablesCreate(t *testing.T) {
2121
).WillReturnResult(sqlmock.NewResult(1, 1))
2222

2323
b := NewSourceMySQLBuilder(db, sourceMySQL)
24+
b.AllTables()
2425
b.MySQLConnection(IdentifierSchemaStruct{Name: "mysql_connection", SchemaName: "schema", DatabaseName: "database"})
2526

2627
if err := b.Create(); err != nil {
@@ -37,6 +38,7 @@ func TestSourceMySQLSpecificTablesCreate(t *testing.T) {
3738

3839
b := NewSourceMySQLBuilder(db, sourceMySQL)
3940
b.MySQLConnection(IdentifierSchemaStruct{Name: "mysql_connection", SchemaName: "schema", DatabaseName: "database"})
41+
b.AllTables()
4042
b.Tables([]TableStruct{
4143
{
4244
UpstreamName: "table_1",

pkg/provider/acceptance_datasource_source_table_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ resource "materialize_source_postgres" "test" {
6161
name = materialize_connection_postgres.postgres_connection.name
6262
}
6363
publication = "mz_source"
64-
table {
65-
upstream_name = "table2"
66-
upstream_schema_name = "public"
67-
}
6864
}
6965
7066
resource "materialize_source_table_postgres" "test" {

pkg/provider/acceptance_source_table_mysql_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,7 @@ func testAccSourceTableMySQLWithENUMResource(nameSpace string) string {
342342
name = materialize_connection_mysql.mysql_connection.name
343343
}
344344
345-
table {
346-
upstream_name = "mysql_table6"
347-
upstream_schema_name = "shop"
348-
name = "mysql_table6_local"
349-
}
350-
351-
text_columns = ["shop.mysql_table6.tags", "shop.mysql_table6.status"]
345+
ignore_columns = ["shop.mysql_table10.year_col"]
352346
}
353347
354348
resource "materialize_source_table_mysql" "test_enum" {
@@ -467,6 +461,8 @@ func testAccSourceTableMySQLWithDateTimeTypesResource(nameSpace string) string {
467461
468462
upstream_name = "mysql_table10"
469463
upstream_schema_name = "shop"
464+
465+
exclude_columns = ["year_col"]
470466
}
471467
`, nameSpace)
472468
}

pkg/provider/acceptance_source_table_sqlserver_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func TestAccSourceTableSQLServer_withUnsupportedTypes(t *testing.T) {
282282
testAccCheckSourceTableSQLServerExists("materialize_source_table_sqlserver.test_unsupported"),
283283
resource.TestCheckResourceAttr("materialize_source_table_sqlserver.test_unsupported", "name", nameSpace+"_table_unsupported"),
284284
resource.TestCheckResourceAttr("materialize_source_table_sqlserver.test_unsupported", "upstream_name", "table5"),
285-
resource.TestCheckResourceAttr("materialize_source_table_sqlserver.test_unsupported", "exclude_columns.#", "2"),
285+
resource.TestCheckResourceAttr("materialize_source_table_sqlserver.test_unsupported", "exclude_columns.#", "4"),
286286
),
287287
},
288288
},
@@ -396,7 +396,9 @@ func testAccSourceTableSQLServerWithUnsupportedTypesResource(nameSpace string) s
396396
397397
exclude_columns = [
398398
"large_text",
399-
"image_data"
399+
"image_data",
400+
"xml_data",
401+
"json_data"
400402
]
401403
}
402404
`, nameSpace)

pkg/resources/resource_source_mysql.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ var sourceMySQLSchema = map[string]*schema.Schema{
7979
},
8080
},
8181
},
82+
"all_tables": {
83+
Description: "Include all tables in the source. If `table` is specified, this will be ignored.",
84+
Deprecated: "Use the new `materialize_source_table_mysql` resource instead.",
85+
Type: schema.TypeBool,
86+
Optional: true,
87+
ForceNew: true,
88+
},
8289
"expose_progress": IdentifierSchema(IdentifierSchemaParams{
8390
Elem: "expose_progress",
8491
Description: "The name of the progress collection for the source. If this is not specified, the collection will be named `<src_name>_progress`.",
@@ -134,6 +141,10 @@ func sourceMySQLCreate(ctx context.Context, d *schema.ResourceData, meta any) di
134141
b.Tables(t)
135142
}
136143

144+
if v, ok := d.GetOk("all_tables"); ok && v.(bool) {
145+
b.AllTables()
146+
}
147+
137148
if v, ok := d.GetOk("ignore_columns"); ok && len(v.([]interface{})) > 0 {
138149
columns, err := materialize.GetSliceValueString("ignore_columns", v.([]interface{}))
139150
if err != nil {

pkg/resources/resource_source_table_postgres_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestResourceSourceTablePostgresCreate(t *testing.T) {
3838
mock.ExpectExec(`CREATE TABLE "database"."schema"."table"
3939
FROM SOURCE "materialize"."public"."source"
4040
\(REFERENCE "upstream_schema"."upstream_table"\)
41-
WITH \(TEXT COLUMNS \("column1", "column2"\)\);`).
41+
WITH \(TEXT COLUMNS \("column1", "column2"\), EXCLUDE COLUMNS \("exclude1", "exclude2"\)\);`).
4242
WillReturnResult(sqlmock.NewResult(1, 1))
4343

4444
// Query Id

0 commit comments

Comments
 (0)