Created
May 11, 2014 13:31
-
-
Save geovanisouza92/91122ff3eb7d12d693f9 to your computer and use it in GitHub Desktop.
Database migration for Android/SQLite
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
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