私は http://grails-plugins.github.io/grails-database-migration/3.0.x/index.html#introduction杯データ移行プラグイン
まず、このリンクからの指示に従っ私はapplication.ymlに必要な行を追加しました:
buildscript {
dependencies {
...
classpath 'org.grails.plugins:database-migration:3.0.0'
}
}
dependencies {
...
compile 'org.grails.plugins:database-migration:3.0.0'
compile 'org.liquibase:liquibase-core:3.5.3'
}
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
は、それから私は、GrailsののDBM-生成・更新履歴」を実行changelog.groovy」その後 "のGrails DBM-changelogの同期" それから私はchangelog.groovyファイルにビューを追加しました:
databaseChangeLog = {
changeSet(author: "xxx (generated)", id: "1490002519504-99", contexts: 'Test') {
createView("""
SELECT dbo.Client.ClientNo, dbo.Client.ClientName
FROM dbo.Client INNER JOIN
dbo.ClientRole ON dbo.Client.ClientNo = dbo.ClientRole.ClientNo AND dbo.ClientRole.RoleType = 2
""", viewName: 'dbo.vw_supplier'
)
}
changeSet(author: "xxx (generated)", id: "1490002519504-1", contexts: 'Test') {
createTable(tableName: "orders") {
column(autoIncrement: "true", name: "id", type: "bigint") {
constraints(primaryKey: "true", primaryKeyName: "PK__orders__3213E83F6FCA6F65")
}
私はapplication.groovyに以下の行を追加しました:いくつかの試行後
grails.plugin.databasemigration.updateOnStartFilename = 'changelog.groovy'
grails.plugin.databasemigration.updateOnStart = true
grails.plugin.databasemigration.updateOnStartContexts = ['Test']
を私は「文脈」を使用しないように、最後の行をコメントしたが、それは何も変わっていませんでした。
また、開発用のブートストラップでcreate-dropをnoneに変更しました。 データベースからすべてのテーブルを削除して、 "grails dbm-update"を実行しました その後、 "changelog.groovy"に追加したビューは表示されませんが、すべてのテーブルが作成されます。 テーブルはすべて列なしで作成されました。
"INFO 2017-03-20 12:54: liquibase: Can not use class org.grails.plugins.databasemigration.liquibase.GormDatabase as a Liquibase service because it does not have a no-argument constructor"
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.11.6"
classpath "org.grails.plugins:hibernate5:6.0.4"
classpath 'org.grails.plugins:database-migration:3.0.0'
}
}
私のプロジェクトは現在、完全に失速: は、私はまた奇妙なメッセージを受け取りました。
なぜあなたは 'grails.plugin.databasemigration.updateOnStartContextsは= [「テスト」]'マイグレーションのみテストコンテキストで実行するかを追加しましたか? – dynamo
ダイナモがない場合、この単語「Test」はどの単語でもかまいませんが、開始時にどのChangeSetを更新するかを選択するだけです。 changeSetを見ると、 'Test'とマークされていますが、最初に更新したくない他のテーブルが別のchangeSetにあります。 – larand
createViewのコードはネット上のチュートリアルからコピーされたので、私はそのことにだまされました。ありがとう、ダイナモ私はこのステップを飛び越えました。私がトップになるかどうかがわかります;-) – larand