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

Support Mysql Function Indexes #2180

Merged
merged 4 commits into from Nov 15, 2021
Merged

Support Mysql Function Indexes #2180

merged 4 commits into from Nov 15, 2021

Conversation

nvoxland
Copy link
Contributor

@nvoxland nvoxland commented Nov 4, 2021

Description

Moved the "select the index metadata" SQL from the driver to our code so that we can also pull from the new column if we have a new enough database.

Fixes #1626 as well as generally snapshots indexes with functions correctly now.

Impact

On Mysql 8.0.13+ create a table and index like:

create table my_table (id int primary key, first_name varchar(50), last_name varchar(50));
create index idx_test on my_table((lower(first_name)));

When running liquibase snapshot you now see the idx_test index.

On older mysql versions, you can't create the index with the lower(first_name) function, but an index like create index idx_test on my_table(first_name); is still correctly found without a SQL error.

Because this snapshot functionality works now, the reported indexExists precondition works as well.


Dev Handoff Notes (Internal Use)

Links

Testing

Dev Verification

Tested snapshot and precondition check on both the latest mysql 8 and 5.7 versions

Test Requirements (Liquibase Internal QA)

Testing this ticket requires a MySQL 5.7 instance and a MySQL 8 instance. One test case will require a Pro license to validate the JSON snapshot feature correctly gathers the function index.

Manual Tests

Setup the SQL in

  • On a MySQL 8 database, execute the SQL in the attached lb2160-setup.sql.
  • on a MySQL 5.7 database. execute the SQL in the attached lb2160-setup-mysql5.sql

Verify snapshot of a MySQL 8 database includes an index that uses a function.

liquibase --output-file mysql8-snapshot.txt snapshot

  • Snapshot includes index idx_lb2160 on table lb2160

Pro: Verify JSON formatted snapshot of a MySQL 8 database includes the

liquibase --output-file mysql8-pro-snapshot.json snapshot --snapshot-format JSON

  • Snapshot includes index idx_lb2160 on table lb2160

Verify validate of an indexExists precondition correctly identifies existence of an index that uses a function.

liquibase --log-level INFO validate--changelog-file lb2160-changelog.xml

  • The indexExists precondition triggers.

Validation Error:
1 preconditions failed
lb2160-changelog.xml : index idx_lb2160 already exists
Liquibase command 'validate' was executed successfully.




**Automated Tests**

* No new functional test is required for this ticket.
* A new test harness test is required for this ticket. There is already a test for the MySQL 5.7 createIndex. The new test will be mySQL 8.0 specific as earlier versions of MySQL do not support creating indexes that use functions.
* Add an XML changelog with two changesets:
  * createTable
  * createIndex
  * Name your file createFunctionIndex.xml
  * liquibase-test-harness/main/src/main/resources/liquibase/harness/change/changelogs/mysql
* Add the JSON snapshot for test validation:
  * src/main/resources/liquibase/harness/change/expectedSnapshot/mysql/8
* Add the generated SQL for test validation:
  * src/main/resources/liquibase/harness/change/expectedSql/mysql/8.0
* Validate that Liquibase correctly generates SQL for MySQL indexes that use functions.



┆Issue is synchronized with this [Jira Bug](https://datical.atlassian.net/browse/LB-2160) by [Unito](https://www.unito.io)

… driver.

Moved SQL from the driver to our code so that we can also pull from the new column if we have a new enough database.
@nvoxland nvoxland added this to To Do in Conditioning++ via automation Nov 4, 2021
@nvoxland nvoxland moved this from To Do to Code Review in Conditioning++ Nov 4, 2021
@suryaaki2 suryaaki2 moved this from Code Review to Ready for Handoff (In JIRA) in Conditioning++ Nov 8, 2021
@sync-by-unito
Copy link

sync-by-unito bot commented Nov 15, 2021

➤ Kristyl Gomes commented:

Jack Odzhubeiskyi Surya Aki Erzsebet Carmean – the test-harness PR (liquibase/liquibase-test-harness#139 ( https://github.com/liquibase/liquibase-test-harness/pull/139|smart-link ) ) has been approved by me.

Please note that merging the test-harness PR will need to wait until the fix (#2180 ( #2180 )) is shipped with the next release of Liquibase Core, otherwise this test will fail.

@nvoxland nvoxland merged commit b9244d4 into master Nov 15, 2021
Conditioning++ automation moved this from Ready for Handoff (In JIRA) to Done Nov 15, 2021
@nvoxland nvoxland deleted the mysql-function-indexes branch November 15, 2021 15:40
@nvoxland nvoxland removed this from Done in Conditioning++ Dec 1, 2021
@nvoxland nvoxland added this to the v4.6.2 milestone Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

indexExists precondition not working for function index in MySQL 8
3 participants