package com.fxy.base;

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

public class RealmMigrations implements RealmMigration {
    @Override
    public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
        final RealmSchema schema = realm.getSchema();
        if(oldVersion == 1) {
            if (schema.get("CutRuleRealm")==null){
                schema.create("CutRuleRealm")
                        .addField("id", int.class)
                        .addField("company_id", int.class)
                        .addField("number_start", String.class)
                        .addField("number_length", int.class)
                        .addField("cut_type", int.class)
                        .addField("start_index", int.class)
                        .addField("cut_length", int.class)
                        .addField("is_delete", String.class)
                        .addField("create_user", int.class)
                        .addField("create_date", String.class);
                oldVersion++;
            }

        }
        if (oldVersion < 2) {
            // 如果oldVersion小于1，这意味着数据库需要迁移
//            RealmObjectSchema objectSchema = schema.get("TakePhotosRealm");
//            if (objectSchema == null) {
//                // 对象不存在，创建它
//                objectSchema = schema.create("TakePhotosRealm");
//            }
//            // 添加新字段
//            objectSchema.addField("businessType", String.class);
//            oldVersion++;


        }
    }

}
