From 25d66ab31bec9ee62c5047d0b7a530d036777f43 Mon Sep 17 00:00:00 2001 From: meskill <8974488+meskill@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:53:32 +0000 Subject: [PATCH] fix(schema_sync): parentheses around timezone operations --- Cargo.lock | 2 +- Cargo.toml | 3 ++- integration/schema_sync/ecommerce_schema.sql | 11 +++++++++++ pgdog/src/backend/schema/sync/pg_dump.rs | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 317d07819..68989550c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3094,7 +3094,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pg_raw_parse" version = "0.1.0" -source = "git+https://github.com/pgdogdev/pg_raw_parse.git?rev=6a6e16719b48eae2c5897e2e28de8d2bd65184f9#6a6e16719b48eae2c5897e2e28de8d2bd65184f9" +source = "git+https://github.com/pgdogdev/pg_raw_parse.git?branch=meskill-2026-09-24-test--wos#ebb4b03cbe11a86174d5c08c2f838934c3235d11" dependencies = [ "bindgen 0.72.1", "cc", diff --git a/Cargo.toml b/Cargo.toml index c4d70ad10..6d2f66dd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,8 @@ edition = "2024" pgdog-plugin = { path = "./pgdog-plugin", version = "0.4.0", default-features = false } pgdog-config = { path = "./pgdog-config", version = "0.1.0" } pgdog-postgres-types = { path = "./pgdog-postgres-types"} -pg_raw_parse = { git = "https://github.com/pgdogdev/pg_raw_parse.git", rev = "6a6e16719b48eae2c5897e2e28de8d2bd65184f9" } +# TODO: update after merge https://github.com/pgdogdev/pg_raw_parse/pull/56 +pg_raw_parse = { git = "https://github.com/pgdogdev/pg_raw_parse.git", branch = "meskill-2026-09-24-test--wos" } bon = "3.9" derive_more = { version = "2", features = ["display", "from"] } schemars = { version = "1.2.1", features = ["uuid1", "chrono04", "indexmap2"] } diff --git a/integration/schema_sync/ecommerce_schema.sql b/integration/schema_sync/ecommerce_schema.sql index 2fab52aa7..db9542bd8 100644 --- a/integration/schema_sync/ecommerce_schema.sql +++ b/integration/schema_sync/ecommerce_schema.sql @@ -109,6 +109,11 @@ AS $$ SELECT COUNT(*) FROM core.users $$; +CREATE TABLE core.timezone_source ( + id BIGINT PRIMARY KEY, + summary JSONB +); + CREATE TABLE core.countries ( country_code CHAR(2) PRIMARY KEY, country_name VARCHAR(100) NOT NULL, @@ -832,6 +837,12 @@ WHERE o.status NOT IN ('cancelled', 'refunded') AND o.created_at >= CURRENT_DATE - INTERVAL '24 months' GROUP BY DATE_TRUNC('month', o.created_at), c.category_id, c.category_name; +CREATE VIEW analytics.timezone_dates AS +SELECT + id, + ((summary ->> 'ts')::timestamptz AT TIME ZONE ((summary -> 'stop') ->> 'tz'))::date AS d +FROM core.timezone_source; + -- ============================================================================ -- FUNCTIONS AND PROCEDURES -- ============================================================================ diff --git a/pgdog/src/backend/schema/sync/pg_dump.rs b/pgdog/src/backend/schema/sync/pg_dump.rs index 6b311e347..5d18df6c4 100644 --- a/pgdog/src/backend/schema/sync/pg_dump.rs +++ b/pgdog/src/backend/schema/sync/pg_dump.rs @@ -1087,6 +1087,24 @@ CREATE TABLE t (id bigint PRIMARY KEY);"#, ); } + #[test] + fn test_view_time_zone_json_path_keeps_parentheses() { + let output = parse( + r#" +CREATE VIEW public.v AS +SELECT id, ((summary ->> 'ts'::text)::timestamp with time zone AT TIME ZONE ((summary -> 'stop'::text) ->> 'tz'::text))::date AS d +FROM public.s;"#, + ); + + let statements = output.statements(SyncState::PreData).unwrap(); + + assert_eq!(statements.len(), 1); + assert_eq!( + statements[0].sql, + "CREATE OR REPLACE VIEW public.v AS SELECT id, ((summary ->> 'ts'::text)::timestamp with time zone AT TIME ZONE ((summary -> 'stop'::text) ->> 'tz'::text))::date AS d FROM public.s" + ); + } + #[test] fn test_generated_identity() { let output = parse(