Skip to content
This repository has been archived by the owner on Jul 2, 2022. It is now read-only.

Fix AUTOINCREMENT #101

Merged
merged 1 commit into from
May 9, 2022

Conversation

MartinRied
Copy link

@MartinRied MartinRied commented Jun 28, 2021

AUTOINCREMENT was not working with the previous implementation, since the actual AUTOINCREMENT/IDENTITY keyword was missing.

Based on other examples, this should usually be provided by AbstractJdbcDatabase#getAutoIncrementClause().

On the other hand, the SnowflakeDatabase#getAutoIncrementClause(BigInteger,BigInteger) method is as far as I can tell irrelevant, since it's not exposed or used by AbstractJdbcDatabase or the Database interface.

The updated auto-increment code has been tested against a live Snowflake instance to create tables with auto-increment enabled.

┆Issue is synchronized with this Jira Bug by Unito

@molivasdat molivasdat requested a review from nvoxland July 15, 2021 19:07
@MartinRied
Copy link
Author

Hi @molivasdat, @nvoxland,

Is there anything I could do to support the review process?

We're using liquibase-snowflake internally and so far I've avoided building our own version in favor of waiting for the PR to hopefully be approved - but of course this blocks any CI/CD which depends on the modified liquibase-snowflake version.

Regards,
Martin

@molivasdat
Copy link

Hi @TheDECKER Do you have an example changeset that can be validated against this change? And thank you for adding to the automated tests.

@MartinRied
Copy link
Author

MartinRied commented Sep 8, 2021

Hi @molivasdat ,

I've slightly modified one of our tables accordingly - though I have to admit I didn't re-test that changeset against Snowflake using the "vanilla" liquibase-snowflake code.

https://pastebin.com/vF5cuevR

@molivasdat
Copy link

Thanks for the update. I noticed that you have constraint primary key which by definition should be unique but also have unique=false on line 11.

@MartinRied
Copy link
Author

MartinRied commented Sep 8, 2021

It certainly looks a bit odd when you read it :-D

On the other hand, what I know from Oracle & co is that when you create a PK constraint, it is automatically unique, so generating a separate UNIQUE constraint should not be necessary. I've got to admit, though, that I'm not sure what ANSI SQL has to say about that...

And lastly:
For Snowflake it really doesn't matter at all, since it allows creating PK and UNIQUE constraints but does not enforce them!

@MartinRied
Copy link
Author

MartinRied commented Sep 8, 2021

Actually I came across the fact that even when using AUTOINCREMENT & UNIQUE & PK on a Snowflake column I can:

  • Manually INSERT a record with PK=1
  • Manually INSERT another record with PK=1
  • INSERT a record without PK - triggering the AUTOINCREMENT - which will produce a third record with PK=1 when I do it for the first time.

All without raising any constraint exceptions..

@KushnirykOleh KushnirykOleh merged commit a64e01f into liquibase:main May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants