Search in sources :

Example 1 with EmptyModel

use of com.orm.androrm.impl.migration.EmptyModel in project androrm by androrm.

the class RenameModelMigrationTest method testRenameRelation.

public void testRenameRelation() {
    Migrator<NewModelWithRelation> migrator = new Migrator<NewModelWithRelation>(NewModelWithRelation.class);
    assertTrue(mHelper.hasRelationTable(ModelWithRelation.class));
    assertTrue(mHelper.tableExists("emptymodel_modelwithrelation"));
    ModelWithRelation model1 = new ModelWithRelation();
    model1.save(getContext());
    EmptyModel empty = new EmptyModel();
    empty.save(getContext());
    model1.addRelation(empty);
    model1.save(getContext());
    assertEquals(1, model1.getRelations(getContext()).count());
    assertEquals(0, NewModelWithRelation.objects(getContext()).count());
    migrator.renameModel("ModelWithRelation", NewModelWithRelation.class);
    migrator.migrate(getContext());
    NewModelWithRelation one = NewModelWithRelation.objects(getContext()).get(1);
    assertEquals(1, one.getRelations(getContext()).count());
    assertTrue(mHelper.hasRelationTable(NewModelWithRelation.class));
    assertFalse(mHelper.hasRelationTable(ModelWithRelation.class));
    assertFalse(mHelper.tableExists("emptymodel_modelwithrelation"));
    Filter filter = new Filter();
    filter.is("mModel", "newmodelwithrelation").is("mAction", "rename_relation").is("mValue", "emptymodel_modelwithrelation");
    assertEquals(1, Migration.objects(getContext()).filter(filter).count());
}
Also used : NewModelWithRelation(com.orm.androrm.impl.migration.NewModelWithRelation) Filter(com.orm.androrm.Filter) NewModelWithRelation(com.orm.androrm.impl.migration.NewModelWithRelation) ModelWithRelation(com.orm.androrm.impl.migration.ModelWithRelation) EmptyModel(com.orm.androrm.impl.migration.EmptyModel) NewEmptyModel(com.orm.androrm.impl.migration.NewEmptyModel) Migrator(com.orm.androrm.migration.Migrator)

Example 2 with EmptyModel

use of com.orm.androrm.impl.migration.EmptyModel in project androrm by androrm.

the class DataFieldMigrationTest method testLocationFieldAdd.

public void testLocationFieldAdd() {
    Migrator<EmptyModel> migrator = new Migrator<EmptyModel>(EmptyModel.class);
    assertFalse(mHelper.hasField(EmptyModel.class, "mLocationLat"));
    assertFalse(mHelper.hasField(EmptyModel.class, "mLocationLng"));
    migrator.addField("mLocation", new LocationField());
    migrator.migrate(getContext());
    assertTrue(mHelper.hasField(EmptyModel.class, "mLocationLat"));
    assertTrue(mHelper.hasField(EmptyModel.class, "mLocationLng"));
}
Also used : LocationField(com.orm.androrm.field.LocationField) EmptyModel(com.orm.androrm.impl.migration.EmptyModel) Migrator(com.orm.androrm.migration.Migrator)

Example 3 with EmptyModel

use of com.orm.androrm.impl.migration.EmptyModel in project androrm by androrm.

the class RenameModelMigrationTest method testRenameTable.

public void testRenameTable() {
    Migrator<NewEmptyModel> migrator = new Migrator<NewEmptyModel>(NewEmptyModel.class);
    assertTrue(mHelper.tableExists(EmptyModel.class));
    EmptyModel model1 = new EmptyModel();
    model1.save(getContext());
    assertEquals(1, EmptyModel.objects(getContext()).count());
    assertEquals(0, NewEmptyModel.objects(getContext()).count());
    migrator.renameModel("EmptyModel", NewEmptyModel.class);
    migrator.migrate(getContext());
    assertFalse(mHelper.tableExists(EmptyModel.class));
    assertEquals(1, NewEmptyModel.objects(getContext()).count());
    Filter filter = new Filter();
    filter.is("mModel", "newemptymodel").is("mAction", "rename_table").is("mValue", "newemptymodel");
    assertEquals(1, Migration.objects(getContext()).filter(filter).count());
}
Also used : Filter(com.orm.androrm.Filter) EmptyModel(com.orm.androrm.impl.migration.EmptyModel) NewEmptyModel(com.orm.androrm.impl.migration.NewEmptyModel) Migrator(com.orm.androrm.migration.Migrator) NewEmptyModel(com.orm.androrm.impl.migration.NewEmptyModel)

Aggregations

EmptyModel (com.orm.androrm.impl.migration.EmptyModel)3 Migrator (com.orm.androrm.migration.Migrator)3 Filter (com.orm.androrm.Filter)2 NewEmptyModel (com.orm.androrm.impl.migration.NewEmptyModel)2 LocationField (com.orm.androrm.field.LocationField)1 ModelWithRelation (com.orm.androrm.impl.migration.ModelWithRelation)1 NewModelWithRelation (com.orm.androrm.impl.migration.NewModelWithRelation)1