{ "id": "107642", "key": "ALOY-453", "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": "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:04:56.000+0000", "created": "2013-01-09T15:37:09.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "GA-candidate", "notable" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-03-07T22:26:00.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": "When constructing a sql database from a series of migrations with no special parameters, we should assume that the latest migration is our target. With the latest migration as the target, we should call the up() function on all migrations before it (including the latest), starting with the last migration that has been executed in the app. down() functions should not be called unless a developer is rolling back a migration to an earlier one, for which we don't really have a method to do so yet anyway. This is not how it working right now in the sql adapter. \r\n\r\nThe basic flow of applying migrations should be as follows:\r\n\r\nh3. Standard application flow, no explicit migration version specified\r\n# Get the \"last migration\" executed, which should be saved. Now it is being saved in the sqlite database, but if it doesn't exist it should be assumed that the first migration is the starting point.\r\n# Execute, in order, the up() function of all migrations from the starting migration to the latest migration.\r\n# Update the \"last migration\" in the sqlite database.\r\n\r\nWe should also add a way for developers to specify a specific migration to which they want their app to conform. We should add a parameter to the model config that allows them to pick that version:\r\n\r\n{code:javascript}\r\nexports.definition = {\r\n\tconfig: {\r\n\t\t\"columns\": {\r\n\t\t\t\"name\":\"text\",\r\n\t\t\t\"nickname\":\"text\"\r\n\t\t},\r\n\t\t\"adapter\": {\r\n\t\t\t\"type\": \"sql\",\r\n\t\t\t\"collection_name\": \"fighters\",\r\n\r\n // this field determines whether the database is up to date,\r\n // or if it requires an upgrade or rollback\r\n \"migration\": \"201209301904312\"\r\n\t\t}\r\n\t}\r\n}\r\n{code}\r\n\r\nNotice the new migration field in \"adapter\". This tells the app which migration to conform to. The following shows the flow for upgrading and downgrading based on this version number.\r\n\r\nh3. config version same as \"last\" version\r\n* Do nothing\r\n\r\nh3. config version is greater than \"last\" version\r\n* Execute all up() functions, in order, on migrations greater than the \"last\" version and less than or equal to the config version\r\n\r\nh3. config version is less than \"last\" version\r\n* Execute all down() functions, in reverse order, on migrations greater than config version and less than or equal to the \"last\" version ", "attachment": [], "flagged": false, "summary": "Fully support up and down migrations in sql adapter", "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": "234862", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Migrations testable up and down in: \r\n\r\n* https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_keywords\r\n* https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_preload\r\n* 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:04:56.000+0000", "updated": "2013-01-17T20:04:56.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }