Skip to content

Commit

Permalink
Fixes crash when exporting after upgrading to v2.4.1-beta1 from v2.4.0
Browse files Browse the repository at this point in the history
   The commudity UIDs across the database were invalidated.
   A new migration has been added to refresh them after a new import.
   This issue only affects beta1 users. Users who went directly from
   v2.4.0 to v2.4.1-beta2 are not affected

 - Properly refrsh the book name in the accounts activity
  • Loading branch information
codinguser committed Nov 27, 2019
1 parent a9fcb9f commit 8631c7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DatabaseSchema {
* Version number of database containing accounts and transactions info.
* With any change to the database schema, this number must increase
*/
public static final int DATABASE_VERSION = 16;
public static final int DATABASE_VERSION = 17;

/**
* Name of the database
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/org/gnucash/android/db/MigrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1653,4 +1653,26 @@ static int upgradeDbToVersion16(SQLiteDatabase db) {

return dbVersion;
}

/**
* Upgrades the database to version 17.
* This migration updates the foreign keys to the commodities in the splits table
* after a previous migration which overwrote the db table for commodities, rendering
* all foreign keys to commodity GUIDs invalid.
*
* @param db SQLite database to be upgraded
* @return New database version, 16 if migration succeeds, 15 otherwise
*/
static int upgradeDbToVersion17(SQLiteDatabase db) {
Log.i(LOG_TAG, "Upgrading database to version 17");
int dbVersion = 16;

db.beginTransaction();
db.execSQL("UPDATE accounts SET commodity_uid = (SELECT uid FROM commodities WHERE mnemonic = accounts.currency_code)");
db.execSQL("UPDATE transactions SET commodity_uid = (SELECT uid FROM commodities WHERE commodities.mnemonic = transactions.currency_code)");

db.endTransaction();

return dbVersion + 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.PreferenceManager;
import android.util.Log;
Expand Down Expand Up @@ -227,7 +228,6 @@ public void onCreate(Bundle savedInstanceState) {

init();

getSupportActionBar().setSubtitle(BooksDbAdapter.getInstance().getActiveBookDisplayName());
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(R.string.title_recent_accounts));
tabLayout.addTab(tabLayout.newTab().setText(R.string.title_all_accounts));
Expand Down Expand Up @@ -269,6 +269,15 @@ public void onClick(View v) {
});
}

@Override
protected void onResume() {
super.onResume();
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setSubtitle(BooksDbAdapter.getInstance().getActiveBookDisplayName());
}
}

@Override
protected void onStart() {
super.onStart();
Expand Down

0 comments on commit 8631c7f

Please sign in to comment.