Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9954b02

Browse files
committedOct 9, 2017
fix migrations, add docs to versions.gradle
1 parent ff2bd73 commit 9954b02

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed
 

‎PersistenceMigrationsSample/app/src/room2/java/com/example/android/persistence/migrations/UsersDatabase.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,8 @@ public void migrate(SupportSQLiteDatabase database) {
6767
static final Migration MIGRATION_2_3 = new Migration(2, 3) {
6868
@Override
6969
public void migrate(SupportSQLiteDatabase database) {
70-
database.execSQL("CREATE TABLE IF NOT EXISTS Users_new ("
71-
+ "`userid` INTEGER NOT NULL,"
72-
+ "`username` TEXT,"
73-
+ "`last_update` INTEGER,"
74-
+ "PRIMARY KEY(`userid`))");
75-
database.execSQL("INSERT INTO Users_new "
76-
+ " SELECT userid, username, null FROM Users");
77-
database.execSQL("DROP TABLE Users");
78-
database.execSQL("ALTER TABLE Users_new RENAME TO users");
70+
database.execSQL("ALTER TABLE Users "
71+
+ " ADD COLUMN last_update INTEGER");
7972
}
8073
};
8174

‎PersistenceMigrationsSample/app/src/room3/java/com/example/android/persistence/migrations/UsersDatabase.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,8 @@ public void migrate(SupportSQLiteDatabase database) {
6767
static final Migration MIGRATION_2_3 = new Migration(2, 3) {
6868
@Override
6969
public void migrate(SupportSQLiteDatabase database) {
70-
database.execSQL("CREATE TABLE IF NOT EXISTS Users_new ("
71-
+ "`userid` INTEGER NOT NULL,"
72-
+ "`username` TEXT,"
73-
+ "`last_update` INTEGER,"
74-
+ "PRIMARY KEY(`userid`))");
75-
database.execSQL("INSERT INTO Users_new "
76-
+ " SELECT userid, username, null FROM Users");
77-
database.execSQL("DROP TABLE Users");
78-
database.execSQL("ALTER TABLE Users_new RENAME TO users");
70+
database.execSQL("ALTER TABLE users "
71+
+ " ADD COLUMN last_update INTEGER");
7972
}
8073
};
8174

‎PersistenceMigrationsSample/app/src/sqlite/java/com/example/android/persistence/migrations/UsersDbHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class UsersDbHelper extends SQLiteOpenHelper {
3535

3636
private static final String SQL_CREATE_ENTRIES =
3737
"CREATE TABLE " + TABLE_NAME + " (" +
38-
COLUMN_NAME_ENTRY_ID + " INTEGER PRIMARY KEY," +
38+
COLUMN_NAME_ENTRY_ID + " INTEGER PRIMARY KEY NOT NULL," +
3939
COLUMN_NAME_USERNAME + " TEXT )";
4040

4141
public UsersDbHelper(Context context) {

‎versions.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Shared file between builds so that they can all use the same dependencies and
3+
* maven repositories.
4+
**/
15
ext.deps = [:]
26
def versions = [:]
37
versions.arch = hasProperty("ARCH_VERSION") ? getProperty("ARCH_VERSION") : "1.0.0-beta2"

0 commit comments

Comments
 (0)
Please sign in to comment.