Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/
- LiquibaseConfiguration.getInstance().getConfiguration(GlobalConfiguration.class).setShouldRun(false)
from somewhere in your code that executes before the CDI bootstrapping happens, possibly in a class's static{} block?
Nathan
Nathan
Hi,
I’m using Gradle 2.7, the Liquibase 1.1.1 plugin and attempting to run my changeset on an Apache Derby (v. 10.12.1.1) in-memory database. Running the following changeSet fails immediately on the first changeSet …
[code]
<changeSet author="my" id="add_my_project_address">
<createTable tableName="my_project_address">
<column defaultValue="" name="id" type="VARCHAR(32)">
<constraints nullable="false" primaryKey="true"/>
</column>
<column defaultValue="" name="address" type="VARCHAR(500)">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="city" type="VARCHAR(100)">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="state" type="VARCHAR(10)">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="zip" type="VARCHAR(10)">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="lattitude" type="INT UNSIGNED">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="longitude" type="INT UNSIGNED">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="email" type="VARCHAR(200)">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="phone" type="VARCHAR(32)">
<constraints nullable="true"/>
</column>
<column defaultValue="" name="phone_type" type="VARCHAR(10)">
<constraints nullable="true"/>
</column>
</createTable>
</changeSet>
[/code]
How can I configure Liquibase to output the SQL generated? Here is how I have set up the plugin …
[code]
liquibase {
activities {
main {
File propsFile = new File("${project.rootDir}/src/main/environment/${environment}/liquibase.properties")
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile 'src/main/resources/db.changelog-master.xml'
url properties['url']
username properties['username']
password properties['password']
}
test {
File propsFile = new File(liquibasePropertiesFile)
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile 'src/main/resources/db.changelog-master.xml'
url 'jdbc:derby:memory:test-jpa;create=true'
username 'sa'
}
runList = 'main,test'
}
}
[/code]
For what its worth, this is all Liquibase tells me when the above is run …
[code]
SEVERE 10/27/15 4:02 PM: liquibase: src/main/resources/db.changelog-master.xml: src/main/resources/db.changelog-1.0.xml::add_my_project_address::my: Change Set src/main/resources/db.changelog-1.0.xml::add_my_project_address::my failed. Error: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "," at line 1, column 224.
liquibase.exception.DatabaseException: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "," at line 1, column 224.
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:316)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:122)
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1227)
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1210)
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:550)
at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:43)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:73)
at liquibase.Liquibase.update(Liquibase.java:200)
at liquibase.integration.commandline.Main.doMigration(Main.java:1044)
at liquibase.integration.commandline.Main.run(Main.java:175)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.liquibase.gradle.LiquibaseTask.runLiquibase(LiquibaseTask.groovy:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[/code]
I'm using Springliquibase 3.3.2. I read the datas for db in csv files.
I have unit tests running with SpringLiquibase and I wanted the database returned to it's initial state after each test run.
I'm setting dropFirst == true and was expecting this to restore the hsql db but it does not. I see data changes in one test that were performed in previous tests. My code to define the SpringLiquibase :
@Configuration
@EnableJpaRepositories(basePackages={"my.package"}) @EntityScan(basePackages={"my.package"}) @EnableTransactionManagement public class DatabaseConfiguration implements EnvironmentAware { private RelaxedPropertyResolver propertyResolver; private Environment env; private DataSource dataSource; private SpringLiquibase springLiquibase; @Autowired(required = false) private MetricRegistry metricRegistry; @Override public void setEnvironment(Environment env) { this.env = env; this.propertyResolver = new RelaxedPropertyResolver(env, "spring.datasource."); } @Bean(destroyMethod = "shutdown") @ConditionalOnMissingClass(name = "fr.ticks.pp.front.config.HerokuDatabaseConfiguration") @Profile("!" + "cloud") public DataSource dataSource() { log.debug("Configuring Datasource"); if (propertyResolver.getProperty("url") == null && propertyResolver.getProperty("databaseName") == null) { log.error("Your database connection pool configuration is incorrect! The application" + "cannot start. Please check your Spring profile, current profiles are: {}", Arrays.toString(env.getActiveProfiles())); throw new ApplicationContextException("Database connection pool is not configured correctly"); } HikariConfig config = new HikariConfig(); config.setDataSourceClassName(propertyResolver.getProperty("dataSourceClassName")); if (propertyResolver.getProperty("url") == null || "".equals(propertyResolver.getProperty("url"))) { config.addDataSourceProperty("databaseName", propertyResolver.getProperty("databaseName")); config.addDataSourceProperty("serverName", propertyResolver.getProperty("serverName")); } else { config.addDataSourceProperty("url", propertyResolver.getProperty("url")); } config.addDataSourceProperty("user", propertyResolver.getProperty("username")); config.addDataSourceProperty("password", propertyResolver.getProperty("password")); if (metricRegistry != null) { config.setMetricRegistry(metricRegistry); } dataSource = new HikariDataSource(config); return dataSource; } @Bean public SpringLiquibase liquibase(DataSource dataSource) { SpringLiquibase liquibase = new SpringLiquibase(); liquibase.setDataSource(dataSource); liquibase.setChangeLog("classpath:config/liquibase/master.xml"); liquibase.setContexts("development, production"); // ne lance liquibase que si on utilise H2 en mémoire boolean runningH2 = isRunningH2(); liquibase.setShouldRun(runningH2); if (runningH2) { log.debug("Configuring Liquibase for H2"); } return liquibase; }
And my test file :
@RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest public abstract class AbstractPPTest { @Autowired protected ApplicationContext applicationContext; protected MockWebServiceClient mockClient; @Before public void initMock() { assertNotNull(applicationContext); mockClient = MockWebServiceClient.createClient(applicationContext); testDate = Calendar.getInstance(); } @Test public void test { ... }
Is there a non-manual (or manual) way to reset the data between tests in test files ?
Thanks
results in the error:
(Needless to say that --Dtable_owner=foo doesn't work either)Errors:
Unexpected value -Dtable_owner=foo: parameters must start with a '--'
Usage: java -jar liquibase.jar [options] [command]
When I try the -D at the end of the line (as shown here)
I get the error:
Unexpected error running Liquibase: Unknown parameter: 'table_owner'
SEVERE 11/3/15 10:41 AM: liquibase: Unknown parameter: 'table_owner'
liquibase.exception.CommandLineParsingException: Unknown parameter: 'table_owner'
at liquibase.integration.commandline.Main.parsePropertiesFile(Main.java:453)
at liquibase.integration.commandline.Main.run(Main.java:159)
at liquibase.integration.commandline.Main.main(Main.java:99)
What am I missing?
I am using Liquibase 3.4.1
How do I pass a parameter (that is used with
"${table_owner}" in the changeLog) on the command line?