Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NOT VALID for Postgres databases #2600

Merged

Conversation

coenvk
Copy link
Contributor

@coenvk coenvk commented Mar 4, 2022

Environment

Liquibase Version: 4.7.1

Liquibase Integration & Version: CLI

Liquibase Extension(s) & Version:

Database Vendor & Version: PostgreSQL 9.1

Operating System Type & Version: Microsoft Windows 11 Home

Pull Request Type

  • Bug fix (non-breaking change which fixes an issue.)
  • Enhancement/New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

PostgreSQL has implemented a feature, since version 9.1, that ensures that constraints are only checked for new or modified rows, but not for existing data. When defining a constraint, NOT VALID can be added at the end to make use of this feature. A similar feature is available in Oracle under the name of ENABLE NOVALIDATE. Currently, NOT VALID is only allowed for foreign key and check constraints.

Steps To Reproduce

<changeSet id="addfkey" author="coenvk">
    <addForeignKeyConstraint baseTableName="account" baseColumnNames="customer_id" referencedTableName="customer" referencedColumnNames="id" constraintName="account_customer_id_fkey" validate="false"/>
</changeSet>

liquibase updateSQL

Actual Behavior

ALTER TABLE public.account ADD CONSTRAINT account_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customer (id) NOT VALID;

Expected/Desired Behavior

Executing the addForeignKeyConstraint migration with validate="false" on a Postgres database will now append "NOT VALID" add the end of the SQL and ensures that existing data will not validated by the foreign key constraint.

Copy link
Contributor

@nvoxland nvoxland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review and test results:

Change makes sense, thanks!

Things to be aware of

Things to worry about

@nvoxland nvoxland added the SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions label Jun 13, 2022
@github-actions
Copy link

Unit Test Results

  4 548 files  ±0    4 548 suites  ±0   30m 6s ⏱️ - 2m 19s
  4 508 tests ±0    4 294 ✔️ ±0     214 💤 ±0  0 ±0 
53 376 runs  ±0  48 368 ✔️ ±0  5 008 💤 ±0  0 ±0 

Results for commit dee23ba. ± Comparison against base commit 4e9b0d5.

Copy link
Contributor

@XDelphiGrl XDelphiGrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix is straight-forward and localized to the Postgres databases 9.1 or higher.
  • Test added to the test harness.

APPROVED

Passing Functional Tests

@nvoxland nvoxland merged commit bdd59d7 into liquibase:master Jun 15, 2022
Conditioning++ automation moved this from To Do to Done Jun 15, 2022
@kataggart kataggart added this to the v4.12.0 milestone Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autocandidate DBPostgres IntegrationCLI OSWindows SafeToBuild Indicates that a particular PR contains changes which are safe to build using GitHub actions sprint2022-27 TypeIncorrectSQL ver4.7.1
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants