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
Improve addColumn handling in SQLite #1970
Conversation
- Added jdbc driver as test dependency - Fixed handling of multi-column addColumn statements - Fix handling of onDelete=cascade for existing columns and new columns - Do not include "null" values in yaml/json snapshot serializers - Correctly escape object names in CopyRowsGenerator
- Fixed dropColumn with multiple columns
- SQLiteIntegrationTest is broken enough I had to take the dependency out so it doesn't run as part of the builds at this point.
@@ -160,6 +161,10 @@ protected String cleanNameFromDatabase(String objectName, Database database) { | |||
} | |||
|
|||
} | |||
|
|||
if (returnList.size() == 0 && database instanceof SQLiteDatabase) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we expand this to other DBs? I found Firebird need same fix as it also fails with liquibase.exception.UnexpectedLiquibaseException: Found a null snapshotId for catalog null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing if condition to include (database instanceof SQLiteDatabase || database instanceof FirebirdDatabase) helps with Firebird snapshot generation, but maybe this can be expanded further
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nvoxland -- please see @KushnirykOleh's comment above and provide guidance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is probably safe to include for all database, not just sqlite and firebird. I updated the code to just be if (returnlist.size() == 0)
Environment
Liquibase Version: 4.4.0
Database Vendor & Version: SQLite
Description
Fixed a variety of issues with SQLite in addColumn. These problems were found by existing liquibase-test-harness tests that are now passing.
Fixed handling of multi-column addColumn statements
Sqlite failed running
liquibase update
with an addColumn change that used multiple columns.Repo Steps
liquibase update
Without the fix, it did not correctly add all 3 columns.
Fixed onDelete cascade
The
onDelete=cascade
for argument was not respected inaddColumn
changes. And, if a table contains existing foreign keys with onDelete=cascade, adding columns to that table loses that setting.Repo Steps:
Fixed multi-column dropColumn
Sqlite failed running
liquibase update
with an dropColumn change that used multiple columns.Repo Steps
liquibase update
Without the fix, it failed with a "column does not exist" error.
ALTERNATE:
<addColumn>
using multiple nested {{}}s.liquibase update
to apply itliquibase rollbackCount 1
to roll it backWithout the fix, it failed with a "column does not exist" error.
JSON Snapshot Serializer should not serialize null values
Sqlite does not use a username, and
liquibase snapshot --format json
would includeusername: "null"
which is not correct. Instead, null values should be not included.Repo steps
liquibase snapshot --format json
The output should not include "null" for username or any attributes.
AddColumn fails with mixed-case column names
Fixed an issue with how quoting was used in the CopyRowsGenerator logic that is ran as part of addColumn. The multi-column example from test harness was using mixed-case column names which tripped up on the way quoting was done before.
Repo Steps
<createTable>
with all objects quoted, and mixed casing on column names<addColumn>
to the tableliquibase
updatePrior to the fix, the update failed
Dev Handoff Notes (Internal Use)
Links
Testing
Dev Verification
Ran a variety of addColumn and dropColumn tests locally, as well as ensured the test harness did not hit these problems anymore.
Test Requirements (Liquibase Internal QA)
Manual Tests
Add and Drop Multi-Column Changesets
Execute the manual tests against any of the Liquibase certified database platforms. After you deploy the XML changesets for creating the table and adding columns, you can use
liquibase generate-changelog
to create the JSON and YML changelogs. Of course, you do not want to try and generate those changelogs after you run the dropColumn changeset!XML
Verify an update of a multi-column addColumn changeset is successful.
liquibase update --changelog-file <yourchangelog.xml> --labels table,addColumns
Verify an update of a multi-column dropColumn changeset is successful.
liquibase update --changelog-file <yourchangelog.xml> --labels dropColumns
Manual Test: Null Username in Snapshot
Setup
jdbc:sqlite:./src/test/resources/sqlite/sqlite.db
Verify that a JSON snapshot does not have “null” for the username.
liquibase snapshot --format json
Manual Test: Casing
Verify adding columns to a table with mixed-case columns is successful.
liquibase update --changelog-file <yourchangelog.xml> --labels table,data,addColumns
Verify the data is present in the table after update is complete.
select * authors
Automated Tests
┆Issue is synchronized with this Jira Bug by Unito