对我们而言,可持续和平消除了不确定性。 在这种情况下,由于数据库更改而引起的想法是欢迎进行Ruby的Active Record迁移 。

迁移对我们意味着什么? 嗯,这是一种方便快捷的方法,可以以一致且简单的方式来改变我们的数据库架构,从而消除了软件开发过程中有关数据库更改的许多不确定性。

目标

我们的目标是根据项目的发展和演变,保持对数据库的生命周期,并对更改进行绝对控制。

为此,我们必须寻找一种具有以下基本特征的简单工具:

  • 尽管现在我们的数据库是MySQL,但可以与任何数据库一起使用。
  • 使并发开发人员能够独立工作。
  • 启用不同的开发环境。
  • 能够与任何版本控制系统集成。
  • 能够轻松地将迁移任务集成到Apache Ant中。
  • 允许向前和向后迁移以及容易管理的冲突。

我们选择MyBatis Migrations工具作为最适合我们的解决方案,并选择GitHub存储库Ant脚本以将MyBatis Migrations的命令作为起点运行。

让我们说到重点:我们如何进行迁移

使用这些工具,我们认为迁移的生命周期可能像这样

第一次

  • 在我们的项目目录中创建一个迁移目录。
  • 下载MyBatis Schema迁移文件mybatis-migrations-3.1.1-bundle.zip 。
  • 创建一个lib目录并复制mybatis-3.2.3.jarmybatis-3.2.3.jar mybatis-migrations-3.1.1.jar文件。
  • 从mybatis-migrations-anttasks-master.zip下载Ant任务的build.propertiesbuild.xml文件,并将其重命名为migrations.properties/xml,以实现更清晰的目标。
  • 显然,此文件定义了迁移工具的ant任务和基本属性,而migrations.properties (包含注释以明确说明)定义了
    # Default environment
    mybatis.default.environment=developmentmybatis.dir=migrations
    mybatis.lib.dir=${mybatis.dir}/libmybatis.repository.dir=${mybatis.dir}/db# 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.
    mybatis.scripts.dir=${mybatis.repository.dir}/scripts# Place your JDBC driver .jar or .zip files in this directory.
    # Upon running a migration, the drivers will be dynamically loaded.
    mybatis.drivers.dir=${mybatis.repository.dir}/drivers# In the environments folder you will find .properties files that
    # represent your database instances. By default a development.properties
    # file is created for you to configure your development time database
    # properties.
    # You can also create test.properties and production.properties
    # files. The properties file is self documented.
    mybatis.env.dir=${mybatis.repository.dir}/environments

    migrations.xml定义了ant任务,您可以在原始文档中看到。 当然,您必须将其重命名为xml文件描述符属性才能加载它

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="MyBatis Migrations" basedir="." default="db:migrate:status"><property file="migrations/migrations.properties" />.....
    </project>
  • 但是, 如何安装 ……很容易,基本上我们必须执行以下操作:
    $ ant -f migrations.xml db:migrate:init

    如在此输出日志中看到的,它将创建目录和初始文件,如在migrations.properties中定义的一样。

    Buildfile: /wpr/myproject/migrations/migrations.xmldb:migrate:init:[echo] ** Executing "migrate init" on "development" environment **-------------------------------------------------------------- MyBatis Migrations - init------------------------------------------------------------Initializing: dbCreating: environmentsCreating: scriptsCreating: driversCreating: READMECreating: development.propertiesCreating: bootstrap.sqlCreating: 20131123174059_create_changelog.sqlCreating: 20131123174100_first_migration.sqlDone!-------------------------------------------------------------- MyBatis Migrations SUCCESS-- Total time: 2s-- Finished at: Sat Nov 23 18:41:00 CET 2013-- Final Memory: 1M/117M------------------------------------------------------------.BUILD SUCCESSFUL
    Total time: 3 seconds

    • 环境脚本驱动程序是目录(如前所述)。
  • 保留开发环境的migrations / db / environment / development.properties数据库属性
    ## JDBC connection properties.
    driver=com.mysql.jdbc.Driver
    url=jdbc:mysql://localhost:3306/<databaseName>
    username=root
    password=root
  • 如果需要,将其他环境属性文件添加到每个migrations / db / environment / <environment> .properties
  • 最后一步,将实际的数据库架构放入bootstrap.sql文件中。

日复一日

在我们通常使用的所有迁移命令中

  • 使用db:migrate:new创建一个或多个迁移。
  • 通过db:migrate:up将迁移应用于数据库。

可选步骤包括:

  • 如果需要解决冲突,请还原迁移。 使用db:migrate:down ..可以轻松解决任何错误,但是请记住,仅一步之遥
  • 如果可以安全地使用db:migrate:pending或db:migrate:version来应用挂起的迁移,请按顺序进行。 实际上,如果要执行这些任务,则必须将代码添加到migrations.xml中
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="MyBatis Migrations" basedir="." default="db:migrate:status">
    ....<!-- $ migrate pending --><target name="db:migrate:pending" description="Runs all pending migrations regardless of their order or position in the status log"><migrate command="pending" environment="${environment}" /></target><!-- $ migrate version --><target name="db:migrate:version" description="Migrate the schema to any specific version"><input addproperty="specific.version" message="Specific version to migrate:" /><migrate command="version" environment="${environment}"><extraarguments><arg value="${specific.version}" /></extraarguments></migrate></target></project>
  • 生成迁移脚本以在无法控制的环境中“脱机”运行 。
  • 随时通过db:migrate:status获取系统状态 。

希望您发现我们的解决方案有用,欢迎所有评论和对我的英语致歉。

参考: TODOdev博客上的JCG合作伙伴 Sergio Molina将数据库更改转换为Java环境实现了可持续和平 。

翻译自: https://www.javacodegeeks.com/2014/01/sustainable-peace-with-database-changes-into-a-java-environment.html

数据库更改到Java环境中实现可持续和平相关推荐

  1. java实现数据库内容修改_数据库更改到Java环境中实现可持续和平

    java实现数据库内容修改 对我们而言,可持续和平正在消除不确定性. 在这种情况下,由于数据库更改,欢迎使用Ruby的Active Record Migrations . 迁移对我们意味着什么? 嗯, ...

  2. 服务数据对象简介(Java 环境中的下一代数据编程)

    如果您认为 J2EE 编程模型和 API 迫使开发人员在特定于技术的配置.编程和调试上浪费了太多的时间,那么欢迎您阅读本文.很多 Java™ 开发人员都怀疑如何能以统一的方式访问异构的数据,并对各种提 ...

  3. java class 静态模块_Java API 最佳设计实践:在模块化和非模块化 Java 环境中使用...

    了解在设计 Java API 时应该运用的一些 API 设计实践.这些实践通常很有用,而且可确保 API 能在诸如 OSGi 和 Java Platform Module System (JPMS) ...

  4. 巨杉数据库SequoiaDB在Java开发中的增删改查CURD

    文章目录 JSON应用开发 增删改查操作 1 快速入门 1.1 环境部署 部署SequoiaDB集群环境 部署Windows开发环境 1.2 正式开始 2 CURD教程 2.1 Java开发环境搭建 ...

  5. gdal在java环境中读取mif/mid文件以及写入数据

    目录 1.maven项目搭建的gdal环境 2.maven项目搭建后开始代码 3.怎么提取两个Layer中某个字段相同的所有数据(这个并非是取属性交集)? 1.maven项目搭建的gdal环境 引入g ...

  6. 数据库数据显示在java表中_实现 从数据库读取数据显示在前台echarts图表里,图表可根据数据库数据实时更新。效果如图...

    实现 从数据库读取数据显示在前台echarts图表里,图表可根据数据库数据实时更新.效果如图 实现步骤 - 1.创建数据表 - 2.建立Java Web Project - 3.创建Bean对象 - ...

  7. 从内存溢出看Java 环境中的内存结构

    作为有个java程序员,我想大家对下面出现的这几个场景并不陌生,倍感亲切,深恶痛绝,抓心挠肝,一定会回过头来问为什么为什么为什么会这样,嘿嘿,让我们看一下我们日常在开发过程中接触内存溢出的异常: Ex ...

  8. mongodb3.2 java,MongoDB学习笔记:(3)、mongodb 3.2在java环境中的简单CRUD

    首先新建一个java project项目,去下载mongo-java-driver-3.2.2.jar包.build path导入junit需要的jar包.另外运行代码前先要启动mongod 服务.下 ...

  9. 生产环境中,RabbitMQ 持续积压消息不进行ack ,发生什么了?

    问题:生产环境 rabbitmq 部分客户端 channel 持续积压消息不进行ack. 0. 服务配置 rabbitmq 集群(普通集群模式) 消费者 三台 消费线程各消费者 10 消费者配置 使用 ...

最新文章

  1. mysql优化 top_Top 20+ MySQL Best Practices【sql优化】
  2. plotly使用mapbox实现地图可视化
  3. 关于UI Automation框架
  4. liteos内核驱动和linux,移植RTOS必备基础知识
  5. openvino安装小记
  6. asp.net ReportViewer 设置 rdlc textbox的值
  7. js 和 css动画
  8. Common Techniques to Improve Shadow Depth Maps
  9. lnk2019 mysql_C++使用MySQL-Connector/C++连接MySQL出现LNK2019错误的解决方法
  10. 这个冬天,我以《监控》下酒
  11. Linux如何动态查看文件信息,怎么查看linux动态链接库文件的版本等其他信息
  12. 关于交流电路的谐振等问题
  13. [2018.08.02 T1] 第一题
  14. 天猫魔盘在 deepin-linux中的使用
  15. ARP协议报文格式及ARP表简述
  16. ildasm、ilasm修改、反编译 已经编译的 dll文件(c#)
  17. linux查看redis链接数,查看redis连接数
  18. python是什么和c++是什么区别_编程c++和python的区别
  19. 倡导国稻种芯·中国水稻节 万祥军:农民丰收节金秋消费季
  20. 如何设计一个网页爬虫

热门文章

  1. Android中ImageView的旋转与缩放
  2. 我的控制反转,依赖注入和面向切面编程的理解
  3. javafx 调用java_Java,JavaFX的流畅设计风格滑块
  4. 净资产滚动率_净资产的结构
  5. javafx ui_调用以验证JavaFX UI的响应能力
  6. 空字符串字符串不为空_当字符串为空但不为空时
  7. aop 获取注解注释的方法_带有AOP和注释的Java方法记录
  8. Java XMPP负载测试工具
  9. TellDontAsk的扩展
  10. Java应用程序中的验证