Skip to content

Instantly share code, notes, and snippets.

@emilsjolander
Created April 5, 2014 12:47
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save emilsjolander/9991512 to your computer and use it in GitHub Desktop.
Sprinkles new migration system
/*
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"))
}
}
));
}
@karllindmark
Copy link

Does #2 mean that we have to specify our columns both in the class that extends Model, as well as in onMigrate()?

@emilsjolander
Copy link
Author

yes

@emilsjolander
Copy link
Author

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