当前位置: 首页 > 知识库问答 >
问题:

LiquiBase:不支持H2的模式名称,但MySQL可以

栾越
2023-03-14
  • 我正在使用Maven Cargo部署我的Spring应用程序。
  • 我正在尝试对MySQLH2嵌入式数据库运行此操作。
    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;
    }
}
@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;
    }
}

当我使用cargo运行集成测试时,我看到了两个区别,

  1. 当对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信息5/26/14 9:18 am:LiquiBase:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/2014/1-1.xml::05192014.1525::h2:表网络创建的信息5/26/14 9:18 am:LiquiBase/Changelog.xml:LiquiBase/2014/1-1.xml::05192014.1525::h2:ChangeSet.DatabaseChangelog INFO 5/26/14 9:18 AM:LiquiBase:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml.xml:05192014.1525::H2:读取test_common.DatabaseChangelog INFO 5/26/14 9:18 AM::Liquibase/2014/1-2.xml::05192014.1525::h2:新行插入网络work INFO 5/26/14 9:18 AM:LiquiBase:LiquiBase/Changelog.xml: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/Changelog.xml:LiquiBase/2014/1-2.xml::05192014.1525::H2:将新行插入网络INFO 5/26/14 9:18 AM: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:成功释放变更日志锁

  1. 当针对h2运行时,它将应用于公共架构,而不应用于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信息5/26/14 9:45上午:LiquiBase:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml信息5/26/14 9:45 AM:LiquiBase:LiquiBase/Changelog.xml:LiquiBase/Changelog.xml:LiquiBase/2014/1-2.xml::05192014.1525::h2:正在读取Public.DatabaseChangelog信息5/26/14 9:45 AM:LiquiBase:LiquiBase/Changelog.xml:LiquiBase/2014/1-2.xml::05192014.1525::h2:插入到网络信息中的新行.xml::05192014.1525::h2:新行插入网络信息5/26/14 9:45 AM:LiquiBase:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase/changelog.xml:LiquiBase 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:成功释放变更日志锁

这里出了什么问题?

共有1个答案

吕新
2023-03-14

Liquibase尝试同时处理“模式”和“目录”,其中目录是最顶部的容器,可以包含模式,也可以不包含模式。对于像MySQL这样只有一级对象分组的数据库,“目录”和“模式”是可以互换的。对于H2,您可以在数据库中同时拥有目录/数据库和模式。您的h2安装程序使用的是test_common数据库,但使用的是该数据库中的默认公共模式。

如果您希望配置Liquibase以使用非默认的H2模式,请使用“DefaultSchema”SpringLiquibase配置属性。

 类似资料:
  • 我正在尝试使用H2内存数据库为java应用程序编写一些功能测试。因为我们使用Oracle作为生产数据库,所以一些代码是用PL/SQL编写的。所以我打开了Oracle兼容模式,现在我的url看起来像这样:。 我遇到问题的实际应用程序代码如下所示(注意,序列和表都是在调用之前创建的): 它失败了,错误与我为测试

  • 支持的颜色名称列表 基础颜色关键词: 颜色名 十六进制RGB值 black(黑) #000000 silver(银) #C0C0C0 gray(灰) #808080 white(白) #FFFFFF maroon(褐紫红) #800000 red(红) #FF0000 purple(紫) #800080 fuchsia(晚樱) #FF00FF green(绿) #008000 lime(石灰) #

  • 我试图在solaris虚拟机上安装Liquibase 3.6.1。< br >我的JRE是1.6.0_151-b10。< br >我的Liquibase.properties文件配置如下: 例如,当调用“./液基--版本”时,我收到一个错误。 线程“Main”Java . lang . unsupportedclassversionerror:liqui base/integration/comm

  • Liquibase是协调数据库更改的好工具。我在集群环境中启动时运行liquibase变更集。第一个应用程序实例放置一个锁(在databasechangeloglock表中)并执行变更集。其他实例在抓取锁时,只将执行的变更集标记为MARK_RAN。到现在为止,一直都还不错。 最近有一个问题,我不得不深入研究databasechangelog表的细节。我希望在元信息中看到实例名(机器名)。但我在那里

  • 我是H2新手,但我读了很多留档,我成功地创建了嵌入式H2 mem或文件数据库。 但我仍然无法使用服务器模式或混合模式: 我像这样启动我的Web服务器和tcp服务器: 正在尝试服务器模式: 我创建文件数据库如下: > jd bc: h 2:~/ma Base H 2 Fic hier TCP 用户名:sa 密码: 数据库已创建,我看到一个锁文件 > url: jdbc: h2:tcp://local

  • 我可以用“小”函数定义“大”函数: 我可以这么说: 另一方面,如果我想多次使用同一个函数并为其使用名称,我就会遇到问题: 最后一行是禁止的。留言: 为什么?对我来说,plus2和plus2是一样的东西? 这篇文章有一个答案,建议在我的例子中使用::plus2。这在技术上有帮助,但不能解释这两种功能之间的区别。