Search in sources :

Example 6 with AddColumnStatement

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

the class AddColumnExecutorTest method generateSql_primaryKey.

@SuppressWarnings("unchecked")
@Test
public void generateSql_primaryKey() throws Exception {
    this.statementUnderTest = new AddColumnStatement(null, "table_name", "column_name", "int", null, new PrimaryKeyConstraint());
    assertCorrect("alter table [table_name] add [column_name] int not null primary key", HsqlDatabase.class);
    assertCorrect("alter table [table_name] add [column_name] int primary key not null", SybaseASADatabase.class, SybaseDatabase.class);
    assertCorrect("alter table [dbo].[table_name] add [column_name] int not null primary key", MSSQLDatabase.class);
    assertCorrect("alter table table_name add column_name int not null primary key", PostgresDatabase.class);
    assertCorrect("alter table `table_name` add `column_name` int not null primary key", MySQLDatabase.class);
    assertCorrect("ALTER TABLE [table_name] ADD [column_name] int PRIMARY KEY NOT NULL");
}
Also used : AddColumnStatement(liquibase.statement.core.AddColumnStatement) Test(org.junit.Test)

Example 7 with AddColumnStatement

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

the class AddColumnExecutorTest method notNull.

@SuppressWarnings("unchecked")
@Test
public void notNull() throws Exception {
    this.statementUnderTest = new AddColumnStatement(null, null, TABLE_NAME, "column_name", "int", 42, new NotNullConstraint());
    assertCorrect("ALTER TABLE [table_name] ADD [column_name] int DEFAULT 42 NOT NULL", SybaseASADatabase.class, SybaseDatabase.class);
    assertCorrect("alter table table_name add column_name int default 42 not null", InformixDatabase.class);
    assertCorrect("alter table [table_name] add [column_name] int not null constraint df_table_name_column_name default 42", MSSQLDatabase.class);
    assertCorrect("alter table table_name add column_name int default 42 not null", OracleDatabase.class, DerbyDatabase.class, HsqlDatabase.class, DB2Database.class, H2Database.class, FirebirdDatabase.class);
    assertCorrect("not supported. fixme!!", SQLiteDatabase.class);
    assertCorrectOnRest("ALTER TABLE [table_name] ADD [column_name] int NOT NULL DEFAULT 42");
}
Also used : AddColumnStatement(liquibase.statement.core.AddColumnStatement) Test(org.junit.Test)

Example 8 with AddColumnStatement

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

the class AddColumnExecutorTest method generateSql_notNull.

@SuppressWarnings("unchecked")
@Test
public void generateSql_notNull() throws Exception {
    this.statementUnderTest = new AddColumnStatement(null, null, "table_name", "column_name", "int", 42, new NotNullConstraint());
    assertCorrect("alter table [table_name] add [column_name] int default 42 not null", SybaseASADatabase.class, SybaseDatabase.class);
    assertCorrect("alter table table_name add column_name int not null default 42", PostgresDatabase.class);
    assertCorrect("alter table [table_name] add [column_name] int not null constraint df_table_name_column_name default 42", MSSQLDatabase.class);
    assertCorrect("alter table table_name add column_name int not null default 42", MySQLDatabase.class);
    assertCorrect("not supported. fixme!!", SQLiteDatabase.class);
    assertCorrect("ALTER TABLE [table_name] ADD [column_name] int DEFAULT 42 NOT NULL");
}
Also used : AddColumnStatement(liquibase.statement.core.AddColumnStatement) Test(org.junit.Test)

Example 9 with AddColumnStatement

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

the class AddColumnExecutorTest method autoIncrement.

@SuppressWarnings("unchecked")
@Test
public void autoIncrement() throws Exception {
    this.statementUnderTest = new AddColumnStatement(null, TABLE_NAME, "column_name", "int", null, new AutoIncrementConstraint());
    assertCorrect("ALTER TABLE [dbo].[table_name] ADD [column_name] int auto_increment_clause", MSSQLDatabase.class);
    assertCorrect("alter table [table_name] add [column_name] int default autoincrement null", SybaseASADatabase.class);
    assertCorrect("alter table [table_name] add [column_name] int identity null", SybaseDatabase.class);
    assertCorrect("alter table [table_name] add [column_name] serial", PostgresDatabase.class, InformixDatabase.class);
    assertCorrect("not supported. fixme!!", SQLiteDatabase.class);
    assertCorrectOnRest("ALTER TABLE [table_name] ADD [column_name] int auto_increment_clause");
}
Also used : AddColumnStatement(liquibase.statement.core.AddColumnStatement) Test(org.junit.Test)

Example 10 with AddColumnStatement

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

the class AddColumnGeneratorDefaultClauseBeforeNotNullTest method validate_noAutoIncrementWithDerby.

@Test
public void validate_noAutoIncrementWithDerby() {
    ValidationErrors validationErrors = generatorUnderTest.validate(new AddColumnStatement(null, null, "table_name", "column_name", "int", null, new AutoIncrementConstraint("column_name")), new DerbyDatabase(), new MockSqlGeneratorChain());
    assertTrue(validationErrors.getErrorMessages().contains("Cannot add an identity column to derby"));
}
Also used : AutoIncrementConstraint(liquibase.statement.AutoIncrementConstraint) ValidationErrors(liquibase.exception.ValidationErrors) AddColumnStatement(liquibase.statement.core.AddColumnStatement) MockSqlGeneratorChain(liquibase.sqlgenerator.MockSqlGeneratorChain) Test(org.junit.Test)

Aggregations

AddColumnStatement (liquibase.statement.core.AddColumnStatement)17 Test (org.junit.Test)13 MockSqlGeneratorChain (liquibase.sqlgenerator.MockSqlGeneratorChain)4 AddColumnChange (liquibase.change.core.AddColumnChange)3 MySQLDatabase (liquibase.database.core.MySQLDatabase)3 AutoIncrementConstraint (liquibase.statement.AutoIncrementConstraint)3 SqlStatement (liquibase.statement.SqlStatement)3 ArrayList (java.util.ArrayList)2 DB2Database (liquibase.database.core.DB2Database)2 ValidationErrors (liquibase.exception.ValidationErrors)2 Sql (liquibase.sql.Sql)2 AbstractSqlGeneratorTest (liquibase.sqlgenerator.AbstractSqlGeneratorTest)2 ReorganizeTableStatement (liquibase.statement.core.ReorganizeTableStatement)2 HashSet (java.util.HashSet)1 AddColumnConfig (liquibase.change.AddColumnConfig)1 DerbyDatabase (liquibase.database.core.DerbyDatabase)1 H2Database (liquibase.database.core.H2Database)1 OracleDatabase (liquibase.database.core.OracleDatabase)1 SQLiteDatabase (liquibase.database.core.SQLiteDatabase)1 DatabaseException (liquibase.exception.DatabaseException)1