package com.github.openwebnet.database;

import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmSchema;

import static com.github.openwebnet.model.AutomationModel.FIELD_WHERE;
import static com.github.openwebnet.model.DomoticModel.FIELD_ENVIRONMENT_ID;
import static com.github.openwebnet.model.DomoticModel.FIELD_FAVOURITE;
import static com.github.openwebnet.model.DomoticModel.FIELD_GATEWAY_UUID;
import static com.github.openwebnet.model.DomoticModel.FIELD_NAME;
import static com.github.openwebnet.model.RealmModel.FIELD_UUID;

public class MigrationStrategy implements RealmMigration {

    @Override
    public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {

        // DynamicRealm exposes an editable schema
        RealmSchema schema = realm.getSchema();

        // Migrate to version 2: Add the AutomationModel class.
        if (oldVersion == 1) {
            schema.create("AutomationModel")
                    .addField(FIELD_UUID, String.class)
                    .addField(FIELD_ENVIRONMENT_ID, Integer.class)
                    .addField(FIELD_GATEWAY_UUID, String.class)
                    .addField(FIELD_NAME, String.class)
                    .addField(FIELD_WHERE, String.class)
                    .addField(FIELD_FAVOURITE, boolean.class)
                    ;
            ++oldVersion;
        }
    }
}

@@ -64,16 +64,48 @@
 cRealm;%0A
+import io.realm.FieldAttribute;%0A
 import i
@@ -989,36 +989,32 @@
                 
-    
 .addField(FIELD_
@@ -1023,38 +1023,62 @@
 ID, String.class
-)%0A    
+, FieldAttribute.PRIMARY_KEY)%0A
                 
@@ -1118,30 +1118,51 @@
 nteger.class
-)%0A    
+, FieldAttribute.REQUIRED)%0A
             
@@ -1199,38 +1199,59 @@
 ID, String.class
-)%0A    
+, FieldAttribute.REQUIRED)%0A
                 
@@ -1276,38 +1276,59 @@
 ME, String.class
-)%0A    
+, FieldAttribute.REQUIRED)%0A
                 
@@ -1358,30 +1358,51 @@
 String.class
-)%0A    
+, FieldAttribute.REQUIRED)%0A
             
@@ -1450,30 +1450,10 @@
 ass)
-%0A                    
 ;
+%0A
 %0A   

fix realm migration strategy v2