[ALOY-453] Fully support up and down migrations in sql adapter
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2013-01-17T20:04:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 0.3.5, 2013 Sprint 02 |
Components | Runtime |
Labels | GA-candidate, notable |
Reporter | Tony Lukasavage |
Assignee | Unknown |
Created | 2013-01-09T15:37:09.000+0000 |
Updated | 2018-03-07T22:26:00.000+0000 |
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.
The basic flow of applying migrations should be as follows:
Standard application flow, no explicit migration version specified
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.
Execute, in order, the up() function of all migrations from the starting migration to the latest migration.
Update the "last migration" in the sqlite database.
We 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:
exports.definition = {
config: {
"columns": {
"name":"text",
"nickname":"text"
},
"adapter": {
"type": "sql",
"collection_name": "fighters",
// this field determines whether the database is up to date,
// or if it requires an upgrade or rollback
"migration": "201209301904312"
}
}
}
Notice 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.
Migrations testable up and down in: * https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_keywords * https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_preload * https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_queries