Re : How do I get Liquibase to print out the SQL it generated?
Drop-create data after each test with SpringLiquibase
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
Inheritable contexts
Cannot pass property using -Dproperty=value
- liquibase -Dtable_owner=foo --defaultsFile=connection.properties --changeLogFile=changelog.xml update
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)
- liquibase --defaultsFile=connection.properties --changeLogFile=changelog.xml update -Dtable_owner=foo
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?
Re : Cannot pass property using -Dproperty=value
- liquibase --defaultsFile=connection.properties --changeLogFile=changelog.xml update -Dtable_owner=foo
Re : Cannot pass property using -Dproperty=value
Sorry for the noise.
Re : Can I add changelog property to liquibase.properties file?
- #Liquibase.properties
- driver: oracle.jdbc.OracleDriver
- classpath: ojdbc7.jar
- url: jdbc:oracle:thin:@10.0.2.1:1521:mydb
- username: USER
- password: pswd
-
parameter.connection_string: user/pswd@mydb
Liquibase problems with converting TINYINT(1) to BIT
Liquibase: Data truncation: Data too long for column 'LOCKED' at row 1 [Failed SQL: INSERT INTO hgigoc.databasechangeloglock (ID, LOC
KED, LOCKGRANTED, LOCKEDBY) VALUES ('1', '0', NULL, NULL)]
Please, review the idea of treating TINYINT as BIT since all it acomplishes is making problems.
Liquibase unknown database error.
slash / after plsql block in sql script included by sqlFile tag
Re : How to add JSONB columns for PostgreSQL?
- <column name="doc" type="jsonb"/>
Re : slash / after plsql block in sql script included by sqlFile tag
* only put one procedure into one SQL file.
* end the procedure definition with a / on a single line.
Then use the <sqlFile> tag to run the script and define the proper endDelimiter:
-
<sqlFile path="create_proc.sql"
relativeToChangelogFile="true"
stripComments="false"
splitStatements="true" endDelimiter="\n/" />
If you do want to keep multiple PL/SQL CREATE statements in a single file, then use
- endDelimiter="\n/\n"
together with splitStatements="true". I think that works fine as well. But I haven't used that for ages.
includeAll not working for multimodule project with spring
-
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="dataSource"/>
<property name="changeLog" value="classpath:db-changelog.xml" />
</bean>
-
<databaseChangeLog>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<includeAll path="classpath:sql/" />
</databaseChangeLog>
.
├── Module1
│ ├── src
│ │ └── main
│ │ └── resources
│ │ ├── db-changelog.xml
│ │ └── sql
│ │ ├── 001-test.sql
│ │ └── 002-test.sql
│ └── target
│ ├── classes
│ │ ├── db-changelog.xml
│ │ └── sql
│ │ ├── 001-test.sql
│ │ └── 002-test.sql
│ └── Module1-1.0-SNAPSHOT.jar
|
└─ Module2
├── src
│ └── main
│ └── resources
│ ├── applicationContext.xml
│ └── mybatis-config.xml
└── target
├── classes
│ ├── applicationContext.xml
│ └── mybatis-config.xml
└── Module2-1.0-SNAPSHOT.jar
INFO 30.11.15 01:05: liquibase: Successfully acquired change log lock
WARNING 30.11.15 01:05: liquibase: included file classpath:db-changelog.xml/ is not a recognized file type
Working
.
├── Module1
│ ├── src
│ │ └── main
│ │ └── resources
│ └── target
│ ├── classes
│ │ └── oceniarka
│ └── Module1-1.0-SNAPSHOT.jar
│
└── Module2
├── src
│ └── main
│ └── resources
│ ├── applicationContext.xml
│ ├── db-changelog.xml
│ ├── mybatis-config.xml
│ └── sql
│ ├── 001-test.sql
│ └── 002-test.sql
└── target
├── classes
│ ├── applicationContext.xml
│ ├── db-changelog.xml
│ ├── mybatis-config.xml
│ └── sql
│ ├── 001-test.sql
│ └── 002-test.sql
└── Module2-1.0-SNAPSHOT.jar
INFO 30.11.15 01:14: liquibase: Successfully acquired change log lock
WARNING 30.11.15 01:14: liquibase: included file classpath:db-changelog.xml/ is not a recognized file type
INFO 30.11.15 01:14: liquibase: Reading from oceniarka.DATABASECHANGELOG
INFO 30.11.15 01:14: liquibase: classpath:db-changelog.xml: sql/002-test.sql::raw::includeAll: Custom SQL executed
INFO 30.11.15 01:14: liquibase: classpath:db-changelog.xml: sql/002-test.sql::raw::includeAll: ChangeSet sql/003-test.sql::raw::includeAll ran successfully in 17ms
This happens for reading sql or xml files both. Problem exists only for running application from jar. I would classify this as a bug because spring properly recognize db-changelog.xml in other module, but master changelog cannot reference sql directory with "include all". I think this is happens because liquibase use some module relative variable for recognizing path.
Referencing files from another module by including one-by-one ("include file" instead "includeAll") works fine. I would be very grateful for fixing the bug or some workaround. Also sorry for my english and formatting (it looks like i seriously messed up something in html).
Re : Liquibase unknown database error.
Re : Liquibase unknown database error.
This is required by the SQL standard: unquoted identifiers have to be stored in uppercase and they have to be case-insensitive.Several databases do things like that - automatically convert the case of all table names, etc. written to the database to either uppercase or lowercase
Unable to generate offline migration script for PostgreSQL database
- <plugin>
- <groupId>org.liquibase</groupId>
- <artifactId>liquibase-maven-plugin</artifactId>
- <version>3.4.2</version>
- <executions>
- <execution>
- <id>liquibase-postgresql-offline</id>
- <configuration>
- <changeLogFile>src/main/resources/liquibase/db-changelog-master.xml</changeLogFile>
- <url>offline:postgresql?changeLogFile=${project.build.directory}/liquibase/postgresql/changelog.csv</url>
- <migrationSqlOutputFile>${project.build.directory}/liquibase/postgresql/migrate.sql</migrationSqlOutputFile>
- <outputFileEncoding>UTF-8</outputFileEncoding>
- </configuration>
- <phase>process-resources</phase>
- <goals>
- <goal>updateSQL</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
Re : Unable to generate offline migration script for PostgreSQL database
New utility for testing your Liquibase changelog using H2 and JUnit
SQL scripts should have "USE " in the header on SQL Server
Liquibase spring bean "log" property
Currently I have in my log4j.properties file a line like this:
log4j.appender.liquibase=org.apache.log4j.RollingFileAppender
and I would like to use this as my default liquibase logger.
Thanks in advance.