Skip to content

Instantly share code, notes, and snippets.

@geovanisouza92
Created May 11, 2014 13:31
Show Gist options
  • Save geovanisouza92/91122ff3eb7d12d693f9 to your computer and use it in GitHub Desktop.
Save geovanisouza92/91122ff3eb7d12d693f9 to your computer and use it in GitHub Desktop.
Database migration for Android/SQLite
package ...
import ...
/**
* Created by Geovani on 09/05/2014.
*/
public class M00_Setup implements Migration {
@Override
public void up(DatabaseApi db) {
db.pragma(foreignKeys(), 1 /* Enabled */);
db.pragma(autoVacuum(), 2 /* Incremental */);
db.create(
table("migrations",
column("name", varchar(32), notNull(), unique()))
.withoutRowid()
);
db.create(
table("dummy",
column("_id", long_(), primaryKey()),
column("foo", varchar(32), foreignKey("migrations").on("name")),
column("bar", double_(), notNull()))
);
db.create(
index("idx_1", "dummy", "bar"));
}
@Override
public void down(DatabaseApi db) {
db.drop(table("migrations"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment