CN112181946A - Method and device for automatically maintaining dynamic database script - Google Patents

Method and device for automatically maintaining dynamic database script Download PDF

Info

Publication number
CN112181946A
CN112181946A CN202011043856.9A CN202011043856A CN112181946A CN 112181946 A CN112181946 A CN 112181946A CN 202011043856 A CN202011043856 A CN 202011043856A CN 112181946 A CN112181946 A CN 112181946A
Authority
CN
China
Prior art keywords
script
dynamic
version
recorder
database
Prior art date
Legal status (The legal status 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 status listed.)
Pending
Application number
CN202011043856.9A
Other languages
Chinese (zh)
Inventor
刘连峰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Unisound Intelligent Technology Co Ltd
Xiamen Yunzhixin Intelligent Technology Co Ltd
Original Assignee
Unisound Intelligent Technology Co Ltd
Xiamen Yunzhixin Intelligent Technology Co Ltd
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 Unisound Intelligent Technology Co Ltd, Xiamen Yunzhixin Intelligent Technology Co Ltd filed Critical Unisound Intelligent Technology Co Ltd
Priority to CN202011043856.9A priority Critical patent/CN112181946A/en
Publication of CN112181946A publication Critical patent/CN112181946A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • G06F16/219Managing data history or versioning
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/23Updating

Abstract

The invention provides a method and a device for automatically maintaining a dynamic database script, wherein the method comprises the following steps: checking whether the current incremental script version is consistent with that in the version recorder; the incremental script comprises fixed business table upgrading information and dynamic business table upgrading information; if not, calculating the interval version and determining whether the dynamic script is upgraded or not; if not, executing the sql script; if so, preprocessing the dynamic script, and then executing the sql script; and after the gradual upgrade is successful, modifying the record in the version recorder. By utilizing the method, the manual maintenance of the dynamic database script can be avoided, the function of automatically maintaining the database script is achieved, and the research and development efficiency is improved.

Description

Method and device for automatically maintaining dynamic database script
Technical Field
One or more embodiments of the present invention relate to the field of computer database technologies, and in particular, to a method and an apparatus for automatically maintaining a dynamic database script.
Background
This section is intended to provide a background or context to the embodiments of the invention that are recited in the claims. The description herein is not admitted to be prior art by inclusion in this section. With the development of computer technology, database technology has also been developed. For a server, the database is a part of the server, the database is used for storing various types of data, and when data has an error, the data needs to be modified and maintained to ensure the normal operation of the server. In the conventional technology, a database script can be used to modify data in a database so as to achieve the purpose of modifying data in the database.
In the prior art, the existing flyway component can only support script maintenance of fixed database tables. And the general scheme for maintaining the data table dynamically generated in the service is as follows:
when the service is published every time, the database script needs to maintain two sets of full-volume scripts and incremental scripts, cross-version upgrading can frequently occur for private cloud deployment, and the incremental scripts of the intermediate versions need to be manually merged at the time.
And counting a data sheet required to be automatically created by the service according to a specific private cloud environment, modifying the script of the related increment, and then upgrading the database.
However, the prior art has the following defects:
(1) inconsistency often occurs in the full-amount script and the upgrading script, and the error rate is high. For example, the field is added in the upgrading script, but the field is not added in the full amount of scripts; repeated addition occurs when fields are added to the full-script, resulting in failed build.
(2) The step of manual inspection can ensure the quality, but the labor consumption is more.
Disclosure of Invention
In view of this, one or more embodiments of the present disclosure describe a method and an apparatus for automatically maintaining a dynamic database script, which do not manually maintain a database upgrade script any more, reduce the manual maintenance cost, achieve the function of automatically maintaining a database script, and improve the research and development efficiency.
The technical scheme provided by one or more embodiments of the specification is as follows:
in order to solve the above problem, in a first aspect, the present invention provides a method for automatic maintenance of a dynamic database script, where the method includes:
checking whether the current incremental script version is consistent with that in the version recorder; the incremental script comprises fixed business table upgrading information and dynamic business table upgrading information;
if not, calculating the interval version and determining whether the dynamic script is upgraded or not;
if not, executing the sql script;
if so, preprocessing the dynamic script, and then executing the sql script;
and after the gradual upgrade is successful, modifying the record in the version recorder.
In one example, delta scripts are managed with project iteration numbers.
In one example, a current script upgrade version is recorded in a version recorder.
In one example, the dynamic scenario is preprocessed, specifically:
when the dynamic service table upgrading information is analyzed, scanning all relevant tables in the current database, searching all matched data tables, and generating an sql script capable of running directly.
In a second aspect, the present invention provides an apparatus for automatic maintenance of dynamic database scripts, the apparatus comprising:
a checking unit for checking whether the current incremental script version is consistent with the version recorder; the incremental script comprises fixed business table upgrading information and dynamic business table upgrading information;
the processing unit is used for calculating the interval version and determining whether the dynamic script is upgraded or not when the incremental script version is inconsistent with the version recorder;
the preprocessing unit is used for preprocessing the dynamic script when the dynamic script is upgraded;
the execution unit is used for executing the sql script on the preprocessed dynamic script or directly executing the sql script when the dynamic script is not upgraded;
and the modification unit is used for modifying the record in the version recorder after the gradual upgrade is successful.
In one example, delta scripts are managed with project iteration numbers.
In one example, a current script upgrade version is recorded in a version recorder.
In an example, the preprocessing unit is configured to, when a dynamic script is upgraded, preprocess the dynamic script, specifically:
when the processing unit analyzes the dynamic service table upgrading information, the preprocessing unit scans all relevant tables in the current database, finds all matched data tables and generates an sql script which can be directly operated.
In a third aspect, the invention provides a computer device comprising a memory storing a computer program and a processor implementing the steps of the method according to one or more of the first aspects when the processor executes the computer program.
In a fourth aspect, the invention provides a computer-readable storage medium having stored thereon a computer program which, when being executed by a processor, carries out the steps of the method according to one or more of the first aspects.
According to the method provided by the embodiment of the invention, when the service is deployed, the difference between the version of the current database and the deployed version is automatically calculated, the response data table in the current database is inquired through the dynamic table identifier and is upgraded, the manual maintenance of the dynamic database script can be avoided, the manual maintenance cost is reduced, the function of automatically maintaining the database script is achieved, and the research and development efficiency is improved.
Drawings
FIG. 1 is a flowchart illustrating a method for automatically maintaining a dynamic database script according to an embodiment of the present invention;
FIG. 2 is a schematic structural diagram of an apparatus for automatically maintaining a dynamic database script according to an embodiment of the present invention;
fig. 3 is a schematic device structure diagram of a computer device for automatic maintenance of dynamic database scripts according to an embodiment of the present invention.
Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be further noted that, for the convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
The present invention provides a method for avoiding manual maintenance of a dynamic database script, and specifically, fig. 1 is a schematic flow chart of a method for automatically maintaining a dynamic database script provided in an embodiment of the present invention, where an execution main body of the method may be any device, equipment, platform, or equipment cluster having computing and processing capabilities. As shown in fig. 1, the method specifically includes the following steps:
step 10, check if the current delta script version is consistent with that in the version recorder.
Specifically, the incremental script is managed by the iteration number of the project, and increment is guaranteed, such as: the sql folder includes:
v1.0.0.sql
v1.0.1.sql
v1.0.2.sql
v1.1.0.sql
in one example, the current script upgrade version is recorded in the version recorder, e.g., 19:42:00 at a current time of 2020-07-01, with a current script upgrade version of v1.0.1. Examples of the recording method are shown in Table 1.
TABLE 1 incremental script and corresponding creation time
Figure BDA0002707405260000041
Figure BDA0002707405260000051
If the current incremental script version is consistent with that in the version recorder, the program is ended; if the current delta script version does not correspond to the version recorder, step 20 is performed.
Step 20, calculating the interval version and determining whether the dynamic script is upgraded.
Specifically, the interval version is calculated and gradually upgraded, and the incremental script comprises two types of data table upgrading information: fixed service table upgrade information and dynamic service table upgrade information. Wherein the dynamic table is uniformly written by $ { } symbols, such as: $ hospital Id.
In other words, at the time of service deployment, the gap between the version of the current database and the deployed version is automatically calculated, and the response data table in the current database is queried through the dynamic table identifier.
If the dynamic script is upgraded, step 30 is executed first, the dynamic script is preprocessed, and step 40 is executed, and the sql script is executed. If it is determined that no dynamic script is upgraded, step 40 is directly executed to execute the sql script.
In one example, the dynamic scenario is preprocessed, specifically:
when $ { } is analyzed, namely when the dynamic service table upgrading information is analyzed, scanning all relevant tables in the current database, searching all matched data tables, and generating an sql script which can be directly run.
And step 50, after the gradual upgrade is successful, modifying the record in the version recorder.
After the gradual upgrade is successful, the record in the version recorder is modified, and the database record version is changed into the latest version for the next upgrade. Such as 12:53:52 with current time 2020-07-08 and current version v1.1.0, the record in the version recorder is modified to table 2 on the basis of table 1.
TABLE 2 latest incremental script and its corresponding creation time
Id sql_version cur_status create_time
1 v1.0.0 0 2020-06-10 10:41:57
2 v1.0.1 0 2020-07-01 19:42:00
3 v1.1.0 1 2020-07-08 12:53:52
The method provided by the embodiment of the invention solves the problems in the prior art based on the following points:
(1) the database upgrade script is not manually maintained.
(2) When the service is deployed, the difference between the version of the current database and the deployed version is automatically calculated, the response data table in the current database is inquired through the dynamic table identifier, and the updating is carried out.
(3) And after the upgrade is successful, changing the database record version into the latest version.
(4) And if the upgrade is unsuccessful, automatically rolling back the database.
(5) The manual maintenance cost is reduced, and the function of automatically maintaining the database script is achieved.
Corresponding to the foregoing embodiment, the present invention further provides an apparatus for automatically maintaining a dynamic database script, as shown in fig. 2, the apparatus for automatically maintaining a dynamic database script further includes: a checking unit 210, a processing unit 220, a pre-processing unit 230, an execution unit 240 and a modification unit 250.
A checking unit 210 for checking whether the current incremental script version is consistent with the version recorder; the incremental script comprises fixed business table upgrading information and dynamic business table upgrading information;
a processing unit 220, configured to calculate an interval version and determine whether there is a dynamic script upgrade when the incremental script version is inconsistent with the version recorder;
a preprocessing unit 230, configured to preprocess the dynamic scenario when the dynamic scenario is upgraded;
an execution unit 240, configured to execute the sql script on the preprocessed dynamic script, or directly execute the sql script when the dynamic script is not upgraded;
and the modifying unit 250 is used for modifying the record in the version recorder after the gradual upgrade is successful.
The functions executed by each component in the device for automatically maintaining the dynamic database scripts provided by the embodiment of the invention are described in detail in the above method, and therefore, redundant description is not repeated here.
Corresponding to the above embodiment, an embodiment of the present invention further provides a computer device, specifically as shown in fig. 3, including a memory 310 and a processor 320, where the memory 310 stores a computer program, and the processor 320, when executing the computer program, implements any method step in the method for automatically maintaining a dynamic database script as described in the above embodiment.
In accordance with the above embodiments, the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements any one of the method steps in the method for automatic maintenance of dynamic database scripts described in the above embodiments.
According to the method provided by the embodiment of the invention, when the service is deployed, the difference between the version of the current database and the deployed version is automatically calculated, the response data table in the current database is inquired through the dynamic table identifier and is upgraded, the manual maintenance of the dynamic database script can be avoided, the manual maintenance cost is reduced, the function of automatically maintaining the database script is achieved, and the research and development efficiency is improved. Those of skill would further appreciate that the various illustrative components and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware, a software module executed by a processor, or a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above embodiments are provided to further explain the objects, technical solutions and advantages of the present invention in detail, it should be understood that the above embodiments are merely exemplary embodiments of the present invention and are not intended to limit the scope of the present invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (10)

1. A method for automatic maintenance of dynamic database scripts, the method comprising:
checking whether the current incremental script version is consistent with that in the version recorder; the incremental script comprises fixed business table upgrading information and dynamic business table upgrading information;
if not, calculating the interval version and determining whether the dynamic script is upgraded or not;
if not, executing the sql script;
if so, preprocessing the dynamic script, and then executing the sql script;
and after the gradual upgrade is successful, modifying the record in the version recorder.
2. The method of claim 1, wherein the delta script is managed with an item iteration number.
3. The method of claim 1, wherein the current script upgrade version is recorded in a version recorder.
4. The method according to claim 1, wherein the dynamic scenario is preprocessed, specifically:
when the dynamic service table upgrading information is analyzed, scanning all relevant tables in the current database, searching all matched data tables, and generating an sql script capable of running directly.
5. An apparatus for automatic maintenance of dynamic database scripts, the apparatus comprising:
a checking unit for checking whether the current incremental script version is consistent with the version recorder; the incremental script comprises fixed business table upgrading information and dynamic business table upgrading information;
the processing unit is used for calculating the interval version and determining whether the dynamic script is upgraded or not when the incremental script version is inconsistent with the version recorder;
the preprocessing unit is used for preprocessing the dynamic script when the dynamic script is upgraded;
the execution unit is used for executing the sql script on the preprocessed dynamic script or directly executing the sql script when the dynamic script is not upgraded;
and the modification unit is used for modifying the record in the version recorder after the gradual upgrade is successful.
6. The apparatus of claim 5, wherein the delta script is managed with an item iteration number.
7. The apparatus of claim 5, wherein the current script upgrade version is recorded in a version recorder.
8. The apparatus according to claim 5, wherein the preprocessing unit is configured to, when the dynamic scenario is upgraded, preprocess the dynamic scenario, specifically:
when the processing unit analyzes the dynamic service table upgrading information, the preprocessing unit scans all relevant tables in the current database, finds all matched data tables and generates an sql script which can be directly operated.
9. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 4 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 4.
CN202011043856.9A 2020-09-28 2020-09-28 Method and device for automatically maintaining dynamic database script Pending CN112181946A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011043856.9A CN112181946A (en) 2020-09-28 2020-09-28 Method and device for automatically maintaining dynamic database script

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011043856.9A CN112181946A (en) 2020-09-28 2020-09-28 Method and device for automatically maintaining dynamic database script

Publications (1)

Publication Number Publication Date
CN112181946A true CN112181946A (en) 2021-01-05

Family

ID=73947257

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011043856.9A Pending CN112181946A (en) 2020-09-28 2020-09-28 Method and device for automatically maintaining dynamic database script

Country Status (1)

Country Link
CN (1) CN112181946A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114153858A (en) * 2021-11-26 2022-03-08 泰康保险集团股份有限公司 Method and device for automatically updating tenant in MySQL table space

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050198630A1 (en) * 2004-03-08 2005-09-08 Microsoft Corporation Relational database schema version management
CN1713154A (en) * 2004-06-22 2005-12-28 中兴通讯股份有限公司 Method for upgrading network management system in mobile communication
CN101183361A (en) * 2006-11-13 2008-05-21 中兴通讯股份有限公司 Method of relation data base applications automatic upgrade
CN102495733A (en) * 2011-12-08 2012-06-13 方正国际软件有限公司 Methods for detecting compatibility of application program and relevant database script and performing upgrading maintenance on application program and relevant database script

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050198630A1 (en) * 2004-03-08 2005-09-08 Microsoft Corporation Relational database schema version management
CN1713154A (en) * 2004-06-22 2005-12-28 中兴通讯股份有限公司 Method for upgrading network management system in mobile communication
CN101183361A (en) * 2006-11-13 2008-05-21 中兴通讯股份有限公司 Method of relation data base applications automatic upgrade
CN102495733A (en) * 2011-12-08 2012-06-13 方正国际软件有限公司 Methods for detecting compatibility of application program and relevant database script and performing upgrading maintenance on application program and relevant database script

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114153858A (en) * 2021-11-26 2022-03-08 泰康保险集团股份有限公司 Method and device for automatically updating tenant in MySQL table space

Similar Documents

Publication Publication Date Title
CN106796585B (en) Conditional validation rules
US8108456B2 (en) Method and apparatus for migrating the system environment on which the applications depend
US11157390B2 (en) Automatic software defect repair
US8832125B2 (en) Extensible event-driven log analysis framework
CN104182335A (en) Software testing method and device
US20110137859A1 (en) Staged Data Conversion
US9336116B2 (en) Automatic correlation accelerator
CN111414302A (en) Static code quality analysis method and computing device for continuous integration process
CN111881012A (en) Log recording method, device, equipment and storage medium
US11399071B2 (en) Program operation system and program operation method
CN112181946A (en) Method and device for automatically maintaining dynamic database script
CN114860654A (en) Method and system for dynamically changing Iceberg table Schema based on Flink data stream
CN110704025A (en) Method and device for generating coding specification tool, storage medium and electronic equipment
US20220114478A1 (en) System and method for enhancing inference models based on prediction data
US20100122240A1 (en) Method and apparatus for analyzing application
CN110928941B (en) Data fragment extraction method and device
CN105808451A (en) Data caching method and related apparatus
CN115438026A (en) Database scanning method, device, equipment, storage medium and product
US11740895B2 (en) Generation of software program repair explanations
CN112433738B (en) Firmware update test method, system, equipment and medium
CN115756554B (en) Version upgrading method and device
CN112148710B (en) Micro-service library separation method, system and medium
US7685188B2 (en) Automated generation of computer-executable compensation procedures for previously executed methods
US11934800B2 (en) Generating metadata to facilitate code generation
CN109739506B (en) Method and system for processing library function missing in high-performance application compilation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination