Skip to content

Commit

Permalink
Fix for bad database migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie0 committed Feb 25, 2014
1 parent 23c6074 commit 43c1576
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/org/thoughtcrime/securesms/database/DatabaseFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class DatabaseFactory {
private static final int INTRODUCED_TOFU_IDENTITY_VERSION = 9;
private static final int INTRODUCED_PUSH_DATABASE_VERSION = 10;
private static final int INTRODUCED_GROUP_DATABASE_VERSION = 11;
private static final int DATABASE_VERSION = 11;
private static final int INTRODUCED_PUSH_FIX_VERSION = 12;
private static final int DATABASE_VERSION = 12;

private static final String DATABASE_NAME = "messages.db";
private static final Object lock = new Object();
Expand Down Expand Up @@ -649,6 +650,15 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("ALTER TABLE mms ADD COLUMN address_device_id INTEGER DEFAULT 1;");
}

if (oldVersion < INTRODUCED_PUSH_FIX_VERSION) {
db.execSQL("CREATE TEMPORARY table push_backup (_id INTEGER PRIMARY KEY, type INTEGER, source, TEXT, destinations TEXT, body TEXT, timestamp INTEGER, device_id INTEGER DEFAULT 1);");
db.execSQL("INSERT INTO push_backup(_id, type, source, body, timestamp, device_id) SELECT _id, type, source, body, timestamp, device_id FROM push;");
db.execSQL("DROP TABLE push");
db.execSQL("CREATE TABLE push (_id INTEGER PRIMARY KEY, type INTEGER, source TEXT, body TEXT, timestamp INTEGER, device_id INTEGER DEFAULT 1);");
db.execSQL("INSERT INTO push (_id, type, source, body, timestamp, device_id) SELECT _id, type, source, body, timestamp, device_id FROM push_backup;");
db.execSQL("DROP TABLE push_backup;");
}

db.setTransactionSuccessful();
db.endTransaction();
}
Expand Down

1 comment on commit 43c1576

@WhisperBTC
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! BitHub has sent payment of $104.20USD for this commit.

Please sign in to comment.