I am using Liquibase
for my database updates and testing it against H2
.
我正在使用Liquibase进行数据库更新并针对H2进行测试。
I am using Spring
to configure the properties. I use
我使用Spring来配置属性。我用
dataSource.setUrl("jdbc:h2:mem:test_common");
to connect to test_common
database, but it did not work out.
连接到test_common数据库,但它没有工作。
I realized that in H2
database != Schema
, so I tried to put a default schema to test_common
as
我意识到在H2数据库中!= Schema,所以我试着将一个默认模式放到test_common中
dataSource.setUrl("jdbc:h2:mem:test_common;INIT=CREATE SCHEMA test_common\\; SET SCHEMA test_common");
but this didn't work out, I see logs as
但这没有用,我把日志视为
INFO 5/26/14 2:24 PM:liquibase: Dropping Database Objects in schema: TEST_COMMON.PUBLIC
INFO 5/26/14 2:24 PM:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Successfully released change log lock
INFO 5/26/14 2:24 PM:liquibase: Successfully acquired change log lock
INFO 5/26/14 2:24 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Table network created
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: ChangeSet liquibase/2014/1-1.xml::05192014.1525::h2 ran successfully in 5ms
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-1.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: New row inserted into network
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: ChangeSet liquibase/2014/1-2.xml::05192014.1525::h2 ran successfully in 5ms
INFO 5/26/14 2:24 PM:liquibase: liquibase/changelog.xml: liquibase/2014/1-2.xml::05192014.1525::h2: Reading from PUBLIC.DATABASECHANGELOG
How do I set default schema and database name in H2?
如何在H2中设置默认架构和数据库名称?
2 个解决方案
#1
4
Default schema is PUBLIC
For the record, the SQL Grammar
page of the H2 Database site for the SET SCHEMA
command says:
为了记录,SET SCHEMA命令的H2数据库站点的SQL语法页面说:
The default schema for new connections is
PUBLIC
.新连接的默认架构是PUBLIC。
That documentation also notes that you can specify the default schema when connecting:
该文档还指出您可以在连接时指定默认架构:
This setting can be appended to the database URL: jdbc:h2:test;SCHEMA=ABC
此设置可以附加到数据库URL:jdbc:h2:test; SCHEMA = ABC
Only one database
As for accessing various databases, H2 does not support the SQL Standard concepts of CLUSTER
or CATALOG
. You connect to one specific database (catalog) as part of your JDBC URL. Connections to that database are limited to that one single database. See the Question, Can you create multiple catalogs in H2? with an Answer by Thomas Mueller.
至于访问各种数据库,H2不支持CLUSTER或CATALOG的SQL标准概念。您作为JDBC URL的一部分连接到一个特定的数据库(目录)。与该数据库的连接仅限于该单个数据库。请参阅问题,您可以在H2中创建多个目录吗?以及Thomas Mueller的回答。
You could open another connection to another database but it would be entirely separate.
您可以打开另一个与另一个数据库的连接但它完全是分开的。
So talking about a “default database” has no meaning with H2 Database.
因此,谈论“默认数据库”与H2数据库没有任何意义。
#2
1
It looks like you are interacting with Liquibase through the Java APIs. There is a setDefaultSchemaName()
method on the Database object that you can use to set a different default schema.
看起来您正在通过Java API与Liquibase进行交互。 Database对象上有一个setDefaultSchemaName()方法,可用于设置不同的默认架构。
#1
4
Default schema is PUBLIC
For the record, the SQL Grammar
page of the H2 Database site for the SET SCHEMA
command says:
为了记录,SET SCHEMA命令的H2数据库站点的SQL语法页面说:
The default schema for new connections is
PUBLIC
.新连接的默认架构是PUBLIC。
That documentation also notes that you can specify the default schema when connecting:
该文档还指出您可以在连接时指定默认架构:
This setting can be appended to the database URL: jdbc:h2:test;SCHEMA=ABC
此设置可以附加到数据库URL:jdbc:h2:test; SCHEMA = ABC
Only one database
As for accessing various databases, H2 does not support the SQL Standard concepts of CLUSTER
or CATALOG
. You connect to one specific database (catalog) as part of your JDBC URL. Connections to that database are limited to that one single database. See the Question, Can you create multiple catalogs in H2? with an Answer by Thomas Mueller.
至于访问各种数据库,H2不支持CLUSTER或CATALOG的SQL标准概念。您作为JDBC URL的一部分连接到一个特定的数据库(目录)。与该数据库的连接仅限于该单个数据库。请参阅问题,您可以在H2中创建多个目录吗?以及Thomas Mueller的回答。
You could open another connection to another database but it would be entirely separate.
您可以打开另一个与另一个数据库的连接但它完全是分开的。
So talking about a “default database” has no meaning with H2 Database.
因此,谈论“默认数据库”与H2数据库没有任何意义。
#2
1
It looks like you are interacting with Liquibase through the Java APIs. There is a setDefaultSchemaName()
method on the Database object that you can use to set a different default schema.
看起来您正在通过Java API与Liquibase进行交互。 Database对象上有一个setDefaultSchemaName()方法,可用于设置不同的默认架构。