Skip to content

Commit

Permalink
Fix v2 to v3 Database migration (#3334)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro committed May 5, 2020
1 parent 46ff588 commit 37a3f8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
13 changes: 2 additions & 11 deletions app/src/common/shared/org/mozilla/vrbrowser/db/AppDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static AppDatabase getAppDatabase(Context context, final AppExecutors exe
@NonNull
private static AppDatabase buildDatabase(final @NonNull Context appContext, final @NonNull AppExecutors executors) {
return Room.databaseBuilder(appContext, AppDatabase.class, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_1_2, MIGRATION_2_3)
.addCallback(new Callback() {
@Override
public void onCreate(@NonNull SupportSQLiteDatabase db) {
Expand Down Expand Up @@ -87,19 +87,10 @@ public void migrate(SupportSQLiteDatabase database) {
}
};

private static final Migration MIGRATION_1_3 = new Migration(1, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE PopUpSite RENAME TO SitePermission");
database.execSQL("ALTER TABLE SitePermission ADD COLUMN category INTEGER NOT NULL DEFAULT 0");
database.execSQL("ALTER TABLE SitePermission ADD COLUMN principal STRING NOT NULL DEFAULT ''");
}
};

private static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE SitePermission ADD COLUMN principal STRING NOT NULL DEFAULT ''");
database.execSQL("ALTER TABLE SitePermission ADD COLUMN principal TEXT NOT NULL DEFAULT ''");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public SitePermission(@NonNull String url, @NonNull String principal, @Category
this.url = url;
this.principal = principal;
this.category = category;
this.allowed = false;
}

@PrimaryKey(autoGenerate = true)
Expand All @@ -29,9 +30,12 @@ public SitePermission(@NonNull String url, @NonNull String principal, @Category
public String url;

@NonNull
@ColumnInfo(name = "principal")
@ColumnInfo(name = "principal", defaultValue = "")
public String principal;

@ColumnInfo(name = "allowed")
public boolean allowed;

@ColumnInfo(name = "category")
public @Category int category;
}
Expand Down

0 comments on commit 37a3f8b

Please sign in to comment.