Search in sources :

Example 6 with NotNullConstraint

use of liquibase.statement.NotNullConstraint 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);
    if (database.supportsSchemas()) {
        table = new CreateTableStatement(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA, TABLE_NAME);
        table.addColumn("id", DataTypeFactory.getInstance().fromDescription("int", database), null, new ColumnConstraint[] { new NotNullConstraint() });
        statements.add(table);
    }
    return statements;
}
Also used : CreateTableStatement(liquibase.statement.core.CreateTableStatement) ArrayList(java.util.ArrayList) NotNullConstraint(liquibase.statement.NotNullConstraint)

Example 7 with NotNullConstraint

use of liquibase.statement.NotNullConstraint in project liquibase by liquibase.

the class CreateDatabaseChangeLogLockTableGenerator method generateSql.

@Override
public Sql[] generateSql(CreateDatabaseChangeLogLockTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    String charTypeName = getCharTypeName(database);
    String dateTimeTypeString = getDateTimeTypeString(database);
    CreateTableStatement createTableStatement = new CreateTableStatement(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), database.getDatabaseChangeLogLockTableName()).setTablespace(database.getLiquibaseTablespaceName()).addPrimaryKeyColumn("ID", DataTypeFactory.getInstance().fromDescription("int", database), null, null, null, new NotNullConstraint()).addColumn("LOCKED", DataTypeFactory.getInstance().fromDescription("boolean", database), null, null, new NotNullConstraint()).addColumn("LOCKGRANTED", DataTypeFactory.getInstance().fromDescription(dateTimeTypeString, database)).addColumn("LOCKEDBY", DataTypeFactory.getInstance().fromDescription(charTypeName + "(255)", database));
    return SqlGeneratorFactory.getInstance().generateSql(createTableStatement, database);
}
Also used : CreateTableStatement(liquibase.statement.core.CreateTableStatement) NotNullConstraint(liquibase.statement.NotNullConstraint)

Example 8 with NotNullConstraint

use of liquibase.statement.NotNullConstraint in project liquibase by liquibase.

the class AddUniqueConstraintExecutorTest method setupStatements.

@Override
protected List<? extends SqlStatement> setupStatements(Database database) {
    List<CreateTableStatement> statements = new ArrayList<CreateTableStatement>();
    CreateTableStatement table = new CreateTableStatement(null, null, TABLE_NAME);
    table.addColumn("id", DataTypeFactory.getInstance().fromDescription("int", database), null, new ColumnConstraint[] { new NotNullConstraint() }).addColumn(COLUMN_NAME, DataTypeFactory.getInstance().fromDescription("int", database), null, new ColumnConstraint[] { new NotNullConstraint() });
    statements.add(table);
    if (database.supportsSchemas()) {
        table = new CreateTableStatement(DatabaseTestContext.ALT_CATALOG, DatabaseTestContext.ALT_SCHEMA, TABLE_NAME);
        table.addColumn("id", DataTypeFactory.getInstance().fromDescription("int", database), null, new ColumnConstraint[] { new NotNullConstraint() }).addColumn(COLUMN_NAME, DataTypeFactory.getInstance().fromDescription("int", database), null, new ColumnConstraint[] { new NotNullConstraint() });
        statements.add(table);
    }
    return statements;
}
Also used : CreateTableStatement(liquibase.statement.core.CreateTableStatement) ColumnConstraint(liquibase.statement.ColumnConstraint) ArrayList(java.util.ArrayList) NotNullConstraint(liquibase.statement.NotNullConstraint)

Aggregations

NotNullConstraint (liquibase.statement.NotNullConstraint)8 CreateTableStatement (liquibase.statement.core.CreateTableStatement)7 MySQLDatabase (liquibase.database.core.MySQLDatabase)4 Sql (liquibase.sql.Sql)4 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)4 Test (org.junit.Test)4 Database (liquibase.database.Database)3 DB2Database (liquibase.database.core.DB2Database)3 DerbyDatabase (liquibase.database.core.DerbyDatabase)3 H2Database (liquibase.database.core.H2Database)3 HsqlDatabase (liquibase.database.core.HsqlDatabase)3 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)3 OracleDatabase (liquibase.database.core.OracleDatabase)3 PostgresDatabase (liquibase.database.core.PostgresDatabase)3 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)3 SybaseASADatabase (liquibase.database.core.SybaseASADatabase)3 SybaseDatabase (liquibase.database.core.SybaseDatabase)3 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)3 ArrayList (java.util.ArrayList)2 MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)1