{ "id": "108020", "key": "ALOY-468", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [ { "id": "14771", "description": "Alloy 0.3.5", "name": "Alloy 0.3.5", "archived": false, "released": true, "releaseDate": "2013-01-18" }, { "id": "14871", "description": "2013 Sprint 02", "name": "2013 Sprint 02", "archived": true, "released": true, "releaseDate": "2013-01-28" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-01-17T20:08:18.000+0000", "created": "2013-01-17T08:56:14.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-03-07T22:25:52.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "12329", "name": "Runtime", "description": "Generic bucket for uncategorized runtime issues" } ], "description": "h2. description\r\n\r\nThe sql adapter has the createTable() and dropTable() functions for, well, creating and deleting tables in migrations. To assist in adding and deleting rows, we should also have insertRow() and deleteRow() function.\r\n\r\ninsertRow() will take a single parameter which is an object that defines the name and values of columns to add. This is the same exact form as the *columns* object in the model definition. deleteRow() will also take a single object. This object will include a list of columns (keys) and corresponding values (values) that will be used in the where clause of the delete that alloy performs. \r\n\r\nThese are simple, shorthand functions. More complex inserts and deletes can be done using the Titanium.Database API.\r\n\r\nh2. example usage\r\n\r\n{code:javascript}\r\nvar rows = [\r\n { firstname: 'tony', lastname: 'lukasavage' },\r\n { firstname: 'chris', lastname: 'barber' },\r\n { firstname: 'bryan', lastname: 'hughes' }\r\n];\r\n\r\nmigration.up = function(migrationObj) {\r\n for (var i = 0; i < rows.length; i++) {\r\n // will insert the given rows\r\n migrationObj.insertRow(rows[i]); \r\n }\r\n}\r\n\r\nmigration.down = function(migrationObj) {\r\n for (var i = 0; i < rows.length; i++) {\r\n // Will delete from the model's table using the given object\r\n // to construct the delete query. For example, assuming the\r\n // table name is 'myTable', the query generated for the \r\n // first object would be:\r\n //\r\n // DELETE FROM myTable WHERE firstname ='tony' AND lastname = 'lukasavage'; \r\n migrationObj.deleteRow(rows[i]); \r\n }\r\n}\r\n{code}\r\n\r\nh2. notes\r\n\r\n* If no columns are given to deleteRow(), all rows will be deleted\r\n* If an up() and down() migration plan to add and remove rows respectively, developers may want to insert their rows' unique ids explicitly, even if they are autoincrement. This will ensure that when the deleteRow() is called in the down(), it will delete the correct, unique row based on the id. This is really only relevant in the case where there are legit reasons for having duplicates in your table.", "attachment": [], "flagged": false, "summary": "add insertRow() and deleteRow() function in sql migrations", "creator": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "234866", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "used in test app: https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_queries", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-01-17T20:08:18.000+0000", "updated": "2013-01-17T20:08:18.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }