maven cargo
部署我的Spring
应用程序。MySQL
和H2
嵌入式数据库运行此功能
H2
的配置类似于@Configuration @Profile("development") public class H2DatabaseConfig extends JpaCommonConfig { @Override public DataSource dataSource() { // (todo: harit) get rid of hard coding System.out.println("This is H2 Database Profile"); final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUrl("jdbc:h2:mem:test_common"); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; } @Override protected Class<? extends Dialect> getDatabaseDialect() { return H2Dialect.class; } @Override protected Properties getJpaProperties() { final Properties properties = new Properties(); properties.setProperty(HBM2DDL_AUTO, Hbm2ddlType.CREATE_DROP.toValue()); properties.setProperty(SHOW_SQL, TRUE.toString()); properties.setProperty(FORMAT_SQL, TRUE.toString()); properties.setProperty(USE_SQL_COMMENTS, TRUE.toString()); properties.setProperty(CONNECTION_CHAR_SET, getHibernateCharSet()); properties.setProperty(NAMING_STRATEGY, ImprovedNamingStrategy.class.getName()); return properties; } }
和MySQL
看起来像
@Configuration
@Profile("default")
public class MySqlDatabaseConfig extends JpaCommonConfig {
@Override
public DataSource dataSource() {
// (todo: harit) remove hardcoding to read from environment variables
System.out.println("This is MySQL Database Profile");
final BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://localhost:3306/test_common?createDatabaseIfNotExist=true");
dataSource.setUsername("root");
return dataSource;
}
@Override
protected Class<? extends Dialect> getDatabaseDialect() {
return MySQL5InnoDBDialect.class;
}
@Override
protected Properties getJpaProperties() {
final Properties properties = new Properties();
properties.setProperty(HBM2DDL_AUTO, Hbm2ddlType.UPDATE.toValue());
properties.setProperty(SHOW_SQL, TRUE.toString());
properties.setProperty(FORMAT_SQL, TRUE.toString());
properties.setProperty(USE_SQL_COMMENTS, TRUE.toString());
properties.setProperty(CONNECTION_CHAR_SET, getHibernateCharSet());
properties.setProperty(NAMING_STRATEGY, ImprovedNamingStrategy.class.getName());
return properties;
}
}
当我使用货物运行集成测试时,我看到两个不同之处,
MySQL
运行时,Liquibase运行时会关注模式名称,我看到 test_common INFO 5/26/14 9:18 AM:liquibase: Successfully acquired change log lock INFO 5/26/14 9:18 AM:liquibase: Dropping Database Objects in schema: test_common.test_common INFO 5/26/14 9:18 AM:liquibase: Creating database history table with name: test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase: Successfully released change log lock INFO 5/26/14 9:18 AM:liquibase: Successfully acquired change log lock INFO 5/26/14 9:18 AM:liquibase: Reading from test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase: Reading from test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase: Reading from test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Reading from
test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2:创建表网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2:ChangeSet liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2在8ms内成功运行 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2:阅读 test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:阅读 test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:ChangeSet liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2在6ms内成功运行 INFO 5/26/14 9:18 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:阅读 test_common.DATABASECHANGELOG INFO 5/26/14 9:18 AM:liquibase:已成功发布更改日志锁
H2
运行时,它适用于 PUBLIC 架构, test_common INFO 5/26/14 9:45 AM:liquibase: Successfully acquired change log lock INFO 5/26/14 9:45 AM:liquibase: Dropping Database Objects in schema: TEST_COMMON.PUBLIC INFO 5/26/14 9:45 AM:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase: Successfully released change log lock INFO 5/26/14 9:45 AM:liquibase: Successfully acquired change log lock INFO 5/26/14 9:45 AM:liquibase: Reading from PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase: Reading from PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase: Reading from PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Reading from
PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2:创建表网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2:ChangeSet liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2在5ms内成功运行 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-1.xml :: 05192014.1525 :: h2:阅读 PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:阅读 PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:插入新行 网络 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:ChangeSet liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2在5ms内成功运行 INFO 5/26/14 9:45 AM:liquibase:liquibase / changelog.xml:liquibase / 2014 / 1-2.xml :: 05192014.1525 :: h2:阅读 PUBLIC.DATABASECHANGELOG INFO 5/26/14 9:45 AM:liquibase:已成功发布更改日志锁定
这里出了什么问题?
答案 0 :(得分:0)
Liquibase尝试处理“模式”和“目录”,其中目录是可能包含或可能不包含模式的最顶层容器。对于像MySQL这样只有一级对象分组的数据库,“目录”和“模式”是可以互换的。对于H2,您可以同时拥有数据库中的目录/数据库和模式。您的h2设置使用的是test_common数据库,但是该数据库中的默认PUBLIC模式。
如果您想要将Liquibase配置为使用非默认的H2模式,请使用“defaultSchema”SpringLiquibase配置属性。