Alloy Framework: Database Migration

You must Login before you can answer or comment on any questions.

Hi,

Can anyone have an example to use database migration. For example the first version looks like this

config: {
        "columns": {
            "name":"string",
            "contact":"string"
        },
        "adapter": {
            "type": "sql",
            "collection_name": "Sample"
        }
    },
and the second version looks like this.
config: {
        "columns": {
            "name":"string",
            "contact":"string",
            "message:"string"
        },
        "adapter": {
            "type": "sql",
            "collection_name": "Sample"
        }
    },
How can I do a migration so that the data in the first version would be copied into the second version before dropping the entire table and recreating it? Does alloy automatically perform this task? if not where should I place my codes? Can anyone post a sample code.

Thanks!!!

1 Answer

http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Sync_Adapters_and_Migrations

Look there, near the bottom.

— answered 4 months ago by Mark Gerecht
answer permalink
2 Comments
  • This is causing an error for me. My newer-version Model has a new field "directions" and I created a migration like this:

    migration.up = function(migrator) {
        migrator.db.execute('ALTER TABLE ' + migrator.table + ' ADD COLUMN directions TEXT;');
    };
    // is migration.down required?
    When I clean/build, the following error happens when the app tries to migrate before creating my "sql" adapter database.
    [ERROR] A SQLite database error occurred on database '/Users/joebeuckman/Library/Application Support/iPhone Simulator/6.1/Applications/471CE5BA-4F51-47C5-9A7F-40E093CE47E0/Library/Private Documents/_alloy_.sql': Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0xa778c90 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=ALTER TABLE BusStops ADD COLUMN directions TEXT;, com.plausiblelabs.pldatabase.error.vendor.string=no such table: BusStops} (SQLite #1: no such table: BusStops) (query: 'ALTER TABLE BusStops ADD COLUMN directions TEXT;')

    — commented 5 weeks ago by Joseph Beuckman

  • Also, a note about the Migration documentation: the example date uses 77 seconds in the datestamp.

    — commented 5 weeks ago by Joseph Beuckman

Your Answer

Think you can help? Login to answer this question!