Rev 14 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
package com.cesams.twogetskills.inconcert.dao;import android.content.Context;import androidx.room.Room;import androidx.room.migration.Migration;import androidx.sqlite.db.SupportSQLiteDatabase;import com.cesams.twogetskills.inconcert.Constants;public class DatabaseHelper {private static DatabaseHelper _INSTANCE = null;private AppDatabase appDatabase;// other instance variables can be hereprivate DatabaseHelper(Context context) {appDatabase = Room.databaseBuilder(context.getApplicationContext(),AppDatabase.class, Constants.DATABASE_FILENAME).allowMainThreadQueries().addMigrations(MIGRATION_1_2).fallbackToDestructiveMigration().addMigrations(MIGRATION_2_3).fallbackToDestructiveMigration().build();};static final Migration MIGRATION_1_2 = new Migration(1, 2) {@Overridepublic void migrate(SupportSQLiteDatabase database) {database.execSQL("CREATE TABLE `tb_notification` (`id` INTEGER NOT NULL, "+ "`title` TEXT,`date` TEXT,`description` TEXT, viewed TEXT, url TEXT, PRIMARY KEY(`id`))");database.execSQL("ALTER TABLE `tb_capsules`"+ "ADD COLUMN added_on TEXT");database.execSQL("ALTER TABLE `tb_capsules`"+ "ADD COLUMN updated_on TEXT");database.execSQL("ALTER TABLE `tb_topics`"+ "ADD COLUMN added_on TEXT");database.execSQL("ALTER TABLE `tb_topics`"+ "ADD COLUMN updated_on TEXT");}};static final Migration MIGRATION_2_3 = new Migration(2, 3) {@Overridepublic void migrate(SupportSQLiteDatabase database) {database.execSQL("ALTER TABLE `tb_capsules`"+ "ADD COLUMN link_comments TEXT");database.execSQL("ALTER TABLE `tb_capsules`"+ "ADD COLUMN link_comment_add TEXT");database.execSQL("ALTER TABLE `tb_capsules`"+ "ADD COLUMN total_comments INTEGER NOT NULL DEFAULT 0");database.execSQL("ALTER TABLE `tb_capsules`"+ "ADD COLUMN total_rating INTEGER NOT NULL DEFAULT 0");database.execSQL("CREATE TABLE `learning_config` (`id` INTEGER NOT NULL, "+ "`title` TEXT,`now` TEXT, PRIMARY KEY(`id`))");}};public static DatabaseHelper getInstance(Context context) {if (_INSTANCE == null) {_INSTANCE = new DatabaseHelper(context);}return(_INSTANCE);}public AppDatabase getAppDatabase() {return appDatabase;}}