Skip to content

Commit e202851

Browse files
committed
Add deprecated message
1 parent c46aa7d commit e202851

File tree

5 files changed

+191
-10
lines changed

5 files changed

+191
-10
lines changed

docs/resources/source_mysql.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ resource "materialize_source_mysql" "test" {
5757
- `comment` (String) **Public Preview** Comment on an object in the database.
5858
- `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.
5959
- `expose_progress` (Block List, Max: 1) The name of the progress collection for the source. If this is not specified, the collection will be named `<src_name>_progress`. (see [below for nested schema](#nestedblock--expose_progress))
60-
- `ignore_columns` (List of String, Deprecated) Ignore specific columns when reading data from MySQL. Can only be updated in place when also updating a corresponding `table` attribute.
60+
- `ignore_columns` (List of String, Deprecated) Ignore specific columns when reading data from MySQL. Can only be updated in place when also updating a corresponding `table` attribute. Deprecated: Use the new materialize_source_table resource instead.
6161
- `ownership_role` (String) The owernship role of the object.
6262
- `region` (String) The region to use for the resource connection. If not set, the default region is used.
6363
- `schema_name` (String) The identifier for the source schema in Materialize. Defaults to `public`.
64-
- `table` (Block Set, Deprecated) Specify the tables to be included in the source. If not specified, all tables are included. (see [below for nested schema](#nestedblock--table))
65-
- `text_columns` (List of String, Deprecated) Decode data as text for specific columns that contain MySQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute.
64+
- `table` (Block Set, Deprecated) Specify the tables to be included in the source. Deprecated: Use the new materialize_source_table resource instead. (see [below for nested schema](#nestedblock--table))
65+
- `text_columns` (List of String, Deprecated) Decode data as text for specific columns that contain MySQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute. Deprecated: Use the new materialize_source_table resource instead.
6666

6767
### Read-Only
6868

docs/resources/source_postgres.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ resource "materialize_source_postgres" "example_source_postgres" {
6262
- `ownership_role` (String) The owernship role of the object.
6363
- `region` (String) The region to use for the resource connection. If not set, the default region is used.
6464
- `schema_name` (String) The identifier for the source schema in Materialize. Defaults to `public`.
65-
- `table` (Block Set, Deprecated) Creates subsources for specific tables in the Postgres connection. (see [below for nested schema](#nestedblock--table))
66-
- `text_columns` (List of String, Deprecated) Decode data as text for specific columns that contain PostgreSQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute.
65+
- `table` (Block Set, Deprecated) Creates subsources for specific tables in the Postgres connection. Deprecated: Use the new materialize_source_table resource instead. (see [below for nested schema](#nestedblock--table))
66+
- `text_columns` (List of String, Deprecated) Decode data as text for specific columns that contain PostgreSQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute. Deprecated: Use the new materialize_source_table resource instead.
6767

6868
### Read-Only
6969

pkg/resources/resource_source_mysql.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ var sourceMySQLSchema = map[string]*schema.Schema{
2727
ForceNew: true,
2828
}),
2929
"ignore_columns": {
30-
Description: "Ignore specific columns when reading data from MySQL. Can only be updated in place when also updating a corresponding `table` attribute.",
30+
Description: "Ignore specific columns when reading data from MySQL. Can only be updated in place when also updating a corresponding `table` attribute. Deprecated: Use the new materialize_source_table resource instead.",
3131
Deprecated: "Use the new materialize_source_table resource instead.",
3232
Type: schema.TypeList,
3333
Elem: &schema.Schema{Type: schema.TypeString},
3434
Optional: true,
3535
},
3636
"text_columns": {
37-
Description: "Decode data as text for specific columns that contain MySQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute.",
37+
Description: "Decode data as text for specific columns that contain MySQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute. Deprecated: Use the new materialize_source_table resource instead.",
3838
Deprecated: "Use the new materialize_source_table resource instead.",
3939
Type: schema.TypeList,
4040
Elem: &schema.Schema{Type: schema.TypeString},
4141
Optional: true,
4242
},
4343
"table": {
44-
Description: "Specify the tables to be included in the source. If not specified, all tables are included.",
44+
Description: "Specify the tables to be included in the source. Deprecated: Use the new materialize_source_table resource instead.",
4545
Deprecated: "Use the new materialize_source_table resource instead.",
4646
Type: schema.TypeSet,
4747
Optional: true,

pkg/resources/resource_source_postgres.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ var sourcePostgresSchema = map[string]*schema.Schema{
3333
ForceNew: true,
3434
},
3535
"text_columns": {
36-
Description: "Decode data as text for specific columns that contain PostgreSQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute.",
36+
Description: "Decode data as text for specific columns that contain PostgreSQL types that are unsupported in Materialize. Can only be updated in place when also updating a corresponding `table` attribute. Deprecated: Use the new materialize_source_table resource instead.",
3737
Deprecated: "Use the new materialize_source_table resource instead.",
3838
Type: schema.TypeList,
3939
Elem: &schema.Schema{Type: schema.TypeString},
4040
Optional: true,
4141
},
4242
"table": {
43-
Description: "Creates subsources for specific tables in the Postgres connection.",
43+
Description: "Creates subsources for specific tables in the Postgres connection. Deprecated: Use the new materialize_source_table resource instead.",
4444
Deprecated: "Use the new materialize_source_table resource instead.",
4545
Type: schema.TypeSet,
4646
Optional: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
---
2+
page_title: "Source versioning: migrating to `materialize_source_table` Resource"
3+
subcategory: ""
4+
description: |-
5+
6+
---
7+
8+
# Source versioning: migrating to `materialize_source_table` Resource
9+
10+
In previous versions of the Materialize Terraform provider, source tables were defined within the source resource itself and were considered subsources of the source rather than separate entities.
11+
12+
This guide will walk you through the process of migrating your existing source table definitions to the new `materialize_source_table` resource.
13+
14+
## Old Approach
15+
16+
Previously, source tables were defined directly within the source resource:
17+
18+
### Example: MySQL Source
19+
20+
```hcl
21+
resource "materialize_source_mysql" "mysql_source" {
22+
name = "mysql_source"
23+
cluster_name = "cluster_name"
24+
25+
mysql_connection {
26+
name = materialize_connection_mysql.mysql_connection.name
27+
}
28+
29+
table {
30+
upstream_name = "mysql_table1"
31+
upstream_schema_name = "shop"
32+
name = "mysql_table1_local"
33+
}
34+
}
35+
```
36+
37+
The same approach was used for other source types such as Postgres and the load generator sources.
38+
39+
## New Approach
40+
41+
The new approach separates source definitions and table definitions. You will now create the source without specifying the tables, and then define each table using the `materialize_source_table` resource.
42+
43+
## Manual Migration Process
44+
45+
This manual migration process requires users to create new source tables using the new `materialize_source_table` resource and then remove the old ones.
46+
47+
### Step 1: Define `materialize_source_table` Resources
48+
49+
Before making any changes to your existing source resources, create new `materialize_source_table` resources for each table that is currently defined within your sources. This ensures that the tables are preserved during the migration:
50+
51+
```hcl
52+
resource "materialize_source_table" "mysql_table_from_source" {
53+
name = "mysql_table1_from_source"
54+
schema_name = "public"
55+
database_name = "materialize"
56+
57+
source {
58+
name = materialize_source_mysql.mysql_source.name
59+
// Define the schema and database for the source if needed
60+
}
61+
62+
upstream_name = "mysql_table1"
63+
upstream_schema_name = "shop"
64+
65+
ignore_columns = ["about"]
66+
}
67+
```
68+
69+
### Step 2: Apply the Changes
70+
71+
Run `terraform plan` and `terraform apply` to create the new `materialize_source_table` resources. This step ensures that the tables are defined separately from the source and are not removed from Materialize.
72+
73+
> **Note:** This will start an ingestion process for the newly created source tables.
74+
75+
### Step 3: Remove Table Blocks from Source Resources
76+
77+
Once the new `materialize_source_table` resources are successfully created, you can safely remove the `table` blocks from your existing source resources:
78+
79+
```hcl
80+
resource "materialize_source_mysql" "mysql_source" {
81+
name = "mysql_source"
82+
cluster_name = "cluster_name"
83+
84+
mysql_connection {
85+
name = materialize_connection_mysql.mysql_connection.name
86+
}
87+
}
88+
```
89+
90+
This will drop the old tables from the source resources.
91+
92+
### Step 4: Update Terraform State
93+
94+
After removing the `table` blocks from your source resources, run `terraform plan` and `terraform apply` again to update the Terraform state and apply the changes.
95+
96+
### Step 5: Verify the Migration
97+
98+
After applying the changes, verify that your tables are still correctly set up in Materialize by checking the table definitions using Materialize’s SQL commands.
99+
100+
During the migration, you can use both the old `table` blocks and the new `materialize_source_table` resources simultaneously. This allows for a gradual transition until the old method is fully deprecated.
101+
102+
## Automated Migration Process (TBD)
103+
104+
> **Note:** This will still not work as the previous source tables are considered subsources of the source and are missing from the `mz_tables` table in Materialize so we can't import them directly without recreating them.
105+
106+
Once the migration on the Materialize side has been implemented, a more automated migration process will be available. The steps will include:
107+
108+
### Step 1: Define `materialize_source_table` Resources
109+
110+
First, define the new `materialize_source_table` resources for each table:
111+
112+
```hcl
113+
resource "materialize_source_table" "mysql_table_from_source" {
114+
name = "mysql_table1_from_source"
115+
schema_name = "public"
116+
database_name = "materialize"
117+
118+
source {
119+
name = materialize_source_mysql.mysql_source.name
120+
// Define the schema and database for the source if needed
121+
}
122+
123+
upstream_name = "mysql_table1"
124+
upstream_schema_name = "shop"
125+
126+
ignore_columns = ["about"]
127+
}
128+
```
129+
130+
### Step 2: Modify the Existing Source Resource
131+
132+
Next, modify the existing source resource by removing the `table` blocks and adding an `ignore_changes` directive for the `table` attribute. This prevents Terraform from trying to delete the tables:
133+
134+
```hcl
135+
resource "materialize_source_mysql" "mysql_source" {
136+
name = "mysql_source"
137+
cluster_name = "cluster_name"
138+
139+
mysql_connection {
140+
name = materialize_connection_mysql.mysql_connection.name
141+
}
142+
143+
lifecycle {
144+
ignore_changes = [table]
145+
}
146+
}
147+
```
148+
149+
- **`lifecycle { ignore_changes = [table] }`**: This directive tells Terraform to ignore changes to the `table` attribute, preventing it from trying to delete tables that were previously defined in the source resource.
150+
151+
### Step 3: Import the Existing Tables
152+
153+
You can then import the existing tables into the new `materialize_source_table` resources without disrupting your existing setup:
154+
155+
```bash
156+
terraform import materialize_source_table.mysql_table_from_source <region>:<table_id>
157+
```
158+
159+
Replace `<region>` with the actual region and `<table_id>` with the table ID. You can find the table ID by querying the `mz_tables` table.
160+
161+
### Step 4: Run Terraform Plan and Apply
162+
163+
Finally, run `terraform plan` and `terraform apply` to ensure that everything is correctly set up without triggering any unwanted deletions.
164+
165+
This approach allows you to migrate your tables safely without disrupting your existing setup.
166+
167+
## Importing Existing Tables
168+
169+
To import existing tables into your Terraform state using the manual migration process, use the following command:
170+
171+
```bash
172+
terraform import materialize_source_table.table_name <region>:<table_id>
173+
```
174+
175+
Ensure you replace `<region>` with the region where the table is located and `<table_id>` with the ID of the table.
176+
177+
> **Note:** The `upstream_name` and `upstream_schema_name` attributes are not yet implemented on the Materialize side, so the import process will not work until these changes are made.
178+
179+
## Future Improvements
180+
181+
The Kafka and Webhooks sources are currently being implemented. Once these changes, the migration process will be updated to include them.

0 commit comments

Comments
 (0)