-
Notifications
You must be signed in to change notification settings - Fork 47
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
createIndex if 'NOT indexExists' fails (version 4.15) #283
Comments
hello, any update on it? |
Can we have this fixed pls? |
@r-michal-ah @kb-mendozaACN I don't think it's worth waiting. I've started using Mongock, maybe it will be good choice for you guys. |
@jmayday unfortunately, we can not introduce more tools. have you tried creating via mongodb:runCommand? I wanted to try it as well, but checking here first, just in case someone already tried and failed too. |
Sorry, I don't understand. What you mean exactly? |
I think I tried. But I don't remember exactly, as it was year ago :). I think I exhausted options to use liquibase with Mongo, and there was no support at all (as we see in this thread), so I started checking alternatives and ended up using Mongock. |
I would love to see this implemented to. The workaround I found was not fail the change set if there was an error. Better than nothing. <?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<!--
Mongo Liquibase does not have a precondition to check if an index exists, so set
failOnError to be false. See https://github.com/liquibase/liquibase-mongodb/issues/283.
-->
<changeSet id="4" author="psc" failOnError="false">
<ext:dropIndex collectionName="testers">
<ext:keys>{firstName: 1}</ext:keys>
</ext:dropIndex>
<rollback>
<ext:createIndex collectionName="testers">
<ext:keys>{firstName: 1}</ext:keys>
<ext:options>{name: "firstName_asc"}</ext:options>
</ext:createIndex>
</rollback>
<comment>
Drops the index on the firstName field in the testers collection
</comment>
</changeSet>
</databaseChangeLog> |
Demo project: https://github.com/jmayday/liquibase-demo
Liquibase version: 4.15.0 #4001 built at 2022-08-05 16:17+0000
I'm adding Liquibase integration to project and I would like to prepare a change set creating indexes if they are missing only. Someone already asked about indexExists precondition here #69 but there was no answer.
This is change set without any precondition and it fails with error below (which is all correct, as there is already index with such name):
The error message (again - all is fine, index is already existing so we can't 2nd one with same name):
But if I extend the changeSet with preConditions, then an exception is being thrown:
The error:
Dependency tree:
When debugging I find method liquibase.snapshot.JdbcDatabaseSnapshot#getMetaDataFromCache to do casting which throws exception because getDatabase().getConnection() is a MongoConnection:
Whole stacktrace below:
The text was updated successfully, but these errors were encountered: