Skip to content

Commit

Permalink
Added asciidoc document, trying to create a nice document for migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
ErwinvanBrandwijk committed Apr 1, 2011
1 parent 16516fa commit cde2136
Showing 1 changed file with 126 additions and 0 deletions.
126 changes: 126 additions & 0 deletions migrationsExamples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
== Groovy Liquibase migrations examples

Created by Erwin van Brandwijk

Company http://www.42.nl/[42bv Netherlands]

This document contains all changes from Liquibase that can be executed with Groovy-Liquibase. These are the examples from liquibase.org/manuel. I have converted them to groovy changes. After that I tested them on
PostgreSQL and some on Mysql.

.Example: changelogFile
----
databaseChangeLog() {
// changeSets
}
----

If quotes are empty, you do not have to use that parameter. See example with addColumn - schemaName.
.Example: Add Column
----
changeSet(author: "erwin", id: "1") {
comment("rollback = yes")

addColumn(tableName: "books", schemaName: "") {
column(name: "firstname", type: "varchar(255)")
}
}
----

Could be ...
----
changeSet(author: "erwin", id: "1") {
comment("rollback = yes")

addColumn(tableName: "person") {
column(name: "firstname", type: "varchar(255)")
}
}
----

If the comment tag contains rollback = no, you will have to create your own rollback. You have got two
possibilities. See next example....
.Example: Drop Column with own rollback
----
changeSet(author: "erwin", id: "4") {
comment("rollback = no")

dropColumn(tableName: "Person", columnName: "test")

rollback{
addColumn(tableName: "Person") {
column(name: "test", type: "varchar(255)")
}
//of SQL in rollback
rollback(“””
//SQL QUERY;
“””)
}
----

Do Not use groovy outside a (custom) groovy change, this will always be executed!! Unless you want that.
When using a Boolean or integer, don't use quotes example: nullable: false


.Add column
----
changeSet(author: "erwin", id: "1") {
comment("rollback = yes")

addColumn(tableName: "persons", schemaName: "") {
column(name: "boss", type: "int") {
constraints(nullable: false, foreignKeyName:
"FK_persons_boss_persons_id", references: "persons(id)")
}
}
// possible parameters → Column
// String name, String type, String value, Number valueNumeric, Date valueDate,
// Boolean valueBoolean, String defaultValue, Number defaultValueNumeric,
// Date defaultValueDate, Boolean defaultValueBoolean,
// DatabaseFunction defaultValueComputed, Boolean autoIncrement, String remarks

// possible parameters → Constraints
// Boolean nullable, Boolean primaryKey, String primaryKeyName,
// String primaryKeyTablespace, String references, Boolean unique,
// String uniqueConstraintName, String check, Boolean deleteCascade,
// String foreignKeyName, Boolean initiallyDeferred, Boolean deferrable
}
----


.Rename column
----
changeSet(author: "erwin", id: "1") {
comment("rollback = yes")

renameColumn(tableName: "test", oldColumnName: "testcolumn", schemaName: "",
newColumnName: "testrenamecolumn", columnDataType: "int")
}
----

.Modify datatype
----
changeSet(author: "erwin", id: "1") {
comment("rollback = yes")

modifyDataType(tableName: "test", clumnName: "testcolumn", schemaName: "",
newDataType: "int")
}
----

.Drop column
----
changeSet(author: "erwin", id: "1") {
comment("rollback = no")

dropColumn(tableName: "person", schemaName: "", columnName: "testcolumn")
}
----

.Alter sequence
----
changeSet(author: "erwin", id: "1") {
comment("rollback = no")

alterSequence(sequenceName: "seq_employee_id", incrementBy: "10")
}
----

0 comments on commit cde2136

Please sign in to comment.