Skip to content

fix(postgres): normalize int, int4, float, time and timestamp aliases in schema baselines - #1088

Open
DG47 wants to merge 2 commits into
elementary-data:masterfrom
DG47:fix/postgres-baseline-type-aliases
Open

DG47 wants to merge 2 commits into
elementary-data:masterfrom
DG47:fix/postgres-baseline-type-aliases

Conversation

@DG47

@DG47 DG47 commented Oct 19, 2026 •

Copy link
Copy Markdown

Fixes #1087

Problem

On Postgres, schema_changes_from_baseline reports type_changed for columns whose baseline data_type is int, int4, float, time or timestamp, even though the type has not changed.

The table side comes from information_schema.columns, so it uses integer, double precision, time without time zone and timestamp without time zone. postgres__get_normalized_data_type maps INTEGER to INT, INT4 and DOUBLE PRECISION to FLOAT8, and leaves the two WITHOUT TIME ZONE names as they are. The aliases are not in the map, so they never match:

The type of "id" was changed from INT to INT, INT4
The type of "updated_at" was changed from TIMESTAMP to TIMESTAMP WITHOUT TIME ZONE
The type of "opened_at" was changed from TIME to TIME WITHOUT TIME ZONE
The type of "score" was changed from FLOAT to FLOAT8

Change

Add the five aliases to the Postgres map, each pointing at the value its info schema type already normalizes to. The info schema names themselves are never one of these aliases, so the values written to schema_columns_snapshot do not change and schema_changes will not report a one-off type change for existing tables after upgrading.

This keeps INT, INT4 as the normalized value for integer. Changing it to INT4 would read better in alerts, but every Postgres user would then get a type_changed result for each integer column on the first schema_changes run after upgrading, because the previous snapshot stores INT, INT4. I left that out of this PR; happy to change it if you'd rather take that one-time hit.

Tests

Added test_schema_changes_from_baseline_postgres_type_aliases (Postgres only, parametrized over int and int4). It builds a table with integer, timestamp, time and float columns and runs schema_changes_from_baseline with enforce_types: true against a baseline that uses the aliases. It fails on master with the four results above and passes with this change.

Ran locally against Postgres 15 (dbt-core 1.12.6, dbt-postgres 1.11.0):

  • pytest test_schema_changes.py --target postgres: 4 passed
  • pytest test_schema_changes.py test_exposure_schema_validity.py test_column_anomalies.py test_volume_anomalies.py --target postgres -n 4: 67 passed, 1 skipped
  • pre-commit run on the changed files: all hooks passed

Summary by CodeRabbit

  • Bug Fixes
    • Improved PostgreSQL schema comparisons for common integer, float, time, and timestamp type aliases, helping prevent false differences when checking a schema baseline.
  • Tests
    • Added coverage to verify schema-baseline comparisons with PostgreSQL type aliases.

… in schema baselines

Postgres reports these columns as integer, double precision, time without
time zone and timestamp without time zone. A baseline that declares them
as int, int4, float, time or timestamp normalized to a different value,
so schema_changes_from_baseline reported a type change for every such
column. Map the aliases to the value their info schema type already
normalizes to, so stored column snapshots are unaffected.
@github-actions

Copy link
Copy Markdown
Contributor

👋 @DG47
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@DG47
DG47 had a problem deploying to elementary_test_env October 19, 2026 13:56 — with GitHub Actions Failure
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2bd5ceca-b2b9-4dcb-90e4-a571c2208e40
Commits

Reviewing files that changed from the base of the PR and between a27ca0e and 364e531.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The Postgres normalization macro now maps standard type aliases to information-schema names. A new Postgres integration test checks schema-baseline results for integer, timestamp, time, and float columns.

Changes: Postgres type alias normalization

Layer / File(s) Summary
Normalize and test Postgres aliases
macros/utils/data_types/get_normalized_data_type.sql, integration_tests/tests/test_schema_changes.py
The macro maps INT and INT4 to INT, INT4, FLOAT to FLOAT8, and TIME and TIMESTAMP to their WITHOUT TIME ZONE names. The Postgres integration test checks baseline results with int and int4 declarations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · previous review a27ca

The alias changes are ready to merge after normal checks; no unresolved behavior issue was identified.

Security architecture risk: Minimal · up to a27ca

The change aligns equivalent PostgreSQL type names without changing existing canonical snapshot values. No material security risk or new production entrypoint was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The production effect is limited to PostgreSQL type strings processed by existing schema-monitoring callers. The change does not add a caller, credential, privilege, network endpoint, or tenant-selection mechanism.

Trust Boundaries and Controls

  • observed — Configured type declarations and database metadata reach an existing adapter-dispatched normalizer. The added cases perform fixed dictionary substitutions; they introduce no SQL execution or authority transition. The live snapshot path continues to quote normalized type values before placing them in generated SQL.

Resilience and Maintainability Implications

  • observed — The test creates its table before baseline comparison and uses matching parametrized identifiers. Existing context managers clean temporary files on failure, and worker-specific schemas limit concurrent collisions. Database-relation cleanup remains delegated to the existing environment lifecycle; this is not a new production lifecycle or security guarantee.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: PostgreSQL type-alias normalization for schema baselines.
Linked Issues check Passed Issue #1087 requires PostgreSQL aliases int, int4, float, time, and timestamp to match unchanged information-schema types. The Postgres normalization map now maps these aliases to `INT, INT4…
Out of Scope Changes check Passed The changes are limited to the Postgres normalization map and a focused integration test for the linked issue. The map preserves INT, INT4 to avoid snapshot changes. No unrelated behavior is demonst…
Full details: Linked Issues check

Explanation

Issue #1087 requires PostgreSQL aliases int, int4, float, time, and timestamp to match unchanged information-schema types. The Postgres normalization map now maps these aliases to INT, INT4, FLOAT8, TIME WITHOUT TIME ZONE, and TIMESTAMP WITHOUT TIME ZONE. The added PostgreSQL-only test covers both integer aliases and all four affected column types with enforce_types: true.

Full details: Out of Scope Changes check

Explanation

The changes are limited to the Postgres normalization map and a focused integration test for the linked issue. The map preserves INT, INT4 to avoid snapshot changes. No unrelated behavior is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches

🧪 Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
ℹ️ Recent review info

⚙️ Run configuration

  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3b0725e7-97ad-495a-ac86-4b26ca64d731
📥 Commits

Reviewing files that changed from the base of the PR and between e3ab23d and a27ca0e.

📒 Files selected for processing: 2

  • integration_tests/tests/test_schema_changes.py
  • macros/utils/data_types/get_normalized_data_type.sql

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@DG47

DG47 commented Oct 30, 2026

Copy link
Copy Markdown
Author

@EladBarkay @haritamar would one of you have time to review this? It fixes #1087: on Postgres, schema_changes_from_baseline reports type_changed for columns whose baseline type is int, int4, float, time or timestamp, because those aliases are missing from postgres__get_normalized_data_type. The change adds the five aliases to the Postgres map, pointing at the values the info schema types already normalize to, so existing snapshots are unaffected. There's a Postgres-only test that fails on master and passes with the change. Happy to rebase or adjust if you'd prefer a different approach.

@DG47

DG47 commented Nov 21, 2026

Copy link
Copy Markdown
Author

Checking back on the Postgres alias fix for #1087: schema_changes_from_baseline reports type_changed for baselines using int, int4, float, time or timestamp, and this adds those aliases to postgres__get_normalized_data_type's map. @EladBarkay @haritamar, the fork workflow still needs a maintainer to approve it before CI runs, and the branch is behind, which I can update. One open question for review: I kept INT, INT4 as the normalized value for integer to avoid a one-time type_changed on every existing integer column, and can switch to INT4 if you'd rather take that hit.

@haritamar
haritamar deployed to elementary_test_env November 27, 2026 22:29 — with GitHub Actions Active
@jonlevine7

jonlevine7 commented Nov 27, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

This branch was successfully deployed

1 active deployment
elementary_test_env — 364e5319 Deployed Nov 27, 2026 by haritamar via approve-fork #5393
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schema_changes_from_baseline on Postgres reports type changes for columns declared as int, int4, float, time or timestamp

3 participants