CN106445618A - Automatic database updating method - Google Patents

Automatic database updating method Download PDF

Info

Publication number
CN106445618A
CN106445618A CN201610903468.0A CN201610903468A CN106445618A CN 106445618 A CN106445618 A CN 106445618A CN 201610903468 A CN201610903468 A CN 201610903468A CN 106445618 A CN106445618 A CN 106445618A
Authority
CN
China
Prior art keywords
database
version
file
system
executed
Prior art date
Application number
CN201610903468.0A
Other languages
Chinese (zh)
Inventor
赵芝明
Original Assignee
成都知道创宇信息技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 成都知道创宇信息技术有限公司 filed Critical 成都知道创宇信息技术有限公司
Priority to CN201610903468.0A priority Critical patent/CN106445618A/en
Publication of CN106445618A publication Critical patent/CN106445618A/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/656Updates while running

Abstract

The invention discloses an automatic database updating method. The automatic database updating method comprises the following steps that a system file version number is recorded in a system file in a source code mode, and a database version number is recorded in a database in an attribute configuration mode; during system starting, the database updating process is executed in a command invoking mode; the system file version number is found in a file lookup file, and then a database is accessed to look up the database version number; after the two version numbers are looked up, the cycling process is executed; after an SQL script is executed, 1 is added to a database version, then cyclic judgment is performed till the database version is greater than a system file version, the cyclic judgment is exited, and the database updating process finishes. The automatic database updating method does not need manual database deployment, the labor cost is reduced, and the database version can be executed each time only needs corresponding SQL script increase and system version update.

Description

一种数据库自动升级方法 One kind of database to automatically upgrade method

技术领域 FIELD

[0001] 本发明涉及数据库维护升级领域,具体涉及一种数据库自动升级方法。 [0001] The present invention relates to the field of database maintenance upgrades, particularly, to a method for automatic upgrade database.

背景技术 Background technique

[0002] 在标准的开发流程中,数据库部署和升级是很多产品和系统必不可少的步骤,但在大部分企业的开发流程中,还是沿用传统的数据库部署流程,这种传统的流程比较依赖人工操作,耗费人力且错误率较高。 [0002] In the standard development process, database deployments and upgrades are a lot of products and systems essential step in the development process but in most enterprises still follow the traditional database deployment process, this process relies more on tradition manual, labor-intensive and high error rates. 例如手动部署,其提供系统部署文档,开发人员详细编写数据库部署的每个步骤,部署或运维人员根据部署文档部署数据库。 Such as a manual deployment, which provides system deployment documentation, developers write in detail each step of database deployment, operation and maintenance personnel deployment or deployment database deployment according to the document. 这种部署方式存在两点不足:I)需要人工干预,遇到文档不清楚的情况部署人员需要咨询开发人员,增加沟通成本。 Two disadvantages of this deployment: I) the need for manual intervention, the deployment encounters a document is not clear who need to consult developers, increased communication costs. 2)人工操作容易造成操作错误,导致数据库表结构发生错误或生产数据被修改。 2) manual operation likely to cause operational errors, leading to an error or the database table structure is modified production data.

[0003] 相关术语 [0003] The term & Related

[0004] SQL:结构化查询语言,用于数据库中的标准数据查询语言 [0004] SQL: Structured Query Language, a standard database query language data

[0005] 数据库执行版本号:SQL脚本执行版本号 [0005] perform database version: SQL script performs a version number

[0006] 数据库版本:记录在数据库中的SQL脚本执行版本 [0006] database version: records in the database execute SQL script version

[0007] 系统版本:记录在系统文件中的SQL脚本执行版本 [0007] System Version: recorded in the system file version of SQL script execution

[0008] MySQL:是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle旗下产品 [0008] MySQL: is a relational database management system, developed by the Swedish company MySQL AB, currently part of Oracle's products

[0009] MongoDB:是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。 [0009] MongoDB: is a product with function between relational databases and non-relational databases, non-relational database functions among the richest and most like a relational database.

发明内容 SUMMARY

[0010] 本发明所要解决的技术问题是提供一种数据库自动升级方法,通过控制数据库的正确部署和升级,只需要在开发过程中对自动化过程进行充分的验证,就可保证后面的数据库部署操作完全自动化,无需人工干预,并保证部署的高正确率。 [0010] The present invention solves the technical problem is to provide an automatic database upgrade method, only by properly controlling the deployment and upgrade of the database in the development process of the full automation of the process of verification, to ensure that the database can later deployment operation fully automated, without human intervention, and to ensure high accuracy deployment.

[0011] 为解决上述技术问题,本发明采用的技术方案是: [0011] To solve the above technical problem, the technical solution adopted by the invention are:

[0012] —种数据库自动升级方法,包括以下步骤: [0012] - Species Database automatic upgrade method, comprising the steps of:

[0013] 步骤1:在系统的文件中通过源代码方式记录一个系统文件版本号,在数据库中通过配置属性的方式记录一个数据库版本号; [0013] Step 1: record a file system by the version number of the source code in the file system, a database record version number by way of configuration properties in a database;

[0014] 步骤2:在系统启动中,通过命令调用的方式执行数据库升级过程; [0014] Step 2: system startup, performing a database upgrade procedure call mode command;

[0015] 步骤3:通过查找文件的方式找到系统文件版本号,并保存为一个本地变量,再连接数据库查找到数据库版本号,保存为第二个本地变量; [0015] Step 3: Find the system by finding the file version number of papers, and saved as a local variable, then connect to the database to find a database version number, save it as a second local variables;

[0016] 步骤4:查找到这两个版本号后,开始执行循环过程,循环判断数据库版本是否小于等于系统文件版本,如果是,则执行对应的数据库SQL文件,执行这些文件升级数据库的功能,包括建表、修改表结构、插入表数据和修改表数据; [0016] Step 4: After finding these two version numbers, begin the cycle, the cycle is determined whether the version of the database file system version or less, and if so, the corresponding SQL database file is executed, to perform the functions of the database upgrade file, including the construction of tables, modified table structure, table data and insertion sheet data modification;

[0017] 步骤5:执行完SQL脚本后,将数据库版本加I,再次进入循环判断,直到数据库版本大于系统文件版本,跳出循环判断,结束数据库升级过程。 [0017] Step 5: After you perform SQL script, plus the version of the database I, enter the circulation judge again until the system is greater than the version of the database file version out of the loop judgment, the end of the database upgrade process.

[0018] 进一步的,在执行SQL脚本的过程中,还包括自动打印出SQL脚本语句,如果执行语句报错,则打印报错信息,并中断升级过程。 [0018] Further, during the execution of SQL script, also includes automatic print out the SQL script statement, the statement is executed if an error, then print an error message and interrupt the upgrade process.

[0019]与现有技术相比,本发明的有益效果是:无需人工部署数据库,减少人力成本,每次有数据库版本要执行只需增加相应的SQL脚本和更新系统版本即可。 [0019] Compared with the prior art, the beneficial effects of the present invention are: no manual database deployment, reduce labor costs, every time a version of the database to be executed by simply adding the appropriate SQL scripts and update the system version.

附图说明 BRIEF DESCRIPTION

[0020]图1是本发明一种数据库自动升级方法具体实例流程示意图。 [0020] FIG. 1 is a database automatically upgrade method of the present invention Specific examples of a schematic flow chart.

具体实施方式 Detailed ways

[0021]下面结合附图和具体实施方式对本发明作进一步详细的说明。 [0021] The present invention will be further described in detail in conjunction with accompanying drawings and specific embodiments. 首先在系统的文件中通过源代码的方式记录一个系统文件版本号,再在数据库中通过配置属性的方式记录一个数据库版本号,最后在系统启动中通过命令调用的方式执行数据库升级过程,保证升级过程会在系统启动时自动执行。 First, the file system is recorded in a system file version number by way of the source code, and then recorded in the database by configuring the property the way a database version number, the last in the system startup in the database upgrade process by way of command invoked to ensure upgrade the process will be executed automatically at system startup.

[0022] 通过查找文件的方式找到系统文件版本号,并保存为一个本地变量,然后再连接数据库查找到数据库版本号,保存为第二个本地变量。 [0022] find a way to find files by file system version number, and save it as a local variable, and then connect to a database lookup database version number, save for the second local variables. 查找到这两个版本号后,开始执行循环过程,循环判断数据库版本是否小于等于系统文件版本,如果是则执行对应的数据库SQL文件,执行这些文件会升级数据库的功能,包括建表、修改表结构、插入表数据、修改表数据等功能。 After finding the two version numbers, begin the cycle, cycle to determine whether the version of the database file version is less than equal to the system, if it is executing the corresponding SQL database files, perform the functions of these documents will upgrade the database, including the construction of the table, modify table structure, inserting table data, table data modifying functions.

[0023] SQL脚本跟数据库的产品类型不相关,可以根据不同的数据库写不同的SQL脚本。 [0023] SQL script with products not related to the type of database, you can write different according to different database SQL script. 如果是MySql关系型数据库,则可以写对应的SQL脚本;如果是MongoDB这样的非关系型数据库,也可以调用该数据库方法。 If MySql relational database, you can write SQL scripts corresponding; if MongoDB is such a non-relational database, the database can also call the method. 本发明方法可以支持不同数据库的自动升级。 The method of the present invention can support different databases automatically upgraded.

[0024] 执行完SQL脚本后,将数据库版本加I,然后再次进入循环判断,直到数据库版本大于系统文件版本,然后跳出循环判断,结束数据库升级过程。 [0024] After executing the SQL script, plus the version of the database I, then enters a loop judge again until the system is greater than the version of the database file version, and then out of the loop judgment, the end of the database upgrade process. 在执行SQL脚本的过程中,自动打印出SQL脚本语句,如果执行语句报错,则打印报错信息,并中断升级过程。 During the execution of SQL scripts in SQL scripts to automatically print out the statement, the statement is executed if an error, then print an error message and interrupt the upgrade process.

[0025]例如,数据库版本是O,系统文件版本是2,执行循环检查功能,如果检测到数据库版本小于系统版本,则执行SQL脚本,执行成功后数据库版本加I,每执行一次循环过程,就执行其中一个版本的SQL脚本,并将数据库版本加I,直到数据库版本大于系统文件版本,则跳出循环,结束数据库升级过程。 [0025] For example, database version is O, system file version 2, execution cycle checking, if the detected database version less than the system version, execute SQL scripts, perform a database version successful plus I, each execution cycle, on one version of execution of SQL scripts, and database version plus I, until the system is greater than the version of the database file version is out of the loop, the end of the database upgrade process.

[0026] 实例流程图如图1所示,详述如下: [0026] Examples of the flowchart shown in FIG. 1, described in detail as follows:

[0027] I)系统启动时数据库自动升级过程开始运行。 Automatic database upgrade process starts running [0027] I) system startup.

[0028] 2)先检查到数据库版本,发现为O (假设数据库还未执行过任何SQL脚本)。 [0028] 2) to check the database version and found to be O (assuming that the database has not performed any SQL script).

[0029] 3)继续检查系统文件版本,发现为2 (假设有2个版本的SQL脚本要执行)。 [0029] 3) continue to check the version of the file system and found to be 2 (assuming that there are two versions of the SQL script to be executed).

[0030] 4)启动循环命令开始对比这2个版本号。 [0030] 4) cycle start command to start comparison of these two version numbers.

[0031] 5)如果数据库版本小于等于系统文件版本,并且数据库版本为O,则连接数据库执行版本为O的SQL脚本,脚本执行完成后将数据库版本加I。 [0031] 5) if the version of the database file system version or less, and the O database version, the connection database SQL script execution version of O, script execution added after the completion of the database version I.

[0032] 6)接着进入下一个循环判断,发现数据库版本(为I)还是小于系统文件版本,则连接数据库执行版本为I的SQL脚本,脚本执行完成后将数据库版本加I。 [0032] 6) then enters the next cycle is determined, the version found in the database (The I) or smaller than the version of the file system, perform the connection database version I SQL scripts, script execution added after the completion of the database version I.

[0033] 7)接着又进入下一个循环判断,发现数据库版本(为2)等于系统文件版本,依然连接数据库,执行版本为2的SQL脚本,脚本执行完成后将数据库版本加I。 The [0033] 7) into a loop followed judgment, found database version (2) equal to the system version of the file, is still connected to the database, SQL script execution version 2, the script execution added after the completion of the database version I.

[0034] 8)最后一次进入循环判断,发现数据库版本(为3)大于系统文件版本,跳出循环,升级过程结束。 [0034] 8) into the last cycle is determined, the version found in the database (3) is greater than the version of the file system, out of the loop, the upgrade process.

Claims (2)

1.一种数据库自动升级方法,其特征在于,包括以下步骤: 步骤1:在系统的文件中通过源代码方式记录一个系统文件版本号,在数据库中通过配置属性的方式记录一个数据库版本号; 步骤2:在系统启动中,通过命令调用的方式执行数据库升级过程; 步骤3:通过查找文件的方式找到系统文件版本号,并保存为一个本地变量,再连接数据库查找到数据库版本号,保存为第二个本地变量; 步骤4:查找到这两个版本号后,开始执行循环过程,循环判断数据库版本是否小于等于系统文件版本,如果是,则执行对应的数据库SQL文件,执行这些文件升级数据库的功能,包括建表、修改表结构、插入表数据和修改表数据; 步骤5:执行完SQL脚本后,将数据库版本加I,再次进入循环判断,直到数据库版本大于系统文件版本,跳出循环判断,结束数据库升级过程。 An automatic database upgrade method comprising the following steps: Step 1: a recording system by the version number of the source file in the file system, a database record version number by way of configuration properties in a database; step 2: in the system startup, perform database upgrade process by calling the command mode; step 3: look through the search for documents the way the system file version number, and save it as a local variable, and then connect to the database to find a database version number, save as second local variables; step 4: after finding these two version numbers, begin the cycle, the cycle is determined whether the version of the database file system version or less, and if so, the corresponding SQL database file is executed, these files are executed to upgrade the database features, including the construction of tables, modified table structure, inserting table data, and modify the table data; step 5: after execute SQL scripts, database version plus I, enter the circulation is determined again until the database version is greater than the system version of the file out of the loop is determined end database upgrade process.
2.如权利要求1所述的一种数据库自动升级方法,其特征在于,在执行SQL脚本的过程中,还包括自动打印出SQL脚本语句,如果执行语句报错,则打印报错信息,并中断升级过程。 2. An automatic database upgrade method according to claim 1, characterized in that, during the execution of SQL script, further comprising automatically print out the SQL script statement, the statement is executed if an error, the print error information, and interrupt the upgrade process.
CN201610903468.0A 2016-10-17 2016-10-17 Automatic database updating method CN106445618A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610903468.0A CN106445618A (en) 2016-10-17 2016-10-17 Automatic database updating method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610903468.0A CN106445618A (en) 2016-10-17 2016-10-17 Automatic database updating method

Publications (1)

Publication Number Publication Date
CN106445618A true CN106445618A (en) 2017-02-22

Family

ID=58175451

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610903468.0A CN106445618A (en) 2016-10-17 2016-10-17 Automatic database updating method

Country Status (1)

Country Link
CN (1) CN106445618A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107357907A (en) * 2017-07-17 2017-11-17 郑州云海信息技术有限公司 Cross-version supporting database upgrading method and device

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1713154A (en) * 2004-06-22 2005-12-28 中兴通讯股份有限公司 Method for upgrading network management system in mobile communication
CN101925094A (en) * 2009-06-17 2010-12-22 中兴通讯股份有限公司 Updating system and method for network element management system
US20140177813A1 (en) * 2008-02-28 2014-06-26 Computer Product Introductions, Corporation Computer Control of Online Social Interactions Based on Conversation Processing

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1713154A (en) * 2004-06-22 2005-12-28 中兴通讯股份有限公司 Method for upgrading network management system in mobile communication
US20140177813A1 (en) * 2008-02-28 2014-06-26 Computer Product Introductions, Corporation Computer Control of Online Social Interactions Based on Conversation Processing
CN101925094A (en) * 2009-06-17 2010-12-22 中兴通讯股份有限公司 Updating system and method for network element management system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107357907A (en) * 2017-07-17 2017-11-17 郑州云海信息技术有限公司 Cross-version supporting database upgrading method and device

Similar Documents

Publication Publication Date Title
US8392462B2 (en) Mapping from objects to data model
US7496596B2 (en) Detecting migration differences of a customized database schema
CN102200977B (en) Way to extend the database table multi-tenant environments and systems
US9311305B2 (en) Online upgrading of a database environment using transparently-patched seed data tables
JP2007519104A (en) A method and system for rule-based generation of automated test scripts from the abstract test case representation
US9569514B2 (en) Statement-level and procedural-level replication
US8065323B2 (en) Offline validation of data in a database system for foreign key constraints
CN101499069B (en) Internal memory database file updating method and apparatus
US20180081956A1 (en) Method for automatically synchronizing multi-source heterogeneous data resources
JP2004532465A (en) Data load from the remote data source
CN102053836B (en) Implementation method of version management tool for Android application development
CN101196926A (en) Database access platform and access method thereof
US7840610B2 (en) Apparatus, system, and method for map definition generation
CN101515290B (en) Metadata management system with bidirectional interactive characteristics and implementation method thereof
CN101645074A (en) Method for accessing relational databases of different types
WO2011082627A1 (en) System and method for developing software
CN103955363B (en) A program update method of manufacturing installation package
CN103440273A (en) Data cross-platform migration method and device
CN100442230C (en) Method and system for software multi-version upgrading
CN102375826B (en) Structured query language script analysis method, device and system
CN104200161B (en) A method for implementing intelligent detection file sandbox and sandbox intelligent detection system
CN103916482B (en) Sqlite one kind of data based on synchronous transmission
CN102156643A (en) Software integration method and system thereof
US8881139B1 (en) Legacy application rehosting system
CN100489778C (en) Method for implementing dynamic update of Java program

Legal Events

Date Code Title Description
C06 Publication
C10 Entry into substantive examination