Skip to content

Commit

Permalink
flyway sample
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro23 committed Apr 4, 2017
1 parent 9a77257 commit c4063c9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Expand Up @@ -43,6 +43,8 @@ dependencies {
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

compile "org.flywaydb:flyway-core:4.1.2"
}

bootRun {
Expand Down
8 changes: 7 additions & 1 deletion grails-app/conf/application.yml
Expand Up @@ -103,10 +103,16 @@ dataSource:
username: sa
password:

flyway:
enabled: true
locations: classpath:db/migration
sql-migration-prefix: V
sql-migration-suffix: .sql

environments:
development:
dataSource:
dbCreate: create-drop
dbCreate: none
url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
Expand Down
2 changes: 2 additions & 0 deletions grails-app/init/myapp/Application.groovy
Expand Up @@ -2,7 +2,9 @@ package myapp

import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
import org.springframework.context.annotation.ComponentScan

@ComponentScan
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
Expand Down
22 changes: 22 additions & 0 deletions grails-app/init/myapp/FlywayConfig.groovy
@@ -0,0 +1,22 @@
package myapp

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.flyway.FlywayDataSource
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

import javax.sql.DataSource

@Configuration
class FlywayConfig {

@Autowired
DataSource dataSource

@Bean
@FlywayDataSource
DataSource flywayDataSource() {
return dataSource
}

}
1 change: 1 addition & 0 deletions src/main/resources/db/migration/V1__create_tables.sql
@@ -0,0 +1 @@
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));

0 comments on commit c4063c9

Please sign in to comment.