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

[DAT-18790] added defaultValue snapshotting #192

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

KushnirykOleh
Copy link
Contributor

No description provided.

@liquibase liquibase deleted a comment from sonarcloud bot Oct 24, 2024
@SvampX SvampX marked this pull request as ready for review October 24, 2024 12:41
@SvampX
Copy link
Contributor

SvampX commented Oct 24, 2024

Should work for most cases except:
Default value is calculated by a function with multiple arguments like eventDate DATE DEFAULT coalesce(CAST(CURRENT_TIMESTAMP() AS DATE), CAST('2024.09.09' AS DATE))

Column column = (Column) super.snapshotObject(example, snapshot);
//These two are used too often, avoiding them? otherwise there would be too much DB calls
if (!column.getRelation().getName().equalsIgnoreCase("databasechangelog")
&& !column.getRelation().getName().equalsIgnoreCase("databasechangeloglock")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even with skipping DBCL and DBCLL we are making additional call for every column. We have info for all columns in show create table.
column.getRelation() has all the columns, so we can iterate over them and add defaultValue information for all columns at once

Copy link
Contributor

Choose a reason for hiding this comment

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

@SvampX as discussed, maybe DatabaseSnapshot.snapshotScratchPad could be useful to cache this information between executions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Moved show create table call to the Table snapshot generator. Storing create table statement in the snapshotScratchPad suggested by @filipelautert with a show create table query as key. I believe such keys should be unique within a database as the query has full table name with catalog and schema.

if (example instanceof Column) {
Column column = (Column) super.snapshotObject(example, snapshot);
//These two are used too often, avoiding them? otherwise there would be too much DB calls
if (!column.getRelation().getName().equalsIgnoreCase("databasechangelog")
Copy link
Contributor Author

@KushnirykOleh KushnirykOleh Oct 25, 2024

Choose a reason for hiding this comment

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

tracking tables can have custom names.
better to use database.getDatabaseChangeLogTableName() and database.getDatabaseChangeLogLockTableName()

Column column = (Column) super.snapshotObject(example, snapshot);
//These two are used too often, avoiding them? otherwise there would be too much DB calls
if (!column.getRelation().getName().equalsIgnoreCase("databasechangelog")
&& !column.getRelation().getName().equalsIgnoreCase("databasechangeloglock")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@SvampX as discussed, maybe DatabaseSnapshot.snapshotScratchPad could be useful to cache this information between executions.

… one per table for column default values. updated test
Copy link
Contributor

@filipelautert filipelautert left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor Author

@KushnirykOleh KushnirykOleh left a comment

Choose a reason for hiding this comment

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

Looks good.
(I can't approve as i opened PR originally)

Copy link

sonarcloud bot commented Nov 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

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.

4 participants