Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database (from an older version of the app) initialization error when starting app #431

Closed
stephanegigandet opened this issue Jul 20, 2021 · 2 comments · Fixed by #432
Closed
Assignees
Labels
🐛 bug Something isn't working db migrations Database migrations

Comments

@stephanegigandet
Copy link
Contributor

The app crashes when I try to run the latest version on the develop branch. It's been a while since I last ran the app, so I probably have a very outdated database. Was the database schema supposed to be upgraded at startup?

E/SQLiteLog(10320): (1) table product_extra has no column named extra_int_value
I/flutter (10320): error DatabaseException(table product_extra has no column named extra_int_value (code 1 SQLITE_ERROR[1]): , while compiling: insert into product_extra(barcode,extra_key,extra_value,extra_int_value,last_upsert) values(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,
I/flutter (10320): Cannot init database: DatabaseException(table product_extra has no column named extra_int_value (code 1 SQLITE_ERROR[1]): , while compiling: insert into product_extra(barcode,extra_key,extra_value,extra_int_value,last_upsert) values(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?)

======== Exception caught by widgets library =======================================================
The following LateError was thrown building FutureBuilder(dirty, state: _FutureBuilderState#15f11):
LateInitializationError: Field '_localDatabase@1508201748' has not been initialized.

When the exception was thrown, this was the stack:
#0 _MyAppState._localDatabase (package:smooth_app/main.dart)
#1 _MyAppState.build. (package:smooth_app/main.dart:109:26)
#2 _FutureBuilderState.build (package:flutter/src/widgets/async.dart:775:55)
#3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4691:27)
#4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15)

@stephanegigandet stephanegigandet added the 🐛 bug Something isn't working label Jul 20, 2021
@stephanegigandet stephanegigandet self-assigned this Jul 20, 2021
@stephanegigandet
Copy link
Contributor Author

Seems to be an ordering issue of the upgrade, we never get to DaoProductExtra.onUpgrade :

I/flutter (10320): _onUpgrade - database oldVersion: 4 - newVersion: 8
I/flutter (10320): before avait DaoProduct.onUpgrade
I/flutter (10320): dao_product - onUpgrade - database oldVersion: 4 - newVersion: 8
I/flutter (10320): before avait DaoProductList.onUpgrade
I/flutter (10320): dao_product_list - onUpgrade - database oldVersion: 4 - newVersion: 8
E/SQLiteLog(10320): (1) table product_extra has no column named extra_int_value

@monsieurtanuki
Copy link
Contributor

@stephanegigandet For the record, there's a database version number in LocalDatabase.getLocalDatabase() (currently it's 8).
The way sqflite works is that onUpgrade(Database db, int oldVersion, int newVersion) is automatically called when the version number is upgraded. Or when you start from scratch (as we did not set onCreate).
Every time you want to add a column to a table or do something similar (about structure), you need to upgrade the version number and to include your database changes in a code called by onUpgrade.

monsieurtanuki added a commit that referenced this issue Jul 21, 2021
…upgrade-order

Fixes #431 by changing the order of the database upgrade
teolemon added a commit that referenced this issue Jul 23, 2021
* feature/#349 - history and scan lists now have displayed timestamps

History and Scan lists now behave differently from the other lists.
They use "extra data": a product is in the History (or the Scan) list
if it has as an "extra data" the "last seen timestamp" (or the last scan timestamp).

Bad news: as it's a new concept in the app, we'll start from scratch for both lists.

Impacted files:
* `continuous_scan_model.dart`: new way of adding a product to scanned products; refactoring
* `continuous_scan_page.dart`: unrelated color fix
* `dao_product.dart`: added "last seen" and "last scan" as extra data, with a direct access to products that have those extra data
* `dao_product_list.dart`: history and scan lists are now handled as "different" lists, computed from the "last seen" and "last scan" extra data; refactored
* `product_list.dart`: added extra `int` data; cleaner "same product list" test
* `product_list_dialog_helper.dart`: cleaner "same product list" test
* `product_list_page.dart`: added dates to the display
* `product_page.dart`: simplified history management
* `smooth_product_card_found.dart`: added an optional `refresh` parameter, after visiting the product page

* New Crowdin translations by Github Action

* feature/#349 - now we store and display the whole history and scan timestamps

In table `product_extra` we added an `int` column:
* the primary keys are barcode and "extra key" (e.g. an id for each different list)
* there is an `int` value and a `String` value
* the `int` value is used for ordering data (timestamps or 1,2,3,...)
* the `String` value is used for storing more complex data as json (e.g. the list of timestamps for history)

The contents of table `product_extra` can be stored in flutter code with the new class `ProductExtra` (basically, `int` and `String`)

For the moment the history and scan timestamps of each product are available via a lousy button at the end of the page.

New file:
* `product_extra.dart`: Extra data attached to a Product when it belongs to a ProductList

Impacted files:
* `dao_product.dart`: added an `int` column to the product extra table; now we use new class `ProductExtra`; refactored
* `dao_product_list.dart`: now we use new class `ProductExtra`; refactored
* `local_database.dart`: upgraded the db version because of a new column; added helper method `timestampToDateTime`
* `product_list.dart`: now we use new class `ProductExtra`; refactored
* `product_list_page.dart`: now we use new class `ProductExtra`
* `product_page.dart`: added a sample button at the end of the page in order to display all history and scans related to the product

* feature/#349 - refactoring the db + storing the product refresh timestamps

New files:
* `abstract_dao.dart`: DAO abstraction
* `dao_product_extra.dart`: DAO for Product Extra data

Impacted files:
* `barcode_product_query.dart`: automatically storing the product in the database
* `continuous_scan_model.dart`: refactored
* `dao_product.dart`: now extends new class `AbstractDao`; moved code to new class `DaoProductExtra`; refactored; optimized bulk actions
* `dao_product_list.dart`: now extends new class `AbstractDao`; now using new class `DaoProductExtra`; removed a SQLite foreign key for performance reasons; not storing products anymore (it's done somewhere else)
* `database_product_list_supplier.dart`: refactored because of `ProductListSupplier`
* `local_database.dart`: new database version; added `DaoProductExtra`
* `main.dart`: more verbose database crash message
* `product_dialog_helper.dart`: minor refactoring
* `product_list_supplier.dart`: refactored
* `product_page.dart`: now we display the access, the scan and the refresh timestamps in the lousy temporary button
* `product_query_model.dart`: removed the code regarding storing products in the database as it's now done in the `QueryProductListSupplier`
* `product_query_page.dart`: minor refactoring
* `product_query_page_helper.dart`: refactored because of `ProductListSupplier`
* `query_product_list_supplier.dart`: automatically storing the products in the database; refactored because of `ProductListSupplier`

* feature/#349 - refactoring the db + storing the product refresh timestamps

Impacted file:
* `continuous_scan_model.dart`: minor private variable renaming

* Update crowdin.yml

* Updated dependencies (#410)

* Update home_page.dart

* Update home_page.dart (#411)

* Linting

* Linting (#412)

* start

* feature/#166_3 - user product lists are now reorderable

Database table `product_extra` replaces now dropped `product_list_item`.

New files:
* `bulk_deletable.dart`: Interface for bulk database deletes
* `bulk_insertable.dart`: Interface for bulk database inserts
* `bulk_manager.dart`: Manager for bulk database inserts and deletes

Impacted files:
* `abstract_dao.dart`: moved specific code to new classes `Bulk...`
* `dao_product.dart`: refactored
* `dao_product_extra.dart`: now manages the product list as "product extra"; now implements new interface `BulkDeletable`
* `dao_product_list.dart`: moved the data from table `product_list_item` to table `product_extra`; dropped table `product_list_item`; refactored
* `home_page.dart`: refresh after product list preview
* `list_page.dart`: refresh after product list preview
* `local_database.dart`: new database version
* `multi_select_product_page.dart`: refactored
* `product_copy_helper.dart`: refactored
* `product_list.dart`: added the list reordering feature; refactored
* `product_list_dialog_helper.dart`: refactored
* `product_list_page.dart`: some product lists are now reorderable and with dismissible items
* `product_list_preview.dart`: added the `andThen` parameter for a refresh afterwards
* `product_page.dart`: minor fix
* `query_product_list_supplier.dart`: refactored
* `smooth_it_model.dart`: refactored

* .

* .

* .

* Null safety on data_models and database folders

As a side effect I've also removed 4 stale files that were kept "just in case".

* Null safety

Co-Authored-By: monsieurtanuki <[email protected]>

* Null safety

* Null safety: no more "official" errors

* invisible bug fix 1

* Null safety

* linting

* Update pubspec.yaml

* Update pubspec.yaml

* New Crowdin translations by Github Action

* Adding template files

* Adding template files

* Flutter format

* Deleyte the desktop version

* feature/#166 _4 - put back pantries and shopping lists, as regular "database" product lists

Now the database and the code is much more consistent.
Is that relevant to display pantries and shopping lists in the home page? That's another story.
But at least for the tests and for brainstorming purposes, it's good to see that it's easy to create product list types with different UIs.

Deleted files:
* `pantry.dart`
* `pantry_button.dart`
* `pantry_dialog_helper.dart`
* `pantry_list_page.dart`
* `pantry_page.dart`
* `pantry_preview.dart`

New files:
* `product_list_add_button.dart`: "Add button" related to a user product list type
* `product_list_item.dart`: Widget for a `ProductList` item, for all product list types
* `product_list_item_pantry.dart`: Widget for a `ProductList` item (pantry)
* `product_list_item_shopping.dart`: Widget for a `ProductList` item (shopping list)
* `product_list_item_simple.dart`: Widget for a `ProductList` item (simple product list)

Impacted files:
* `home_page.dart`: now displays pantries and shopping lists (as product lists) and removed dead commented code
* `list_page.dart`: now manages new product list types; now uses new class `ProductListAddButton`
* `multi_select_product_page.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_copy_helper.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_copy_view.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_list.dart`: create new list types for pantries and shopping lists;
* `product_list_button.dart`: moved code to new class `ProductListAddButton` - here we only care about
* `product_list_dialog_helper.dart`: now manages new product list types, more specifically in method `openNew`
* `product_list_page.dart`: now manages new product list types, by using new class `ProductListItem`
* `product_page.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_query_page_helper.dart`: handled the new product list types; refactored
* `smooth_product_card_found.dart`: unrelated fix
* `user_preferences.dart`: removed everything related to pantry and shopping

* feature/#37 - "details" button for ecoscore with html page display

New file:
* `html_page.dart`: Displays as widgets a HTML page

Impacted files:
* `attribute_card.dart`: added a barcode parameter that is needed (only) for ecoscore details; added a "details" button for ecoscore with html page display
* `attribute_list_expandable.dart`: added a now relevant barcode parameter to `AttributeCard`
* `pubspec.yaml`: added `flutter_widget_from_html_core` for html page display

* feature/#37 - "details" button for ecoscore with html page display

New file:
* `html_page.dart`: Displays as widgets a HTML page

Impacted files:
* `attribute_card.dart`: added a barcode parameter that is needed (only) for ecoscore details; added a "details" button for ecoscore with html page display
* `attribute_list_expandable.dart`: added a now relevant barcode parameter to `AttributeCard`
* `pubspec.yaml`: added `flutter_widget_from_html_core` for html page display

* feature/#166 _4 - put back pantries and shopping lists, as regular "database" product lists

Now the database and the code is much more consistent.
Is that relevant to display pantries and shopping lists in the home page? That's another story.
But at least for the tests and for brainstorming purposes, it's good to see that it's easy to create product list types with different UIs.

Deleted files:
* `pantry.dart`
* `pantry_button.dart`
* `pantry_dialog_helper.dart`
* `pantry_list_page.dart`
* `pantry_page.dart`
* `pantry_preview.dart`

New files:
* `product_list_add_button.dart`: "Add button" related to a user product list type
* `product_list_item.dart`: Widget for a `ProductList` item, for all product list types
* `product_list_item_pantry.dart`: Widget for a `ProductList` item (pantry)
* `product_list_item_shopping.dart`: Widget for a `ProductList` item (shopping list)
* `product_list_item_simple.dart`: Widget for a `ProductList` item (simple product list)

Impacted files:
* `home_page.dart`: now displays pantries and shopping lists (as product lists) and removed dead commented code
* `list_page.dart`: now manages new product list types; now uses new class `ProductListAddButton`
* `multi_select_product_page.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_copy_helper.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_copy_view.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_list.dart`: create new list types for pantries and shopping lists;
* `product_list_button.dart`: moved code to new class `ProductListAddButton` - here we only care about
* `product_list_dialog_helper.dart`: now manages new product list types, more specifically in method `openNew`
* `product_list_page.dart`: now manages new product list types, by using new class `ProductListItem`
* `product_page.dart`: simplified by removing the pantries and shopping lists, as they are now just special product lists
* `product_query_page_helper.dart`: handled the new product list types; refactored
* `smooth_product_card_found.dart`: unrelated fix
* `user_preferences.dart`: removed everything related to pantry and shopping

* Update crowdin.yml

* feature/#338 - explicit "server search" button and "local result" label

In order to avoid confusion in the suggestion display.

Impacted file:
* `text_search_widget.dart`: added a fake null Product for server search button

* New Crowdin translations by Github Action

* feature_2/#37 - preparing the code for the next openfoodfacts-dart version

Impacted file:
* `attribute_card.dart`: preparing the code for when OpenFoodAPIClient.getEcoscoreHtmlDescription is available

* fix/#427 - dialogs and context management with list items

Impacted file:
* `text_search_widget.dart`: now using the "main" context for the dialogs, instead of the transient single item context

* remove vulnerability

* feature/#429 - possible barcode suggestions

Impacted files:
* `bulk_manager.dart`: unrelated - fixed a bug about the number of parameters for bulk insert; `insert` method now returns the number of inserted rows; `delete` method now returns the number of deleted rows
* `dao_product.dart`: added barcode for suggestion if text is number; refactored
* `text_search_widget.dart`: added the barcode to the suggestion results

* Fixes #431 by changing the order of the database upgrade

* Remove unused code and deprecated fields/methods

* removed deprecated fields and methods

* new Smoothie icons

* built new splash screen

* built new splash screen

* changed app name from smooth_app to Smoothie

* fixed transparency for glass reflection

* use pnnsGroup2 filter instead of deprecated queryPnnsGroup

* Replace lc query param with language, fixes #433

* Update README.md

* minor change to export filename

* removed default flutter Logo

* removed /assets/temp/, added /assets/app/

Co-authored-by: monsieurtanuki <[email protected]>
Co-authored-by: Crowdin Bot <[email protected]>
Co-authored-by: Marvin M <[email protected]>
Co-authored-by: monsieurtanuki <[email protected]>
Co-authored-by: mboussaid <[email protected]>
Co-authored-by: Stéphane Gigandet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working db migrations Database migrations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants