use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.
the class RenameColumnExecuteTest method setupStatements.
@Override
protected List<? extends SqlStatement> setupStatements(Database database) {
ArrayList<CreateTableStatement> statements = new ArrayList<CreateTableStatement>();
CreateTableStatement table = new CreateTableStatement(null, null, TABLE_NAME);
if (database instanceof MySQLDatabase) {
table.addPrimaryKeyColumn("id", DataTypeFactory.getInstance().fromDescription("int", database), null, "pk_", null);
} else {
table.addColumn("id", DataTypeFactory.getInstance().fromDescription("int", database), null, new ColumnConstraint[] { new NotNullConstraint() });
}
table.addColumn(COLUMN_NAME, DataTypeFactory.getInstance().fromDescription("int", database));
statements.add(table);
// }
return statements;
}
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!");
}
}
use of liquibase.statement.core.CreateTableStatement in project liquibase by liquibase.
the class CreateDatabaseChangeLogTableGenerator method generateSql.
@Override
public Sql[] generateSql(CreateDatabaseChangeLogTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
String charTypeName = getCharTypeName(database);
String dateTimeTypeString = getDateTimeTypeString(database);
CreateTableStatement createTableStatement = new CreateTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogTableName()).setTablespace(database.getLiquibaseTablespaceName()).addColumn("ID", DataTypeFactory.getInstance().fromDescription(charTypeName + "(" + getIdColumnSize() + ")", database), null, null, new NotNullConstraint()).addColumn("AUTHOR", DataTypeFactory.getInstance().fromDescription(charTypeName + "(" + getAuthorColumnSize() + ")", database), null, null, new NotNullConstraint()).addColumn("FILENAME", DataTypeFactory.getInstance().fromDescription(charTypeName + "(" + getFilenameColumnSize() + ")", database), null, null, new NotNullConstraint()).addColumn("DATEEXECUTED", DataTypeFactory.getInstance().fromDescription(dateTimeTypeString, database), null, null, new NotNullConstraint()).addColumn("ORDEREXECUTED", DataTypeFactory.getInstance().fromDescription("int", database), null, null, new NotNullConstraint()).addColumn("EXECTYPE", DataTypeFactory.getInstance().fromDescription(charTypeName + "(10)", database), null, null, new NotNullConstraint()).addColumn("MD5SUM", DataTypeFactory.getInstance().fromDescription(charTypeName + "(35)", database)).addColumn("DESCRIPTION", DataTypeFactory.getInstance().fromDescription(charTypeName + "(255)", database)).addColumn("COMMENTS", DataTypeFactory.getInstance().fromDescription(charTypeName + "(255)", database)).addColumn("TAG", DataTypeFactory.getInstance().fromDescription(charTypeName + "(255)", database)).addColumn("LIQUIBASE", DataTypeFactory.getInstance().fromDescription(charTypeName + "(20)", database)).addColumn("CONTEXTS", DataTypeFactory.getInstance().fromDescription(charTypeName + "(" + getContextsSize() + ")", database)).addColumn("LABELS", DataTypeFactory.getInstance().fromDescription(charTypeName + "(" + getLabelsSize() + ")", database)).addColumn("DEPLOYMENT_ID", DataTypeFactory.getInstance().fromDescription(charTypeName + "(10)", database));
// use LEGACY quoting since we're dealing with system objects
ObjectQuotingStrategy currentStrategy = database.getObjectQuotingStrategy();
database.setObjectQuotingStrategy(ObjectQuotingStrategy.LEGACY);
try {
return SqlGeneratorFactory.getInstance().generateSql(createTableStatement, database);
} finally {
database.setObjectQuotingStrategy(currentStrategy);
}
}
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());
}
}
}
Aggregations