{ "id": "123652", "key": "ALOY-900", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [ { "id": "15758", "description": "Alloy 1.4.0", "name": "Alloy 1.4.0", "archived": false, "released": true, "releaseDate": "2014-07-17" }, { "id": "15904", "description": "2014 Sprint 08", "name": "2014 Sprint 08", "archived": true, "released": true, "releaseDate": "2014-04-24" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2014-04-16T14:49:38.000+0000", "created": "2013-12-12T18:25:45.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "alloy", "notable", "qe-testadded" ], "versions": [], "issuelinks": [], "assignee": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "updated": "2014-05-15T21:04:50.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "13605", "name": "Models" } ], "description": "Creating a new table with a pre-build db fails because Alloy executes \"pragma table_info\" to get columns information:\r\n\r\n{code} \r\n12-11 19:04:30.728: E/TiExceptionHandler(13828): (main) [366,366] ----- Titanium Javascript Runtime Error -----\r\n12-11 19:04:30.728: E/TiExceptionHandler(13828): (main) [0,366] - In alloy/sync/sql.js:11,69\r\n12-11 19:04:30.733: E/TiExceptionHandler(13828): (main) [1,367] - Message: Uncaught TypeError: Cannot call method 'isValidRow' of null\r\n12-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\r\n12-11 19:04:30.733: E/V8Exception(13828): Exception occurred at alloy/sync/sql.js:11: Uncaught TypeError: Cannot call method 'isValidRow' of null\r\n{code} \r\n\r\nDetailed problem:\r\n\r\nhttp://developer.appcelerator.com/question/160374/alloy--migrations---create-new-table-with-migrations", "attachment": [], "flagged": false, "summary": "Create a new table with Alloy and pre-built db", "creator": { "name": "davidbenko", "key": "davidbenko", "displayName": "David Benko", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "davidbenko", "key": "davidbenko", "displayName": "David Benko", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "284365", "author": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Moving this issue to Alloy project based on Tony's recommendation on the Q&A thread.", "updateAuthor": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-15T18:04:55.000+0000", "updated": "2013-12-15T18:04:55.000+0000" }, { "id": "284366", "author": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "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].", "updateAuthor": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-12-15T18:08:14.000+0000", "updated": "2013-12-15T18:08:14.000+0000" }, { "id": "294235", "author": { "name": "ns", "key": "ns", "displayName": "Nils Sdun", "active": true, "timeZone": "Europe/Berlin" }, "body": "Possible Solution:\r\nPlace following code in sql.js in line 271.\r\nIt 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.\r\n\r\n{code:javascript}\r\nif(rs == null) {\r\n var idAttribute = ALLOY_ID_DEFAULT;\r\n if(config.adapter.idAttribute) {\r\n idAttribute = config.adapter.idAttribute; \r\n }\r\n var columns = [];\r\n var found = false;\r\n for (var k in config.columns) { \r\n k === idAttribute && (found = true); \r\n columns.push(k + \" \" + config.columns[k]); \r\n }\r\n found || columns.push(idAttribute + \" TEXT UNIQUE\");\r\n db.execute( 'CREATE TABLE ' + table + ' (' + columns.join(\", \") + ');' );\r\n var rs = db.execute('pragma table_info(\"' + table + '\");'); \r\n}\r\n{code}", "updateAuthor": { "name": "ns", "key": "ns", "displayName": "Nils Sdun", "active": true, "timeZone": "Europe/Berlin" }, "created": "2014-02-22T00:56:41.000+0000", "updated": "2014-02-22T00:56:41.000+0000" }, { "id": "297252", "author": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "body": "PR https://github.com/appcelerator/alloy/pull/347\n\nTest app included: test/apps/testing/ALOY-900\n\nThis change adds support for a few scenarios: \n\n* Existing model, which points to an external database, with a migration file used to define a new table in that database\n* Existing external database, add a new table by simply defining a new model file and instantiating it in a controller, no migration needed\n* Alloy-created database, add a new table by simply defining a new model file and instantiating it in a controller, no migration needed\n\nFunctional test:\n\n1. Run the test app in the iOS simulator\n2. Open ~/Library/Application Support/iPhone Simulator/VERSION/GUID/Library/Private Documents folder to find the generated sqlite database file\n3. 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\n4. Delete the app from the simulator\n5. Rename the migrations folder or delete it so that it's not used\n6. Repeat steps 1-3, this time the database's table structure will match the table definition in the models/weather.js file\n7. Delete the app from the simulator\n8. Edit the models/weather.js file to remove the db_file property from the adapter config.\n9. Repeat steps 1-3 to create the standard _alloy_.sql file. It will contain the tables as defined in the model", "updateAuthor": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "created": "2014-03-14T15:34:18.000+0000", "updated": "2014-03-14T15:34:18.000+0000" }, { "id": "297266", "author": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "body": "Sorry, not supposed to Resolve till the PR is merged.", "updateAuthor": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "created": "2014-03-14T17:11:29.000+0000", "updated": "2014-03-14T17:11:29.000+0000" }, { "id": "301098", "author": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "body": "PR merged", "updateAuthor": { "name": "skypanther", "key": "skypanther", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/New_York" }, "created": "2014-04-16T14:49:38.000+0000", "updated": "2014-04-16T14:49:38.000+0000" }, { "id": "305178", "author": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Ran through the functional test steps mentioned by [~skypanther]. All steps worked as expected.\r\n\r\nClosing.\r\n\r\nEnvironment:\r\nAppc Studio : 3.3.0.201405121247\r\nTi SDK : 3.3.0.v20140514163013\r\nMac OSX : 10.8.5\r\nAlloy : 1.4.0-alpha\r\nCLI - 3.3.0-dev\r\niPhone simulator : 7.1 64-bit", "updateAuthor": { "name": "lchoudhary", "key": "lchoudhary", "displayName": "Lokesh Choudhary", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-05-15T21:03:03.000+0000", "updated": "2014-05-15T21:03:03.000+0000" } ], "maxResults": 7, "total": 7, "startAt": 0 } } }