diff --git a/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/LiquibaseProcessor.java b/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/LiquibaseProcessor.java index 5903b5749efff..ac6787506dc87 100644 --- a/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/LiquibaseProcessor.java +++ b/extensions/liquibase/deployment/src/main/java/io/quarkus/liquibase/LiquibaseProcessor.java @@ -3,7 +3,13 @@ import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -27,12 +33,18 @@ import io.quarkus.deployment.builditem.CapabilityBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; -import io.quarkus.deployment.builditem.nativeimage.*; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.pkg.steps.NativeBuild; import io.quarkus.deployment.util.ServiceUtil; import io.quarkus.liquibase.runtime.LiquibaseBuildTimeConfig; import io.quarkus.liquibase.runtime.LiquibaseContainerProducer; import io.quarkus.liquibase.runtime.LiquibaseRecorder; +import liquibase.change.Change; +import liquibase.change.core.LoadDataChange; import liquibase.changelog.ChangeLogParameters; import liquibase.changelog.ChangeSet; import liquibase.changelog.DatabaseChangeLog; @@ -82,6 +94,7 @@ void nativeImageConfiguration( liquibase.logging.LogFactory.class.getName(), liquibase.change.ColumnConfig.class.getName(), liquibase.change.AddColumnConfig.class.getName(), + liquibase.change.core.LoadDataColumnConfig.class.getName(), liquibase.sql.visitor.PrependSqlVisitor.class.getName(), liquibase.sql.visitor.ReplaceSqlVisitor.class.getName(), liquibase.sql.visitor.AppendSqlVisitor.class.getName(), @@ -237,7 +250,7 @@ private List getChangeLogs(Collection dataSourceNames, Liquibase // default datasource if (DataSourceUtil.hasDefault(dataSourceNames)) { - resources.addAll(findAllChangeLogs(liquibaseBuildConfig.defaultDataSource.changeLog, changeLogParserFactory, + resources.addAll(findAllChangeLogFiles(liquibaseBuildConfig.defaultDataSource.changeLog, changeLogParserFactory, classLoaderResourceAccessor, changeLogParameters)); } @@ -250,7 +263,7 @@ private List getChangeLogs(Collection dataSourceNames, Liquibase for (String namedDataSourceChangeLog : namedDataSourceChangeLogs) { resources.addAll( - findAllChangeLogs(namedDataSourceChangeLog, changeLogParserFactory, classLoaderResourceAccessor, + findAllChangeLogFiles(namedDataSourceChangeLog, changeLogParserFactory, classLoaderResourceAccessor, changeLogParameters)); } @@ -262,7 +275,7 @@ private List getChangeLogs(Collection dataSourceNames, Liquibase /** * Finds all resource files for the given change log file */ - private Set findAllChangeLogs(String file, ChangeLogParserFactory changeLogParserFactory, + private Set findAllChangeLogFiles(String file, ChangeLogParserFactory changeLogParserFactory, ClassLoaderResourceAccessor classLoaderResourceAccessor, ChangeLogParameters changeLogParameters) { try { @@ -275,6 +288,11 @@ private Set findAllChangeLogs(String file, ChangeLogParserFactory change for (ChangeSet changeSet : changelog.getChangeSets()) { result.add(changeSet.getFilePath()); + changeSet.getChanges().stream() + .filter(c -> c instanceof LoadDataChange) + .map(c -> ((LoadDataChange) c).getFile()) + .forEach(result::add); + // get all parents of the changeSet DatabaseChangeLog parent = changeSet.getChangeLog(); while (parent != null) { diff --git a/integration-tests/liquibase/src/main/resources/db/changeLog.xml b/integration-tests/liquibase/src/main/resources/db/changeLog.xml index fefb1ac2cf9b3..b5455cf33466a 100644 --- a/integration-tests/liquibase/src/main/resources/db/changeLog.xml +++ b/integration-tests/liquibase/src/main/resources/db/changeLog.xml @@ -8,4 +8,5 @@ + diff --git a/integration-tests/liquibase/src/main/resources/db/complex-schema/changeLog.xml b/integration-tests/liquibase/src/main/resources/db/complex-schema/changeLog.xml new file mode 100644 index 0000000000000..fff8b99b60b51 --- /dev/null +++ b/integration-tests/liquibase/src/main/resources/db/complex-schema/changeLog.xml @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/integration-tests/liquibase/src/main/resources/db/complex-schema/data/authority.csv b/integration-tests/liquibase/src/main/resources/db/complex-schema/data/authority.csv new file mode 100644 index 0000000000000..af5c6dfa186d3 --- /dev/null +++ b/integration-tests/liquibase/src/main/resources/db/complex-schema/data/authority.csv @@ -0,0 +1,3 @@ +name +ROLE_ADMIN +ROLE_USER diff --git a/integration-tests/liquibase/src/main/resources/db/complex-schema/data/user.csv b/integration-tests/liquibase/src/main/resources/db/complex-schema/data/user.csv new file mode 100644 index 0000000000000..6052c4250d399 --- /dev/null +++ b/integration-tests/liquibase/src/main/resources/db/complex-schema/data/user.csv @@ -0,0 +1,5 @@ +id;login;password_hash;first_name;last_name;email;image_url;activated;lang_key;created_by;last_modified_by +1;system;$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG;System;System;system@localhost;;true;ru;system;system +2;anonymoususer;$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO;Anonymous;User;anonymous@localhost;;true;ru;system;system +3;admin;$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC;Administrator;Administrator;admin@localhost;;true;ru;system;system +4;user;$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K;User;User;user@localhost;;true;ru;system;system diff --git a/integration-tests/liquibase/src/main/resources/db/complex-schema/data/user_authority.csv b/integration-tests/liquibase/src/main/resources/db/complex-schema/data/user_authority.csv new file mode 100644 index 0000000000000..06c5feeeeace8 --- /dev/null +++ b/integration-tests/liquibase/src/main/resources/db/complex-schema/data/user_authority.csv @@ -0,0 +1,6 @@ +user_id;authority_name +1;ROLE_ADMIN +1;ROLE_USER +3;ROLE_ADMIN +3;ROLE_USER +4;ROLE_USER diff --git a/integration-tests/liquibase/src/test/java/io/quarkus/it/liquibase/LiquibaseFunctionalityTest.java b/integration-tests/liquibase/src/test/java/io/quarkus/it/liquibase/LiquibaseFunctionalityTest.java index 5555d9ab7c61b..04d16376a46a2 100644 --- a/integration-tests/liquibase/src/test/java/io/quarkus/it/liquibase/LiquibaseFunctionalityTest.java +++ b/integration-tests/liquibase/src/test/java/io/quarkus/it/liquibase/LiquibaseFunctionalityTest.java @@ -19,7 +19,7 @@ public void testLiquibaseQuarkusFunctionality() { .get("/liquibase/update") .then() .body(is( - "create-tables-1,test-1,json-create-tables-1,json-test-1,sql-create-tables-1,sql-test-1,yaml-create-tables-1,yaml-test-1")); + "create-tables-1,test-1,json-create-tables-1,json-test-1,sql-create-tables-1,sql-test-1,yaml-create-tables-1,yaml-test-1,00000000000000,00000000000001,00000000000002")); } }