在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):marceloemanoel/gradle-migrations-plugin开源软件地址(OpenSource Url):https://github.com/marceloemanoel/gradle-migrations-plugin开源编程语言(OpenSource Language):Groovy 74.0%开源软件介绍(OpenSource Introduction):Gradle Migrations PluginProvide gradle build integration with mybatis migrations. The plugin adds a group of tasks named Migrations composed by:
InstallJust put the following code snippet in your build.gradle file. buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "com.github.marceloemanoel:gradle-migrations:0.2.1"
}
}
apply plugin: "migrations" ConfigurationsThe only required configuration is made on your scripts dependencies section.
The plugin add a configuration scope known as To use the migrations with a mysql database for example, one should instruct the build as following: dependencies {
migrationsDriver 'mysql:mysql-connector-java:5+'
} This will ensure that the last mysql connector will be downloaded when you first run any migration task, it will be cached by gradle and on later calls it will be used from the local repository. CustomizationFollowing the rule of convention over configuration the plugin adds a configuration closure to your build.
If all default values are good for you, you're ready to go. But if you need to change anything, you'll see that
it is an easy task. You only need to write the following on your migrations {
baseDir = "anotherDirectory"
environment = "test"
force = true
} All values are optional. The following table presents the default values of each property:
Available TasksmigrateInitThe init command initializes a new repository’ of migration scripts. You’ll run init once to create the
workspace in which everything you need to manage database change will be placed. Running this
command will create the directory specified by the When the command is completed, the directory will contain the following sub-directories:
In the environments folder you will find .properties files that represent your database instances. By
default a
This directory contains your migration SQL files. These are the files that contain your DDL to both upgrade and downgrade your database structure. By default, the directory will contain the script to create the changelog table, plus one empty example migration script. To create a new migration script, use the migrateNew command. To run all pending migrations in order, use the migrateUp command. To undo the last migration applied, use the migrateDown command etc. migrateBootstrapThe bootstrap command enables the starting point for migrations if you’re working from an existing database.
There’s no point in trying to rewind time and shoehorn your existing database into a series of migration scripts.
It’s more practical to just accept the current state of your database schema and identify this as the starting point.
In the scripts directory you’ll find a file named In order to run, the migrateBootstrap command need the JDBC driver of your database.
The plugin add the configuration migrateStatusThe status command will report the current state of the database. :migrateStatus ID Applied At Description ================================================================================ 20130314124532 ...pending... create changelog 20130314124533 ...pending... first migration migrateNewThis task enable the creation of new migrations. Every migration script file should have a .sql extension and have both sections DO and UNDO. As soon you init the migrations repository two files are created for you, the changelog migration and the first migration. The changelog migration contains the following code: --// Create Changelog
-- Default DDL for changelog table that will keep
-- a record of the migrations that have been run.
-- You can modify this to suit your database before
-- running your first migration.
-- Be sure that ID and DESCRIPTION fields exist in
-- BigInteger and String compatible fields respectively.
CREATE TABLE ${changelog} (
ID NUMERIC(20,0) NOT NULL,
APPLIED_AT VARCHAR(25) NOT NULL,
DESCRIPTION VARCHAR(255) NOT NULL
);
ALTER TABLE ${changelog}
ADD CONSTRAINT PK_${changelog}
PRIMARY KEY (id);
--//@UNDO
DROP TABLE ${changelog}; This file is composed of three sections:
--// Create Changelog
-- Default DDL for changelog table that will keep
-- a record of the migrations that have been run.
-- You can modify this to suit your database before
-- running your first migration.
-- Be sure that ID and DESCRIPTION fields exist in
-- BigInteger and String compatible fields respectively.
CREATE TABLE ${changelog} (
ID NUMERIC(20,0) NOT NULL,
APPLIED_AT VARCHAR(25) NOT NULL,
DESCRIPTION VARCHAR(255) NOT NULL
);
ALTER TABLE ${changelog}
ADD CONSTRAINT PK_${changelog}
PRIMARY KEY (id);
DROP TABLE ${changelog}; The migrateNew task needs one parameter to work as expected, the description of what this migration will do to your database. It is used like this:
This parameter can be abreviated as simple as this:
migrateUp and migrateDownTheses tasks enable the evolving and devolving of your database. They use the script files inside the scripts directory. The task Both tasks have a parameter named
or
It is possible to abreviate it like this:
or
LicenseCopyright 2012 Marcelo Emanoel B. Diniz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. DevelopersContributionsJust fork the project and send a pull request :D |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论