Exemple #1
0
  @Test
  public void test_compare_addAndDropColumn() throws Exception {

    MTable base = base();
    MTable newTable = newTable();

    ModelDiff diff = new ModelDiff();
    base.compare(diff, newTable);

    assertThat(diff.getApplyChanges()).hasSize(1);
    assertThat(diff.getDropChanges()).hasSize(1);
  }
  /** Convert the model into a ChangeSet. */
  private ChangeSet asChangeSet() {

    // empty diff so changes will effectively all be create
    ModelDiff diff = new ModelDiff();
    diff.compareTo(model);

    List<Object> createChanges = diff.getCreateChanges();

    // put the changes into a ChangeSet
    ChangeSet createChangeSet = new ChangeSet();
    createChangeSet.getChangeSetChildren().addAll(createChanges);
    return createChangeSet;
  }
Exemple #3
0
  @Test
  public void test_compare_addHistoryToTable() {

    MTable base = base();
    MTable withHistory = base();
    withHistory.setWithHistory(true);

    ModelDiff diff = new ModelDiff();
    base.compare(diff, withHistory);

    assertThat(diff.getDropChanges()).isEmpty();
    assertThat(diff.getApplyChanges()).hasSize(1);
    assertThat(diff.getApplyChanges().get(0)).isInstanceOf(AddHistoryTable.class);
  }
Exemple #4
0
  @Test
  public void test_compare_addTwoColumnsToSameTable() throws Exception {

    ModelDiff diff = new ModelDiff();
    diff.compareTables(base(), newTableAdd2Columns());

    List<Object> createChanges = diff.getApplyChanges();
    assertThat(createChanges).hasSize(1);

    AddColumn addColumn = (AddColumn) createChanges.get(0);
    assertThat(addColumn.getColumn()).extracting("name").contains("comment", "note");
    assertThat(addColumn.getColumn()).extracting("type").contains("varchar(1000)", "varchar(2000)");

    assertThat(diff.getDropChanges()).hasSize(0);
  }
Exemple #5
0
  @Test
  public void test_compare_removeHistoryFromTable() throws Exception {

    MTable withHistory = base();
    withHistory.setWithHistory(true);

    MTable noHistory = base();

    ModelDiff diff = new ModelDiff();
    withHistory.compare(diff, noHistory);

    assertThat(diff.getApplyChanges()).isEmpty();
    assertThat(diff.getDropChanges()).hasSize(1);
    assertThat(diff.getDropChanges().get(0)).isInstanceOf(DropHistoryTable.class);
  }
Exemple #6
0
  @Test
  public void test_compare_addColumnDropColumn() throws Exception {

    ModelDiff diff = new ModelDiff();
    diff.compareTables(base(), newTable());

    List<Object> createChanges = diff.getApplyChanges();
    assertThat(createChanges).hasSize(1);
    AddColumn addColumn = (AddColumn) createChanges.get(0);
    assertThat(addColumn.getColumn()).extracting("name").contains("comment");
    assertThat(addColumn.getColumn()).extracting("type").contains("varchar(1000)");

    List<Object> dropChanges = diff.getDropChanges();
    assertThat(dropChanges).hasSize(1);

    DropColumn dropColumn = (DropColumn) dropChanges.get(0);
    assertThat(dropColumn.getColumnName()).isEqualTo("status");
    assertThat(dropColumn.getTableName()).isEqualTo("tab");
  }
Exemple #7
0
  @Test
  public void test_compare_modifyColumn() throws Exception {

    ModelDiff diff = new ModelDiff();
    diff.compareTables(base(), newTableModifiedColumn());

    List<Object> createChanges = diff.getApplyChanges();
    assertThat(createChanges).hasSize(1);

    AlterColumn alterColumn = (AlterColumn) createChanges.get(0);
    assertThat(alterColumn.getColumnName()).isEqualTo("name");
    assertThat(alterColumn.getType()).isEqualTo("varchar(30)");
    assertThat(alterColumn.isNotnull()).isEqualTo(true);
    assertThat(alterColumn.getUnique()).isNull();
    assertThat(alterColumn.getCheckConstraint()).isNull();
    assertThat(alterColumn.getReferences()).isNull();

    assertThat(diff.getDropChanges()).hasSize(0);
  }