From c830c037f7a4515cd304d2fa47d0efb047189fd7 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 1 Jan 2016 13:13:22 +0100 Subject: [PATCH] Fix #11 --- .../eu/kanade/mangafeed/data/database/DbOpenHelper.java | 9 +++++++-- .../mangafeed/data/database/tables/MangaSyncTable.java | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java index e58cbcb1a9..8fdfca7051 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/DbOpenHelper.java @@ -14,7 +14,7 @@ import eu.kanade.mangafeed.data.database.tables.MangaTable; public class DbOpenHelper extends SQLiteOpenHelper { public static final String DATABASE_NAME = "mangafeed.db"; - public static final int DATABASE_VERSION = 1; + public static final int DATABASE_VERSION = 2; public DbOpenHelper(@NonNull Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -36,7 +36,12 @@ public class DbOpenHelper extends SQLiteOpenHelper { @Override public void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) { - + if (oldVersion == 1) { + db.execSQL("ALTER TABLE manga_sync RENAME TO tmp;"); + db.execSQL(MangaSyncTable.getCreateTableQuery()); + db.execSQL("INSERT INTO " + MangaSyncTable.TABLE + " SELECT * FROM tmp;"); + db.execSQL("DROP TABLE tmp;"); + } } @Override diff --git a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java index 7dcdd86b47..09779b3325 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/database/tables/MangaSyncTable.java @@ -36,6 +36,7 @@ public class MangaSyncTable { + COLUMN_TOTAL_CHAPTERS + " INTEGER NOT NULL, " + COLUMN_STATUS + " INTEGER NOT NULL, " + COLUMN_SCORE + " FLOAT NOT NULL, " + + "UNIQUE (" + COLUMN_MANGA_ID + ", " + COLUMN_SYNC_ID + ") ON CONFLICT REPLACE, " + "FOREIGN KEY(" + COLUMN_MANGA_ID + ") REFERENCES " + MangaTable.TABLE + "(" + MangaTable.COLUMN_ID + ") " + "ON DELETE CASCADE" + ");";