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());
}
}
}
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());
}
}
}
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());
}
}
}
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());
}
}
}
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!");
}
}
Aggregations