Proyectos de Subversion Android Microlearning - Nuevo Interface

Rev

Rev 43 | Rev 65 | 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
58 gabriel 24
        ).allowMainThreadQueries().addMigrations(MIGRATION_1_2).fallbackToDestructiveMigration().addMigrations(MIGRATION_2_3).fallbackToDestructiveMigration()
19 gabriel 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
 
58 gabriel 50
    static final Migration MIGRATION_2_3 = new Migration(2, 3) {
51
        @Override
52
        public void migrate(SupportSQLiteDatabase database) {
53
            database.execSQL("ALTER TABLE `tb_capsules`"
54
                    + "ADD COLUMN link_comments TEXT");
43 gabriel 55
 
58 gabriel 56
            database.execSQL("ALTER TABLE `tb_capsules`"
57
                    + "ADD COLUMN link_comment_add TEXT");
58
 
59
            database.execSQL("ALTER TABLE `tb_capsules`"
60
                    + "ADD COLUMN total_comments INTEGER");
61
 
62
            database.execSQL("ALTER TABLE `tb_capsules`"
63
                    + "ADD COLUMN total_rating INTEGER");
64
 
65
 
66
        }
67
    };
68
 
69
 
1 gabriel 70
    public static DatabaseHelper getInstance(Context context) {
71
        if (_INSTANCE == null) {
72
            _INSTANCE = new DatabaseHelper(context);
73
        }
74
        return(_INSTANCE);
75
    }
76
 
77
    public AppDatabase getAppDatabase() {
78
        return appDatabase;
79
    }
80
}