Search in sources :

Example 31 with PostgresDatabase

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());
        }
    }
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) MockDatabaseConnection(liquibase.database.MockDatabaseConnection) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 32 with PostgresDatabase

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());
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) CreateTableStatement(liquibase.statement.core.CreateTableStatement) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DerbyDatabase(liquibase.database.core.DerbyDatabase) H2Database(liquibase.database.core.H2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) MySQLDatabase(liquibase.database.core.MySQLDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) OracleDatabase(liquibase.database.core.OracleDatabase) SybaseDatabase(liquibase.database.core.SybaseDatabase) SybaseASADatabase(liquibase.database.core.SybaseASADatabase) Database(liquibase.database.Database) AbstractDb2Database(liquibase.database.core.AbstractDb2Database) HsqlDatabase(liquibase.database.core.HsqlDatabase) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 33 with PostgresDatabase

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;
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) DatabaseFactory(liquibase.database.DatabaseFactory) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) PostgresDatabase(liquibase.database.core.PostgresDatabase) Database(liquibase.database.Database) DatabaseConnection(liquibase.database.DatabaseConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection)

Aggregations

PostgresDatabase (liquibase.database.core.PostgresDatabase)33 Test (org.junit.Test)19 Sql (liquibase.sql.Sql)16 Database (liquibase.database.Database)11 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)11 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)11 MySQLDatabase (liquibase.database.core.MySQLDatabase)10 OracleDatabase (liquibase.database.core.OracleDatabase)10 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)9 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)8 H2Database (liquibase.database.core.H2Database)7 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)7 SybaseDatabase (liquibase.database.core.SybaseDatabase)7 BigInteger (java.math.BigInteger)6 ColumnConfig (liquibase.change.ColumnConfig)6 DerbyDatabase (liquibase.database.core.DerbyDatabase)6 HsqlDatabase (liquibase.database.core.HsqlDatabase)6 CreateTableStatement (liquibase.statement.core.CreateTableStatement)6 MockDatabaseConnection (liquibase.database.MockDatabaseConnection)5 ArrayList (java.util.ArrayList)4