Skip to content

fix: Add 'DEFAULT' to column definition when creating columns with a defaultValue - #438

Open
pvlov wants to merge 1 commit into
liquibase:mainfrom
pvlov:main
Open

fix: Add 'DEFAULT' to column definition when creating columns with a defaultValue#438
pvlov wants to merge 1 commit into
liquibase:mainfrom
pvlov:main

Conversation

@pvlov

@pvlov pvlov commented Dec 2, 2025

Copy link
Copy Markdown

When creating tables with columns which use defaultValue, the sqlgenerator does not add the DEFAULT keyword and some whitespace leading to syntactically wrong SQL being generated and then executed. See [1] for more details on default values in big query.

So, for a changelog like this:

databaseChangeLog:
  ....
  - createTable
     tableName: Foo
     columns:
        - column:
           name: bar
           type: STRING
           defaultValue: "BAZ"

The generator will end up generating something like this:

CREATE TABLE mydataset.Foo (bar STRING'BAZ');

[1] https://docs.cloud.google.com/bigquery/docs/default-values

@coderabbitai

coderabbitai Bot commented Dec 2, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

BigQueryCreateTableGenerator now appends a DEFAULT clause when emitting SQL for columns with non-auto-increment types and default values. A corresponding test method verifies this behavior with a STRING column containing a default value.

Changes

Cohort / File(s) Summary
SQL Generation Logic
src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java
Modified to append DEFAULT clause before emitting default values for non-auto-increment columns, applicable to both DatabaseFunction and literal defaults.
Test Coverage
src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java
Added new test method generateSqlWithDefaultValue() that verifies DEFAULT clause generation for STRING-typed columns with default values. Added imports: DataTypeFactory, DatabaseDataType, LiquibaseSerializable, and DataType.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify that the DEFAULT clause is only applied when the column is non-auto-increment
  • Confirm the DEFAULT clause behavior handles both DatabaseFunction and literal default values correctly
  • Ensure the new test properly validates the expected SQL output format

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and accurately describes the main fix: adding 'DEFAULT' keyword to column definitions with defaultValue, which matches the core change in the implementation.
Description check ✅ Passed The pull request description clearly explains the issue being fixed: missing DEFAULT keyword in SQL generation for columns with defaultValue, provides a concrete example of the incorrect SQL output, and references BigQuery documentation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java (1)

3-4: Consider removing unused imports.

The imports DatabaseDataType, LiquibaseSerializable, and DataType don't appear to be used in the test class. Consider removing them to keep the imports clean.

Apply this diff to remove unused imports:

-import liquibase.datatype.DatabaseDataType;
 import liquibase.ext.bigquery.database.BigQueryDatabase;
-import liquibase.serializer.LiquibaseSerializable;
 import liquibase.sql.Sql;
 import liquibase.statement.core.CreateTableStatement;
-import liquibase.structure.core.DataType;

Also applies to: 6-6, 9-9

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 44683a7 and 84867e3.

📒 Files selected for processing (2)
  • src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java (1 hunks)
  • src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java (2 hunks)
🔇 Additional comments (2)
src/main/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGenerator.java (1)

61-70: LGTM! The DEFAULT keyword is correctly added.

The change properly adds the DEFAULT keyword with appropriate spacing before the default value. The logic correctly handles both DatabaseFunction and literal defaults, and the condition guards ensure that DEFAULT is only emitted for non-auto-increment columns that have a default value.

src/test/java/liquibase/ext/bigquery/sqlgenerator/BigQueryCreateTableGeneratorTest.java (1)

36-43: LGTM! Test validates the DEFAULT clause fix.

The test correctly verifies that the generated SQL includes the DEFAULT keyword for a column with a default value. The assertion confirms the expected format: CREATE TABLE schema.table (name STRING DEFAULT 'default_name').

…REATE TABLE' statement to avoid invalid SQL being generated
@sonarqubecloud

Copy link
Copy Markdown

@filipelautert
filipelautert requested a review from a team February 11, 2026 16:35
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.

2 participants