Package org.databene.mad4db.cmd

Examples of org.databene.mad4db.cmd.SchemaChange


  }
 
  // interface -------------------------------------------------------------------------------------------------------

  public SchemaChange compare(Database db1, Database db2) {
    SchemaChange change = new SchemaChange(config);
    compareTables(db1, db2, change);
    if (!config.isIgnoringSequences())
      compareSequences(db1, db2, change);
    compareTriggers(db1, db2, change);
    comparePackages(db1, db2, change);
View Full Code Here


public class TableCreationValuatorTest {

  @Test
  public void testNewMandatoryFkInOldTableReferencesNewTable() {
    // given a new table which will be referenced by a new mandatory FK in an old table
    SchemaChange schemaChange = createSchemaChange(false);
    // when performing check
    new TableCreationValuator().process(schemaChange);
    // then expect AUGMENTAION
    assertEquals(ChangeSeverity.AUGMENTATION, schemaChange.getSubChange(TableCreation.class, "referee").getSeverity());
    assertEquals(ChangeSeverity.AUGMENTATION, schemaChange.getSubChange(ForeignKeyConstraintCreation.class, "new_fk").getSeverity());
  }
View Full Code Here

  }

  @Test
  public void testNewOptionalFkInOldTableReferencesNewTable() {
    // given a new table which will be referenced by a new optional FK in an old table
    SchemaChange schemaChange = createSchemaChange(true);
    // when performing check
    new TableCreationValuator().process(schemaChange);
    // then expect EXTENSION
    assertEquals(ChangeSeverity.EXTENSION, schemaChange.getSubChange(TableCreation.class, "referee").getSeverity());
    assertEquals(ChangeSeverity.RESTRICTION, schemaChange.getSubChange(ForeignKeyConstraintCreation.class, "new_fk").getSeverity());
  }
View Full Code Here

  @Test
  public void testUnchanged() {
    // given two identical table versions
    DBTable table1 = createTableWithColumns("tbl", 3);
    DBTable table2 = createTableWithColumns("tbl", 3);
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be empty
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = schemaChange.getSubChanges();
    assertEquals(0, tableChanges.size());
  }
View Full Code Here

    assertEquals(ChangeSeverity.EXTENSION, schemaChange.getSubChange(TableCreation.class, "referee").getSeverity());
    assertEquals(ChangeSeverity.RESTRICTION, schemaChange.getSubChange(ForeignKeyConstraintCreation.class, "new_fk").getSeverity());
  }

  private SchemaChange createSchemaChange(boolean nullableFk) {
    SchemaChange schemaChange = new SchemaChange(new ComparisonConfig(null, null, null));
    DBTable refereeTable = new DBTable("referee");
    DBTable refererTable = new DBTable("referer");
    DBColumn fkColumn = new DBColumn("ref", refererTable, DBDataType.getInstance(Types.INTEGER, "int"));
    fkColumn.setNullable(nullableFk);
    refereeTable.addColumn(fkColumn);
    schemaChange.addSubChange(new TableCreation(refereeTable));
    DBForeignKeyConstraint fk = new DBForeignKeyConstraint("new_fk", true, refererTable, new String[] { "ref" }, refereeTable, new String[] { "id" });
    schemaChange.addSubChange(new ForeignKeyConstraintCreation(fk));
    return schemaChange;
  }
View Full Code Here

  @Test
  public void testColumnsAdded() {
    // given a table which got two additional columns
    DBTable table1 = createTableWithColumns("tbl", 2);
    DBTable table2 = createTableWithColumns("tbl", 4);
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be two ColumnCreations
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.EXTENSION, schemaChange);
View Full Code Here

  @Test
  public void testColumnsRemoved() {
    // given a table of which two columns were removed
    DBTable table1 = createTableWithColumns("tbl", 4);
    DBTable table2 = createTableWithColumns("tbl", 2);
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be two ColumnDeletions
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.DELETION, schemaChange);
View Full Code Here

  @Test
  public void testColumnOrderChanged() {
    // given a table in which the column order was reversed
    DBTable table1 = createTableWithColumns("tbl", 3);
    DBTable table2 = createTableWithColumns("tbl", "col3", "col2", "col1");
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be a ColumnOrderChange
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.REORGANIZATION, schemaChange);
View Full Code Here

  public void testColumnsRemovedAddedAndReordered() {
    // given a table in which the the first column (col1) is removed,
    // col2 and col3 swapped and a new column (col4) appended
    DBTable table1 = createTableWithColumns("tbl", "col1", "col2", "col3");
    DBTable table2 = createTableWithColumns("tbl", "col3", "col2", "col4");
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be a ColumnOrderChange
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.EXTENSION, schemaChange);
View Full Code Here

  public void testPKCreated() {
    // given a table to which a primary key was added
    DBTable table1 = createTableWithColumns("tbl", 2);
    DBTable table2 = createTableWithColumns("tbl", 2);
    new DBPrimaryKeyConstraint(table2, "pk1", false, "col1");
    SchemaChange schemaChange = new SchemaChange(config);
    // when comparing the tables
    new TableComparator(config).compareObjects(table1, table2, schemaChange);
    // then the result must be an primary key creation creation
    System.out.println(schemaChange);
    List<StructuralChange<?>> tableChanges = assertSingleSubChangeAndGetItsSubChanges(TableChange.class, DBTable.class, "tbl", ChangeSeverity.RESTRICTION, schemaChange);
View Full Code Here

TOP

Related Classes of org.databene.mad4db.cmd.SchemaChange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.