Skip to content

Commit e37ad20

Browse files
Merge pull request #1 from Snowflake-Labs/fix/parameterize-postgres-cdc-demo
fix: parameterize schema and publication name in postgres-cdc-demo init SQL
2 parents 7502633 + 8aa17aa commit e37ad20

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

flows/data-generator/postgres-cdc-demo.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@
830830
"Max Batch Size": "1",
831831
"Connection Pooling Service": "ce22d3a0-f94b-3a61-ffff-ffff82c298f6",
832832
"Max Content Reference Size": "32 KB",
833-
"SQL": "CREATE SCHEMA IF NOT EXISTS demo_postgres;\n\nCREATE TABLE IF NOT EXISTS demo_postgres.customers (\n customer_id INTEGER PRIMARY KEY,\n first_name VARCHAR(100) NOT NULL,\n last_name VARCHAR(100) NOT NULL,\n email VARCHAR(255),\n phone VARCHAR(50),\n updated_at TIMESTAMP DEFAULT NOW()\n);\n\nCREATE TABLE IF NOT EXISTS demo_postgres.orders (\n order_id INTEGER PRIMARY KEY,\n customer_id INTEGER NOT NULL,\n order_status VARCHAR(50) DEFAULT 'pending',\n total_amount NUMERIC(10,2),\n shipping_address TEXT,\n updated_at TIMESTAMP DEFAULT NOW()\n);\n\nCREATE TABLE IF NOT EXISTS demo_postgres.order_items (\n item_id SERIAL PRIMARY KEY,\n order_id INTEGER NOT NULL,\n product_name VARCHAR(255) NOT NULL,\n quantity INTEGER DEFAULT 1,\n unit_price NUMERIC(10,2)\n);\n\nDO $$\nBEGIN\n IF NOT EXISTS (SELECT 1 FROM pg_publication WHERE pubname = 'demo_publication') THEN\n CREATE PUBLICATION demo_publication FOR TABLE\n demo_postgres.customers,\n demo_postgres.orders,\n demo_postgres.order_items;\n END IF;\nEND\n$$;"
833+
"SQL": "CREATE SCHEMA IF NOT EXISTS #{Schema Name};\n\nCREATE TABLE IF NOT EXISTS #{Schema Name}.customers (\n customer_id INTEGER PRIMARY KEY,\n first_name VARCHAR(100) NOT NULL,\n last_name VARCHAR(100) NOT NULL,\n email VARCHAR(255),\n phone VARCHAR(50),\n updated_at TIMESTAMP DEFAULT NOW()\n);\n\nCREATE TABLE IF NOT EXISTS #{Schema Name}.orders (\n order_id INTEGER PRIMARY KEY,\n customer_id INTEGER NOT NULL,\n order_status VARCHAR(50) DEFAULT 'pending',\n total_amount NUMERIC(10,2),\n shipping_address TEXT,\n updated_at TIMESTAMP DEFAULT NOW()\n);\n\nCREATE TABLE IF NOT EXISTS #{Schema Name}.order_items (\n item_id SERIAL PRIMARY KEY,\n order_id INTEGER NOT NULL,\n product_name VARCHAR(255) NOT NULL,\n quantity INTEGER DEFAULT 1,\n unit_price NUMERIC(10,2)\n);\n\nDO $$\nBEGIN\n IF NOT EXISTS (SELECT 1 FROM pg_publication WHERE pubname = '#{Publication Name}') THEN\n CREATE PUBLICATION #{Publication Name} FOR TABLE\n #{Schema Name}.customers,\n #{Schema Name}.orders,\n #{Schema Name}.order_items;\n END IF;\nEND\n$$;"
834834
},
835835
"propertyDescriptors": {
836836
"Max Batch Size": {
@@ -1616,7 +1616,6 @@
16161616
"flowFileOutboundPolicy": "STREAM_WHEN_AVAILABLE",
16171617
"componentType": "PROCESS_GROUP"
16181618
},
1619-
"externalControllerServices": {},
16201619
"parameterContexts": {
16211620
"CDC Postgres Demo - Data Generator": {
16221621
"name": "CDC Postgres Demo - Data Generator",
@@ -1660,6 +1659,13 @@
16601659
"sensitive": false,
16611660
"provided": false,
16621661
"value": "demo_postgres"
1662+
},
1663+
{
1664+
"name": "Publication Name",
1665+
"description": "Name of the PostgreSQL publication to create for CDC. Must match the publication name used by the CDC connector.",
1666+
"sensitive": false,
1667+
"provided": false,
1668+
"value": "demo_publication"
16631669
}
16641670
],
16651671
"description": "",

flows/data-generator/postgres-cdc-demo.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ The flow automatically creates the required Postgres schema, tables, and publica
1313
| `Database Connection URL` | JDBC URL to the Postgres instance |
1414
| `Database Name` | Postgres database name |
1515
| `Database User` | Postgres username |
16-
| `Schema Name` | Schema for the generated tables |
16+
| `Database Password` | Postgres password (sensitive) |
17+
| `Schema Name` | Schema for the generated tables (used in CREATE SCHEMA, CREATE TABLE, and CREATE PUBLICATION) |
18+
| `Publication Name` | Name of the PostgreSQL publication created for CDC. Must match the publication name configured in the CDC connector. Default: `demo_publication` |
1719
| `Database Driver` | JDBC driver asset (postgresql-42.7.10.jar) |
1820

1921
## Deployment

0 commit comments

Comments
 (0)