diff --git a/mobile/src/main/java/ru/omni_devel/cards/DbHelper.kt b/mobile/src/main/java/ru/omni_devel/cards/DbHelper.kt index f8843fd..7d7a2eb 100644 --- a/mobile/src/main/java/ru/omni_devel/cards/DbHelper.kt +++ b/mobile/src/main/java/ru/omni_devel/cards/DbHelper.kt @@ -8,7 +8,7 @@ import com.google.zxing.BarcodeFormat class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?) : SQLiteOpenHelper(context, "omni_cards", factory, 5) { override fun onCreate(db: SQLiteDatabase?) { - db!!.execSQL("CREATE TABLE IF NOT EXISTS cards (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, codeType TEXT, codeValue TEXT, color TEXT, position INTEGER DEFAULT 0)") + db!!.execSQL("CREATE TABLE IF NOT EXISTS cards (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, codeType TEXT, codeValue TEXT, color TEXT)") } override fun onUpgrade( diff --git a/wear/src/main/java/ru/omni_devel/cards/presentation/DbHelper.kt b/wear/src/main/java/ru/omni_devel/cards/presentation/DbHelper.kt index f5d726c..6aa41c5 100644 --- a/wear/src/main/java/ru/omni_devel/cards/presentation/DbHelper.kt +++ b/wear/src/main/java/ru/omni_devel/cards/presentation/DbHelper.kt @@ -6,7 +6,7 @@ import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper import com.google.zxing.BarcodeFormat -class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?) : SQLiteOpenHelper(context, "omni_cards", factory, 2) { +class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?) : SQLiteOpenHelper(context, "omni_cards", factory, 4) { override fun onCreate(db: SQLiteDatabase?) { db!!.execSQL("CREATE TABLE IF NOT EXISTS cards (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, codeType TEXT, codeValue TEXT, color TEXT)") } @@ -19,6 +19,17 @@ class DbHelper(val context: Context, val factory: SQLiteDatabase.CursorFactory?) if (oldVersion < 2) { db!!.execSQL("ALTER TABLE cards ADD COLUMN color TEXT") } + + if (oldVersion < 3) { + db!!.execSQL("ALTER TABLE cards ADD COLUMN position INTEGER DEFAULT 0") + db.execSQL("ALTER TABLE cards ADD COLUMN iconPath TEXT") + db.execSQL("UPDATE cards SET position = id") + } + + if (oldVersion < 4) { + db!!.execSQL("ALTER TABLE cards DROP COLUMN position") + db.execSQL("ALTER TABLE cards DROP COLUMN iconPath") + } } fun clearDatabase() {