日期:2014-05-16  浏览次数:20675 次

maven数据库处理插件db-migration-maven-plugin

配置repository:

    <pluginRepositories>
        <pluginRepository>
            <id>c5-public-repository</id>
            <url>http://mvn.carbonfive.com/public</url>
        </pluginRepository>
    </pluginRepositories>

?

配置plugin:

            <plugin>
                <groupId>com.carbonfive.db-support</groupId>
                <artifactId>db-migration-maven-plugin</artifactId>
                <version>0.9.9-m5</version>

                <configuration>
                    <url>jdbc:mysql://localhost:3306/everest</url>
                    <username>root</username>
                    <password>root</password>
                    <migrationsPath>file:src/main/db/migrations/*.sql</migrationsPath>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.6</version>
                    </dependency>
                </dependencies>
            </plugin>

?

将你的数据库删除、创建及初始化语句放在src/main/db/migrations目录下即可。

?

需要重设数据库时只需要执行mvn db-migration:reset即可

?

更多命令请参考: http://code.google.com/p/c5-db-migration/wiki/MavenPlugin