1
0
mirror of https://github.com/etesync/android synced 2025-01-11 00:01:12 +00:00

Journal model: fix broken database migration

Add missing readOnly column
Make the new_Entry foreign key refer to new_Journal and not the old one.
This commit is contained in:
Tom Hacohen 2017-04-24 15:17:38 +01:00
parent fab8aa90ac
commit 96443a0b57

View File

@ -247,10 +247,10 @@ public class App extends Application {
if (oldVersion < 3) {
db.execSQL("PRAGMA foreign_keys=OFF;");
db.execSQL("CREATE TABLE new_Journal (id integer primary key autoincrement not null, deleted boolean not null, encryptedKey varbinary(255), info varchar(255), owner varchar(255), service integer, serviceModel integer, uid varchar(64) not null, foreign key (serviceModel) references Service (id) on delete cascade);");
db.execSQL("CREATE TABLE new_Entry (id integer primary key autoincrement not null, content varchar(255), journal integer, uid varchar(64) not null, foreign key (journal) references Journal (id) on delete cascade);");
db.execSQL("CREATE TABLE new_Journal (id integer primary key autoincrement not null, deleted boolean not null, encryptedKey varbinary(255), info varchar(255), owner varchar(255), service integer, serviceModel integer, uid varchar(64) not null, readOnly boolean default false, foreign key (serviceModel) references Service (id) on delete cascade);");
db.execSQL("CREATE TABLE new_Entry (id integer primary key autoincrement not null, content varchar(255), journal integer, uid varchar(64) not null, foreign key (journal) references new_Journal (id) on delete cascade);");
db.execSQL("INSERT INTO new_Journal SELECT id, deleted, encryptedKey, info, owner, service, serviceModel, uid from Journal;");
db.execSQL("INSERT INTO new_Journal SELECT id, deleted, encryptedKey, info, owner, service, serviceModel, uid, 0 from Journal;");
db.execSQL("INSERT INTO new_Entry SELECT id, content, journal, uid from Entry;");
db.execSQL("DROP TABLE Journal;");