use of liquibase.database.core.PostgresDatabase in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByPostgresDatabase.
@Test
public void testAutoIncrementStartWithIncrementByPostgresDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
MockDatabaseConnection conn = new MockDatabaseConnection();
conn.setDatabaseMajorVersion(9);
database.setConnection(conn);
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, BigInteger.TEN));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
// start with and increment by supported over generated sequence
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGSERIAL)", generatedSql[0].toSql());
conn.setDatabaseMajorVersion(10);
generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0, INCREMENT BY 10))", generatedSql[0].toSql());
}
}
}
use of liquibase.database.core.PostgresDatabase in project liquibase by liquibase.
the class CreateTableGeneratorTest method createReferencesSchemaEscaped.
@Test
public void createReferencesSchemaEscaped() throws Exception {
Database database = new PostgresDatabase();
database.setOutputDefaultSchema(true);
database.setDefaultSchemaName("my-schema");
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumnConstraint(new ForeignKeyConstraint("fk_test_parent", TABLE_NAME + "(id)").setColumn("id"));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (, CONSTRAINT fk_test_parent FOREIGN KEY (id) REFERENCES \"my-schema\".TABLE_NAME(id))", generatedSql[0].toSql());
}
use of liquibase.database.core.PostgresDatabase in project collect by openforis.
the class LiquibaseRelationalSchemaCreator method getDatabaseImplementation.
private Database getDatabaseImplementation(Connection targetConn) throws DatabaseException {
DatabaseConnection dbconn = new JdbcConnection(targetConn);
DatabaseFactory dbFactory = DatabaseFactory.getInstance();
Database rdb = dbFactory.findCorrectDatabaseImplementation(dbconn);
if (rdb instanceof PostgresDatabase) {
rdb = new CollectPostgresDatabase(dbconn);
}
return rdb;
}
Aggregations