Created
April 5, 2014 12:47
-
-
Save emilsjolander/9991512 to your computer and use it in GitHub Desktop.
Sprinkles new migration system
This file contains 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
/* | |
pros: | |
- Simple and little code | |
cons: | |
- What happens when an @Check annotation is removed form Note.class model? | |
Not intuitive that that column will be dropped and recreated | |
*/ | |
void onCreate() { | |
Sprinkles s = Sprinkles.init(this); | |
s.registerModel(Note.class) | |
} | |
/* | |
pros: | |
- No suprises | |
cons: | |
- Some duplication of code as the column name and type is declared in the model class | |
*/ | |
void onCreate() { | |
Sprinkles s = Sprinkles.init(this); | |
s.migrate(Migration.createTable("Notes", | |
new Migrator() { | |
void onMigrate(CreateTableMigration m) { | |
m.addColumn("id", long.class).constraints(Constraint.primaryKey(), Constraint.autoincrement()); | |
m.addColumn("title", String.class).constraints(Constraint.notNull()); | |
m.addColumn("color", Color.class) | |
m.addColumn("tag_id", long.class).constraints(Constraint.foriegnKey("Tags","id")) | |
} | |
} | |
)); | |
} |
yes
The model will only act as a mapping against the underlying columns
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does #2 mean that we have to specify our columns both in the class that extends
Model
, as well as inonMigrate()
?