Skip to content

Commit

Permalink
updates onUpgrade method in the DatabaseHelper class
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferjinyoungyang committed Aug 14, 2023
1 parent 7192294 commit 2f06c2d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/src/main/java/com/courseproject/tindar/ds/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class DatabaseHelper extends SQLiteOpenHelper implements EditProfileDsGat
* test database instance
*/
private static DatabaseHelper testDbInstance;
/**
* current database version
*/
private static final int databaseVersion = 2;
/**
* table name for the accounts
*/
Expand Down Expand Up @@ -254,7 +258,7 @@ public static synchronized DatabaseHelper getTestInstance(Context context) {
private DatabaseHelper(@Nullable Context context, String databaseName) {
// access modifier is private so DatabaseHelper doesn't get directly instantiated. The instantiation of
// DatabaseHelper should go through getInstance method.
super(context, databaseName, null, 1);
super(context, databaseName, null, databaseVersion);
}

/**
Expand Down Expand Up @@ -283,12 +287,14 @@ public void onCreate(SQLiteDatabase db) {
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ACCOUNTS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_LIKES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_MATCHES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_MESSAGES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONVERSATIONS);
onCreate(db);
if (oldVersion < newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ACCOUNTS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_LIKES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_MATCHES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_MESSAGES);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONVERSATIONS);
onCreate(db);
}
}

/**
Expand Down

0 comments on commit 2f06c2d

Please sign in to comment.