├── .gitignore
├── .travis.yml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ ├── assets
│ │ ├── database_v1.db
│ │ ├── database_v2.db
│ │ ├── database_v3.db
│ │ └── database_v4.db
│ └── java
│ │ └── za
│ │ └── co
│ │ └── riggaroo
│ │ └── databaseupgrades
│ │ ├── ApplicationTest.java
│ │ └── db
│ │ └── DatabaseUpgradesTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── from_1_to_2.sql
│ │ ├── from_2_to_3.sql
│ │ └── from_3_to_4.sql
│ ├── java
│ │ └── za
│ │ │ └── co
│ │ │ └── riggaroo
│ │ │ └── databaseupgrades
│ │ │ ├── MainActivity.java
│ │ │ └── db
│ │ │ ├── BookEntry.java
│ │ │ └── DatabaseHelper.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── za
│ └── co
│ └── riggaroo
│ └── databaseupgrades
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .DS_Store
5 | /build
6 | /captures
7 | .idea/**
8 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk7
3 | # Turn off caching to avoid any caching problems
4 | cache: false
5 | # Use the Travis Container-Based Infrastructure
6 | sudo: false
7 |
8 | android:
9 | components:
10 | - platform-tools
11 | - tools
12 |
13 | - build-tools-23.0.2
14 | - android-23
15 |
16 | - extra-google-m2repository
17 | - extra-android-m2repository
18 | - addon-google_apis-google-19
19 | - sys-img-armeabi-v7a-android-21
20 |
21 | env:
22 | global:
23 | # install timeout in minutes (2 minutes by default)
24 | - ADB_INSTALL_TIMEOUT=8
25 |
26 | # Emulator Management: Create, Start and Wait
27 | before_script:
28 | - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
29 | - emulator -avd test -no-skin -no-audio -no-window &
30 | - android-wait-for-emulator
31 | - adb shell input keyevent 82 &
32 |
33 | script:
34 | - android list target
35 | - ./gradlew connectedAndroidTest
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidDatabaseUpgrades
2 | A demo application showing the correct way to do database upgrades in your Android application using SQLite and the onUpgrade method
3 |
4 | Read the full blog post here : http://riggaroo.co.za/android-sqlite-database-use-onupgrade-correctly/
5 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "za.co.riggaroo.databaseupgrades"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 4
12 | versionName "1.0.3"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | packagingOptions {
23 | exclude 'META-INF/ASL2.0'
24 | exclude 'META-INF/LICENSE'
25 | exclude 'META-INF/license.txt'
26 | exclude 'META-INF/LICENSE.txt'
27 | exclude 'META-INF/NOTICE'
28 | exclude 'META-INF/NOTICE.txt'
29 | exclude 'META-INF/notice.txt'
30 |
31 | exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
32 | exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
33 | exclude 'LICENSE.txt'
34 | }
35 | }
36 |
37 | dependencies {
38 | compile fileTree(dir: 'libs', include: ['*.jar'])
39 | testCompile 'junit:junit:4.12'
40 | compile 'com.android.support:appcompat-v7:23.1.1'
41 | androidTestCompile ('com.android.support.test.espresso:espresso-web:2.2.1'){
42 | exclude module: 'support-annotations'
43 | exclude module: 'support-v4'
44 | }
45 | androidTestCompile ("com.android.support.test:runner:$rootProject.ext.runnerVersion"){
46 | exclude module: 'support-annotations'
47 | exclude module: 'support-v4'
48 | }
49 | androidTestCompile ("com.android.support.test:rules:$rootProject.ext.runnerVersion"){
50 | exclude module: 'support-annotations'
51 | exclude module: 'support-v4'
52 | }
53 |
54 | // Espresso UI Testing
55 | androidTestCompile ("com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion"){
56 | exclude module: 'recyclerview-v7'
57 | exclude module: 'support-annotations'
58 | exclude module: 'support-v4'
59 | exclude group: "javax.inject"
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/rebeccafranks/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/assets/database_v1.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/androidTest/assets/database_v1.db
--------------------------------------------------------------------------------
/app/src/androidTest/assets/database_v2.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/androidTest/assets/database_v2.db
--------------------------------------------------------------------------------
/app/src/androidTest/assets/database_v3.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/androidTest/assets/database_v3.db
--------------------------------------------------------------------------------
/app/src/androidTest/assets/database_v4.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/androidTest/assets/database_v4.db
--------------------------------------------------------------------------------
/app/src/androidTest/java/za/co/riggaroo/databaseupgrades/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package za.co.riggaroo.databaseupgrades;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/za/co/riggaroo/databaseupgrades/db/DatabaseUpgradesTest.java:
--------------------------------------------------------------------------------
1 | package za.co.riggaroo.databaseupgrades.db;
2 |
3 | import android.support.test.InstrumentationRegistry;
4 | import android.support.test.runner.AndroidJUnit4;
5 | import android.test.suitebuilder.annotation.LargeTest;
6 | import android.util.Log;
7 |
8 | import junit.framework.Assert;
9 |
10 | import org.junit.Test;
11 | import org.junit.runner.RunWith;
12 |
13 | import java.io.File;
14 | import java.io.FileOutputStream;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 | import java.io.OutputStream;
18 |
19 |
20 | @RunWith(AndroidJUnit4.class)
21 | @LargeTest
22 | public class DatabaseUpgradesTest {
23 |
24 |
25 | private static final String TAG = DatabaseUpgradesTest.class.getCanonicalName();
26 |
27 | /**
28 | * This test runs through all the database versions from the /androidTest/assets/ folder. It copies the old database to the file path of the application.
29 | * It tests that the database upgrades to the correct version.
30 | * If there is an issue with the upgrade, generally a SQLiteException will be thrown and the test will fail.
31 | * for example:
32 | * android.database.sqlite.SQLiteException: duplicate column name: calculated_pages_times_rating (code 1): , while compiling: ALTER TABLE book_information ADD COLUMN calculated_pages_times_rating INTEGER;
33 | *
34 | * @throws IOException if the database cannot be copied.
35 | */
36 | @Test
37 | public void testDatabaseUpgrades() throws IOException {
38 | DatabaseHelper.getInstance(InstrumentationRegistry.getTargetContext());
39 |
40 | for (int i = 1; i < DatabaseHelper.DATABASE_VERSION; i++) {
41 | Log.d(TAG, "Testing upgrade from version:" + i);
42 | DatabaseHelper.clearInstance();
43 | copyDatabase(i);
44 |
45 | DatabaseHelper databaseHelperNew = DatabaseHelper.getInstance(InstrumentationRegistry.getTargetContext());
46 | Log.d(TAG, " New Database Version:" + databaseHelperNew.getWritableDatabase().getVersion());
47 | Assert.assertEquals(DatabaseHelper.DATABASE_VERSION, databaseHelperNew.getWritableDatabase().getVersion());
48 | }
49 |
50 | }
51 |
52 |
53 | private void copyDatabase(int version) throws IOException {
54 | String dbPath = InstrumentationRegistry.getTargetContext().getDatabasePath(DatabaseHelper.DATABASE_NAME).getAbsolutePath();
55 |
56 | String dbName = String.format("database_v%d.db", version);
57 | InputStream mInput = InstrumentationRegistry.getContext().getAssets().open(dbName);
58 |
59 | File db = new File(dbPath);
60 | if (!db.exists()){
61 | db.getParentFile().mkdirs();
62 | db.createNewFile();
63 | }
64 | OutputStream mOutput = new FileOutputStream(dbPath);
65 | byte[] mBuffer = new byte[1024];
66 | int mLength;
67 | while ((mLength = mInput.read(mBuffer)) > 0) {
68 | mOutput.write(mBuffer, 0, mLength);
69 | }
70 | mOutput.flush();
71 | mOutput.close();
72 | mInput.close();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/assets/from_1_to_2.sql:
--------------------------------------------------------------------------------
1 | ALTER TABLE books ADD COLUMN book_rating INTEGER;
--------------------------------------------------------------------------------
/app/src/main/assets/from_2_to_3.sql:
--------------------------------------------------------------------------------
1 | ALTER TABLE books RENAME TO book_information;
--------------------------------------------------------------------------------
/app/src/main/assets/from_3_to_4.sql:
--------------------------------------------------------------------------------
1 | ALTER TABLE book_information ADD COLUMN calculated_pages_times_rating INTEGER;
2 | UPDATE book_information SET calculated_pages_times_rating = (book_pages * book_rating) ;
--------------------------------------------------------------------------------
/app/src/main/java/za/co/riggaroo/databaseupgrades/MainActivity.java:
--------------------------------------------------------------------------------
1 | package za.co.riggaroo.databaseupgrades;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 | import android.database.sqlite.SQLiteDatabase;
6 | import android.support.v4.widget.TextViewCompat;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.util.Log;
10 | import android.widget.TextView;
11 |
12 | import za.co.riggaroo.databaseupgrades.db.BookEntry;
13 | import za.co.riggaroo.databaseupgrades.db.DatabaseHelper;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | private static final String TAG = "MainActivity";
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | DatabaseHelper databaseHelper = DatabaseHelper.getInstance(this);
24 |
25 |
26 | //Note - you shouldn't do this kind of stuff on the main thread in production. This should go onto a background thread. This is just for example purposes.
27 | SQLiteDatabase database = databaseHelper.getWritableDatabase();
28 |
29 | ContentValues contentValues = new ContentValues();
30 | contentValues.put(BookEntry.COL_BOOKNAME, "Life of Pi");
31 | contentValues.put(BookEntry.COL_DESCRIPTION, "Yann Martel's Life of Pi is the story of a young man who survives a harrowing shipwreck and months in a lifeboat with a large Bengal tiger named Richard Parker. The beginning of the novel covers Pi's childhood and youth.");
32 | contentValues.put(BookEntry.COL_NO_PAGES, 24325);
33 | contentValues.put(BookEntry.COL_RATING, 8);
34 | contentValues.put(BookEntry.COL_CALCULATED_RATING, 8 * 24325);
35 | database.insert(BookEntry.TABLE_NAME, null, contentValues);
36 |
37 | ContentValues contentValues2 = new ContentValues();
38 | contentValues2.put(BookEntry.COL_BOOKNAME, "Gone Girl");
39 | contentValues2.put(BookEntry.COL_DESCRIPTION, "In Carthage, Mo., former New York-based writer Nick Dunne (Ben Affleck) and his glamorous wife Amy (Rosamund Pike) present a portrait of a blissful marriage to the public. However, when Amy goes missing on the couple's fifth wedding anniversary, Nick becomes the prime suspect in her disappearance. The resulting police pressure and media frenzy cause the Dunnes' image of a happy union to crumble, leading to tantalizing questions about who Nick and Amy truly are.");
40 | contentValues2.put(BookEntry.COL_NO_PAGES, 45425);
41 | contentValues2.put(BookEntry.COL_RATING, 5);
42 | contentValues.put(BookEntry.COL_CALCULATED_RATING, 5 * 45245);
43 | database.insert(BookEntry.TABLE_NAME, null, contentValues2);
44 |
45 | SQLiteDatabase db = databaseHelper.getWritableDatabase();
46 | Cursor c = db.query(BookEntry.TABLE_NAME, null, null, null, null, null, null);
47 |
48 | String books = "";
49 | while (c.moveToNext()) {
50 | String bookName = c.getString(c.getColumnIndex(BookEntry.COL_BOOKNAME));
51 | String bookDescription = c.getString(c.getColumnIndex(BookEntry.COL_DESCRIPTION));
52 | String rating = c.getString(c.getColumnIndex(BookEntry.COL_RATING));
53 | String calculatedCol = c.getString(c.getColumnIndex(BookEntry.COL_CALCULATED_RATING));
54 |
55 | books += bookName + " - " + bookDescription + ".[RATING]:" + rating + "[CALCULATED RATING]:" + calculatedCol + "\r\n";
56 | Log.d(TAG, "Book Name:" + bookName);
57 |
58 | }
59 | c.close();
60 |
61 | TextView textViewBooks = (TextView) findViewById(R.id.text_view_books);
62 | textViewBooks.setText(books);
63 |
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/za/co/riggaroo/databaseupgrades/db/BookEntry.java:
--------------------------------------------------------------------------------
1 | package za.co.riggaroo.databaseupgrades.db;
2 |
3 |
4 | import android.provider.BaseColumns;
5 |
6 | public class BookEntry implements BaseColumns {
7 |
8 | public static final String TABLE_NAME = "book_information";
9 | public static final String COL_BOOKNAME = "book_name";
10 |
11 | public static final String COL_NO_PAGES = "book_pages";
12 |
13 | public static final String COL_DESCRIPTION = "book_description";
14 | public static final String COL_RATING = "book_rating";
15 | public static final String COL_CALCULATED_RATING = "calculated_pages_times_rating";
16 |
17 | public static final String SQL_CREATE_BOOK_ENTRY_TABLE = "CREATE TABLE " + TABLE_NAME + " (" +
18 | BookEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT , " +
19 | BookEntry.COL_BOOKNAME + " TEXT ," +
20 | BookEntry.COL_DESCRIPTION + " TEXT, " +
21 | BookEntry.COL_RATING + " INTEGER, " +
22 | BookEntry.COL_CALCULATED_RATING + " INTEGER, " +
23 | BookEntry.COL_NO_PAGES + " INTEGER )";
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/za/co/riggaroo/databaseupgrades/db/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package za.co.riggaroo.databaseupgrades.db;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.AssetManager;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteOpenHelper;
8 | import android.support.annotation.VisibleForTesting;
9 | import android.text.TextUtils;
10 | import android.util.Log;
11 |
12 | import java.io.BufferedReader;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.InputStreamReader;
16 |
17 |
18 | public class DatabaseHelper extends SQLiteOpenHelper {
19 |
20 | static final int DATABASE_VERSION = 4;
21 |
22 | static final String DATABASE_NAME = "database.db";
23 | private static final String TAG = DatabaseHelper.class.getName();
24 |
25 | private static DatabaseHelper mInstance = null;
26 | private final Context context;
27 |
28 | private DatabaseHelper(Context context) {
29 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
30 | this.context = context;
31 | }
32 |
33 | public static synchronized DatabaseHelper getInstance(Context ctx) {
34 | if (mInstance == null) {
35 | mInstance = new DatabaseHelper(ctx.getApplicationContext());
36 | }
37 | return mInstance;
38 | }
39 |
40 | @VisibleForTesting
41 | public static void clearInstance() {
42 | mInstance = null;
43 | }
44 |
45 | @Override
46 | public void onCreate(SQLiteDatabase db) {
47 | db.execSQL(BookEntry.SQL_CREATE_BOOK_ENTRY_TABLE);
48 | // The rest of your create scripts go here.
49 |
50 | }
51 |
52 |
53 | @Override
54 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
55 | Log.e(TAG, "Updating table from " + oldVersion + " to " + newVersion);
56 | // You will not need to modify this unless you need to do some android specific things.
57 | // When upgrading the database, all you need to do is add a file to the assets folder and name it:
58 | // from_1_to_2.sql with the version that you are upgrading to as the last version.
59 | for (int i = oldVersion; i < newVersion; ++i) {
60 | String migrationName = String.format("from_%d_to_%d.sql", i, (i + 1));
61 | Log.d(TAG, "Looking for migration file: " + migrationName);
62 | readAndExecuteSQLScript(db, context, migrationName);
63 | }
64 |
65 | }
66 |
67 | @Override
68 | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
69 |
70 | }
71 |
72 | private void readAndExecuteSQLScript(SQLiteDatabase db, Context ctx, String fileName) {
73 | if (TextUtils.isEmpty(fileName)) {
74 | Log.d(TAG, "SQL script file name is empty");
75 | return;
76 | }
77 |
78 | Log.d(TAG, "Script found. Executing...");
79 | AssetManager assetManager = ctx.getAssets();
80 | BufferedReader reader = null;
81 |
82 | try {
83 | InputStream is = assetManager.open(fileName);
84 | InputStreamReader isr = new InputStreamReader(is);
85 | reader = new BufferedReader(isr);
86 | executeSQLScript(db, reader);
87 | } catch (IOException e) {
88 | Log.e(TAG, "IOException:", e);
89 | } finally {
90 | if (reader != null) {
91 | try {
92 | reader.close();
93 | } catch (IOException e) {
94 | Log.e(TAG, "IOException:", e);
95 | }
96 | }
97 | }
98 |
99 | }
100 |
101 | private void executeSQLScript(SQLiteDatabase db, BufferedReader reader) throws IOException {
102 | String line;
103 | StringBuilder statement = new StringBuilder();
104 | while ((line = reader.readLine()) != null) {
105 | statement.append(line);
106 | statement.append("\n");
107 | if (line.endsWith(";")) {
108 | db.execSQL(statement.toString());
109 | statement = new StringBuilder();
110 | }
111 | }
112 | }
113 |
114 | }
115 |
116 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DatabaseUpgrades
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/za/co/riggaroo/databaseupgrades/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package za.co.riggaroo.databaseupgrades;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
25 | ext {
26 | // Sdk and tools
27 | junitVersion = '4.12'
28 | mockitoVersion = '1.10.19'
29 | powerMockito = '1.6.2'
30 | runnerVersion = '0.4.1'
31 | rulesVersion = '0.4.1'
32 | espressoVersion = '2.2.1'
33 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/riggaroo/AndroidDatabaseUpgrades/e2bc396315f7823403c39013814f8dd8aef1b7e6/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------