日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

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

發布時間:2023/12/3 java 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据库更改到Java环境中实现可持续和平 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對我們而言,可持續和平消除了不確定性。 在這種情況下,由于數據庫更改而引起的想法是歡迎進行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.jar和mybatis-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环境中实现可持续和平的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。