Created
April 5, 2014 13:14
-
-
Save emilsjolander/9991770 to your computer and use it in GitHub Desktop.
pre and post migration callbacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void onCreate() { | |
| Sprinkles s = Sprinkles.init(this); | |
| s.migrate( | |
| new Migration() { | |
| void onPreMigrate() { | |
| // TODO query data in id column | |
| } | |
| void migrate() { | |
| Table table = createTable("Notes") | |
| table.addColumn("id", long.class).constraints(Constraint.primaryKey(), Constraint.autoincrement()); | |
| table.addColumn("title", String.class).constraints(Constraint.notNull()); | |
| table.addColumn("tag_id", long.class).constraints(Constraint.foriegnKey("Tags","id")); | |
| addIndex("TitleIndex", true, "Notes", "title") | |
| Table table = alterTable("Notes") | |
| table.addColumn("color", Color.class); | |
| } | |
| void onPostMigrate() { | |
| // TODO re-add data into id column | |
| } | |
| } | |
| )); | |
| } | |
| void onCreate() { | |
| Sprinkles s = Sprinkles.init(this); | |
| s.migrate( | |
| new Migration() { | |
| void onPreMigrate() { | |
| // TODO query data in id column | |
| } | |
| void migrate(SQLiteDatabase db) { | |
| db.execSql( | |
| "CREATE TABLE Notes ("+ | |
| "id INTEGER AUTOINCREMENT PRIMARY KEY,"+ | |
| "title TEXT,"+ | |
| "tag_id INTEGER FORIEGN KEY Tags(id),"+ | |
| "color INTEGER"+ | |
| ");"); | |
| } | |
| void onPostMigrate() { | |
| // TODO re-add data into id column | |
| } | |
| } | |
| )); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment