Search in sources :

Example 6 with CreateTableStatement

use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByDerbyDatabase.

@Test
public void testAutoIncrementStartWithIncrementByDerbyDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof DerbyDatabase) {
            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);
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0, INCREMENT BY 10))", generatedSql[0].toSql());
        }
    }
}
Also used : DerbyDatabase(liquibase.database.core.DerbyDatabase) 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 7 with CreateTableStatement

use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementMSSQLDatabase.

@Test
public void testAutoIncrementMSSQLDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof MSSQLDatabase) {
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new ColumnConstraint[] { new AutoIncrementConstraint(COLUMN_NAME1), new NotNullConstraint(COLUMN_NAME1) });
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("Error on " + database, "CREATE TABLE CATALOG_NAME.SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME " + "bigint IDENTITY (1, 1) NOT NULL)", generatedSql[0].toSql());
        }
    }
}
Also used : 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) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Sql(liquibase.sql.Sql) AbstractSqlGeneratorTest(liquibase.sqlgenerator.AbstractSqlGeneratorTest) Test(org.junit.Test)

Example 8 with CreateTableStatement

use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementSQLiteDatabase.

@Test
public void testAutoIncrementSQLiteDatabase() throws Exception {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof SQLiteDatabase) {
            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));
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGINT AUTOINCREMENT)", generatedSql[0].toSql());
        }
    }
}
Also used : SQLiteDatabase(liquibase.database.core.SQLiteDatabase) 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 9 with CreateTableStatement

use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.

the class CreateTableGeneratorTest method testAutoIncrementGenerationTypeDefaultOnNullOracleDatabase.

@Test
public void testAutoIncrementGenerationTypeDefaultOnNullOracleDatabase() {
    for (Database database : TestContext.getInstance().getAllDatabases()) {
        if (database instanceof OracleDatabase) {
            MockDatabaseConnection conn = new MockDatabaseConnection();
            database.setConnection(conn);
            CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
            AutoIncrementConstraint autoIncrementConstraint = new AutoIncrementConstraint(COLUMN_NAME1);
            autoIncrementConstraint.setGenerationType("BY DEFAULT");
            autoIncrementConstraint.setDefaultOnNull(true);
            statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("SMALLINT{autoIncrement:true}", database), autoIncrementConstraint);
            Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
            assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME NUMBER(5) GENERATED BY DEFAULT ON NULL AS IDENTITY)", generatedSql[0].toSql());
        }
    }
}
Also used : OracleDatabase(liquibase.database.core.OracleDatabase) 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 10 with CreateTableStatement

use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.

the class AbstractIntegrationTest method testInsertLongClob.

@Test
public void testInsertLongClob() {
    assumeNotNull(this.getDatabase());
    DatabaseChangeLog longClobChangelog = new DatabaseChangeLog();
    ChangeSet longClobInsert = new ChangeSet(longClobChangelog);
    ColumnConfig clobColumn = new ColumnConfig();
    clobColumn.setName("clobColumn");
    clobColumn.setType(LoadDataChange.LOAD_DATA_TYPE.CLOB.name());
    // Oracle database only allows string values of up to 4000 characters
    // so we test that the CLOB insertion is actually done as a CLOB in the JDBC statement
    StringBuilder longClobString = new StringBuilder(4001);
    for (int i = 0; i < 4001; i++) {
        longClobString.append('a');
    }
    clobColumn.setValue(longClobString.toString());
    CreateTableStatement clobTableCreator = new CreateTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), "tableWithClob");
    clobTableCreator.addColumn("clobColumn", new ClobType());
    InsertExecutablePreparedStatement insertStatement = new InsertExecutablePreparedStatement(database, database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), "tableWithClob", Arrays.asList(clobColumn), longClobInsert, Scope.getCurrentScope().getResourceAccessor());
    try {
        database.execute(new SqlStatement[] { clobTableCreator, insertStatement }, new ArrayList<>());
    } catch (LiquibaseException ex) {
        ex.printStackTrace();
        fail("Long clob insertion failed!");
    }
}
Also used : ClobType(liquibase.datatype.core.ClobType) ColumnConfig(liquibase.change.ColumnConfig) CreateTableStatement(liquibase.statement.core.CreateTableStatement) LiquibaseException(liquibase.exception.LiquibaseException) ChangeSet(liquibase.changelog.ChangeSet) InsertExecutablePreparedStatement(liquibase.statement.InsertExecutablePreparedStatement) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) Test(org.junit.Test)

Aggregations

CreateTableStatement (liquibase.statement.core.CreateTableStatement)54 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)45 OracleDatabase (liquibase.database.core.OracleDatabase)45 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)45 Test (org.junit.Test)45 Database (liquibase.database.Database)44 AbstractDb2Database (liquibase.database.core.AbstractDb2Database)44 DerbyDatabase (liquibase.database.core.DerbyDatabase)44 H2Database (liquibase.database.core.H2Database)44 HsqlDatabase (liquibase.database.core.HsqlDatabase)44 MySQLDatabase (liquibase.database.core.MySQLDatabase)44 PostgresDatabase (liquibase.database.core.PostgresDatabase)44 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)44 SybaseDatabase (liquibase.database.core.SybaseDatabase)44 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)44 Sql (liquibase.sql.Sql)41 MockDatabaseConnection (liquibase.database.MockDatabaseConnection)10 ArrayList (java.util.ArrayList)6 NotNullConstraint (liquibase.statement.NotNullConstraint)6 ColumnConfig (liquibase.change.ColumnConfig)3