Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 39 | Rev 58 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 gabriel 1
package com.cesams.twogetskills.dao;
2
 
3
import android.content.Context;
4
 
5
import androidx.room.Room;
19 gabriel 6
import androidx.room.migration.Migration;
7
import androidx.sqlite.db.SupportSQLiteDatabase;
1 gabriel 8
 
9
import com.cesams.twogetskills.Constants;
19 gabriel 10
import com.cesams.twogetskills.entity.NotificationCenter;
1 gabriel 11
 
12
public class DatabaseHelper {
13
 
14
 
15
    private static DatabaseHelper _INSTANCE = null;
16
    private AppDatabase appDatabase;
17
 
18
    // other instance variables can be here
19
 
20
    private DatabaseHelper(Context context) {
21
        appDatabase = Room.databaseBuilder(
22
                context.getApplicationContext(),
23
                AppDatabase.class, Constants.DATABASE_FILENAME
19 gabriel 24
        ).allowMainThreadQueries().addMigrations(MIGRATION_1_2).fallbackToDestructiveMigration()
25
                .build();
1 gabriel 26
    };
27
 
19 gabriel 28
    static final Migration MIGRATION_1_2 = new Migration(1, 2) {
29
        @Override
30
        public void migrate(SupportSQLiteDatabase database) {
31
            database.execSQL("CREATE TABLE `tb_notification` (`id` INTEGER NOT NULL, "
39 gabriel 32
                    + "`title` TEXT,`date` TEXT,`description` TEXT, viewed TEXT, url TEXT, PRIMARY KEY(`id`))");
21 gabriel 33
 
34
            database.execSQL("ALTER TABLE `tb_capsules`"
35
                    + "ADD COLUMN added_on TEXT");
36
 
37
            database.execSQL("ALTER TABLE `tb_capsules`"
38
                    + "ADD COLUMN updated_on TEXT");
39
 
40
            database.execSQL("ALTER TABLE `tb_topics`"
43 gabriel 41
                    + "ADD COLUMN added_on TEXT");
21 gabriel 42
 
43
            database.execSQL("ALTER TABLE `tb_topics`"
44
                    + "ADD COLUMN updated_on TEXT");
45
 
46
 
19 gabriel 47
        }
48
    };
49
 
43 gabriel 50
 
1 gabriel 51
    public static DatabaseHelper getInstance(Context context) {
52
        if (_INSTANCE == null) {
53
            _INSTANCE = new DatabaseHelper(context);
54
        }
55
        return(_INSTANCE);
56
    }
57
 
58
    public AppDatabase getAppDatabase() {
59
        return appDatabase;
60
    }
61
}