Skip to content

feat: validate change history table schema upfront, add ERROR_MESSAGE column#426

Open
luisggc wants to merge 1 commit intoSnowflake-Labs:masterfrom
luisggc:pr1/change-history-schema-validation
Open

feat: validate change history table schema upfront, add ERROR_MESSAGE column#426
luisggc wants to merge 1 commit intoSnowflake-Labs:masterfrom
luisggc:pr1/change-history-schema-validation

Conversation

@luisggc
Copy link
Copy Markdown

@luisggc luisggc commented Mar 26, 2026

Summary

  • Adds ERROR_MESSAGE VARCHAR to the CREATE TABLE statement so newly created change history tables include the column from the start
  • Adds validate_change_history_schema() called at initialization (after the table is confirmed to exist, before any scripts run), using a fast metadata-only SELECT ERROR_MESSAGE FROM <table> LIMIT 0 check
  • If the column is missing on an existing table (created by an older version of schemachange or manually by a DBA): schemachange attempts ALTER TABLE ... ADD COLUMN IF NOT EXISTS ERROR_MESSAGE VARCHAR automatically
  • If the role lacks ALTER privileges, the deploy fails immediately with a clear message showing the exact SQL to run manually — no mid-deploy surprises
  • In dry-run mode, a warning is logged if the column is missing but no ALTER is attempted
  • Removes the previous runtime try/except hack in record_change_history that added the column on INSERT failure

Motivation

Previously, ERROR_MESSAGE was added via auto-ALTER when an INSERT failed at runtime. This was risky: it introduced DDL mid-deploy, and if the role lacked ALTER privileges the deploy would break even for successful scripts (since error_message='' is always passed). Moving this check to initialization gives a predictable, upfront failure instead.

This is a prerequisite for the continue-on-error feature (#339).

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.

1 participant