Created
August 16, 2012 12:48
-
-
Save jrdalpra/3369883 to your computer and use it in GitHub Desktop.
Migration for Java - Ideas
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
import static test.DataBaseField.DataBaseTypes.LONG; | |
import static test.DataBaseField.DataBaseTypes.STRING; | |
import static test.DatabaseCommands.createSequence; | |
import static test.DatabaseCommands.createTable; | |
import static test.DatabaseCommands.dropSequence; | |
import static test.DatabaseCommands.dropTable; | |
import static test.DatabaseCommands.sql; | |
import lombok.experimental.ExtensionMethod; | |
import test.DatabaseCommand; | |
import test.Migration; | |
// @ManagedBean <-- usar com CDI | |
// @Enviroment(Enviroments.TEST) <-- definir migrations que devem ser executadas apenas em alguns ambientes | |
@ExtensionMethod({ Migrations.Language.class }) | |
public class CriaUsuarios_16082012_084830_jrdalpra implements Migration { | |
@Override | |
public DatabaseCommand[] up() { | |
return new DatabaseCommand[] { | |
createSequence(SEQ_USUARIOS()).startWith(2).incrementBy(1), | |
createTable(USUARIO()).columns("id".as(LONG).primary("pk_usuario"), | |
"login".as(STRING).length(255).unique("uk_usuario_login"), | |
"senha".as(STRING).length(20)), | |
sql(INSERT_USUARIO()).set(1, 1).set(2, "admin").set(3, "admin") | |
}; | |
} | |
@Override | |
public DatabaseCommand[] down() { | |
return new DatabaseCommand[] { | |
dropTable(USUARIO()), | |
dropSequence(SEQ_USUARIOS()) | |
}; | |
} | |
private String USUARIO() { | |
return "usuario"; | |
} | |
private String SEQ_USUARIOS() { | |
return "SEQ_USUARIO"; | |
} | |
private String INSERT_USUARIO() { | |
return "insert into usuario (id,login,senha) values (?,?,?)"; | |
} | |
} |
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
import test.DataBaseField; | |
public class Migrations { | |
public static class Language { | |
public static DataBaseField as(String name, DataBaseField.DataBaseTypes type) { | |
return new DataBaseField(name).as(type); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment