[ALOY-900] Create a new table with Alloy and pre-built db
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-04-16T14:49:38.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.4.0, 2014 Sprint 08 |
Components | Models |
Labels | alloy, notable, qe-testadded |
Reporter | David Benko |
Assignee | Tim Poulsen |
Created | 2013-12-12T18:25:45.000+0000 |
Updated | 2014-05-15T21:04:50.000+0000 |
Description
Creating a new table with a pre-build db fails because Alloy executes "pragma table_info" to get columns information:
12-11 19:04:30.728: E/TiExceptionHandler(13828): (main) [366,366] ----- Titanium Javascript Runtime Error -----
12-11 19:04:30.728: E/TiExceptionHandler(13828): (main) [0,366] - In alloy/sync/sql.js:11,69
12-11 19:04:30.733: E/TiExceptionHandler(13828): (main) [1,367] - Message: Uncaught TypeError: Cannot call method 'isValidRow' of null
12-11 19:04:30.733: E/TiExceptionHandler(13828): (main) [0,367] - Source: base.install(b,d),d=b.execute('pragma table_info("'+e+'");'),f={};d.isValidRow
12-11 19:04:30.733: E/V8Exception(13828): Exception occurred at alloy/sync/sql.js:11: Uncaught TypeError: Cannot call method 'isValidRow' of null
Detailed problem:
http://developer.appcelerator.com/question/160374/alloy--migrations---create-new-table-with-migrations
Moving this issue to Alloy project based on Tony's recommendation on the Q&A thread.
FYI - JIRA changed the reporter to "me" when I moved this ticket from TC to ALLOY and I don't have permission to change it back. This issue was originally reported by [~davidbenko].
Possible Solution: Place following code in sql.js in line 271. It will create a Table from a Model if it doesn´t exist. If no columns given in the model, the ALLOY_ID_DEFAULT will be taken.
PR https://github.com/appcelerator/alloy/pull/347 Test app included: test/apps/testing/ALOY-900 This change adds support for a few scenarios: * Existing model, which points to an external database, with a migration file used to define a new table in that database * Existing external database, add a new table by simply defining a new model file and instantiating it in a controller, no migration needed * Alloy-created database, add a new table by simply defining a new model file and instantiating it in a controller, no migration needed Functional test: 1. Run the test app in the iOS simulator 2. Open ~/Library/Application Support/iPhone Simulator/VERSION/GUID/Library/Private Documents folder to find the generated sqlite database file 3. Use a SQLite tool, such as the SQLite Manager plugin for Firefox to open that file. It will contain a table named weather with three columns, city, id, and bogusField as defined in the migration 4. Delete the app from the simulator 5. Rename the migrations folder or delete it so that it's not used 6. Repeat steps 1-3, this time the database's table structure will match the table definition in the models/weather.js file 7. Delete the app from the simulator 8. Edit the models/weather.js file to remove the db_file property from the adapter config. 9. Repeat steps 1-3 to create the standard _alloy_.sql file. It will contain the tables as defined in the model
Sorry, not supposed to Resolve till the PR is merged.
PR merged
Ran through the functional test steps mentioned by [~skypanther]. All steps worked as expected. Closing. Environment: Appc Studio : 3.3.0.201405121247 Ti SDK : 3.3.0.v20140514163013 Mac OSX : 10.8.5 Alloy : 1.4.0-alpha CLI - 3.3.0-dev iPhone simulator : 7.1 64-bit