A database upgrading method, device and equipment
Patent Information
- Application Number
- CN202110521410.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-13
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2041-05-13
AI Technical Summary
[0004]人工比较新旧两个版本的数据库并手工编写升级脚本,耗时耗力,效率低下
[0063] By obtaining the scripts for the first version of the database in the production environment and the scripts for the second version of the database in the pre-production environment, a database upgrade script is generated based on the scripts for the first and second versions of the database. The second version of the microservice program is then deployed in the production environment, and the database upgrade script is executed. This invention enables the export of corresponding scripts from the microservice program and the automatic generation of an upgrade database, thus achieving rapid and efficient database upgrades.
Smart Images

Figure CN115344278B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database information processing technology, and in particular to a database upgrade method, apparatus, and equipment. Background Technology
[0002] With the development of microservices, applications are being released more and more frequently. Upgrading applications requires retaining existing data and upgrading based on the old database table structure and data.
[0003] Upgrading applications in a production environment requires upgrading the corresponding database structure and data. It's crucial to ensure that the database table structure and data from before the upgrade are compatible with the upgraded application after executing the upgrade script. Existing technologies suffer from at least the following problems:
[0004] Manually comparing the old and new versions of the database and writing upgrade scripts is time-consuming, labor-intensive, and inefficient. Summary of the Invention
[0005] The technical problem this invention aims to solve is how to provide a database upgrade method, apparatus, and device to achieve efficient and rapid database upgrades.
[0006] To solve the above-mentioned technical problems, the technical solution of the present invention is as follows:
[0007] A database upgrade method, the method comprising:
[0008] A script to obtain the first version of the database in the production environment and a script to obtain the second version of the database in the pre-production environment;
[0009] Generate a database upgrade script based on the scripts of the first version of the database and the scripts of the second version of the database;
[0010] After deploying the second version of the microservice application in the production environment, the database upgrade script is then executed.
[0011] Optional, the script to obtain the first version of the database for the production environment includes:
[0012] Obtain the first database full script of the first version of the microservice program in the production environment;
[0013] Obtain the full script of the second database corresponding to the first version database of the first version microservice program;
[0014] Obtain the enumeration value of the attribute defined as an enumeration value in the production environment, or the enumeration value of the attribute tagged with an enumeration.
[0015] If the enumeration values in the full scripts of the first database and the full scripts of the second database are consistent with the enumeration values of the attributes, a first version of the script is obtained.
[0016] Optionally, obtain the first database full script of the first version of the microservice program in the production environment, including:
[0017] Export the first full table script of the first relational database using the first version of the microservice program in the production environment;
[0018] Export the first full table script of the first non-relational database using the first version of the microservice program;
[0019] Scan the first version of the microservice program to obtain a list of the first preset objects for the user documentation;
[0020] Obtain the name, type, and value of all attributes of the first preset object, and generate and export the full script of the first database.
[0021] Optionally, export the first full table script of the relational database from the first version of the microservice application in the production environment, including:
[0022] Scan the first version of the microservice program to obtain a list of second preset objects that use the table, and form a first database table based on the second preset objects;
[0023] Scan the microservice resource file package of the first version of the microservice program to obtain all target files, and form a second database table based on the target files;
[0024] The union of the first database table and the second database table is determined as the full table script of the first relational database.
[0025] Optionally, the first version of the microservice program can be used to export the first full table script of the NoSQL database, including:
[0026] By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export the first full table script for a non-relational database.
[0027] Optionally, obtain the full script of the second database corresponding to the first version of the microservice program, including:
[0028] When the database is a relational database, export the full script of the second database corresponding to the first version of the microservice program using the export command provided by the relational database; or
[0029] When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the second database corresponding to the first version of the microservice program.
[0030] Optional database upgrade methods also include:
[0031] If the enumeration values in the full script of the first database and the full script of the second database are inconsistent with the enumeration values of the attributes, if the enumeration value in the full script of the first database is incorrect, then the first version of the microservice program is corrected; if the enumeration value in the full script of the second database is incorrect, then the first version of the database corresponding to the first version of the microservice program is corrected.
[0032] Optionally, a script to obtain a second version of the database for a pre-production environment includes:
[0033] Obtain the full script of the third database for the second version of the microservice program in the pre-production environment;
[0034] Obtain the full script of the fourth database corresponding to the second version database of the second version microservice program;
[0035] Obtain the enumeration value of the attribute defined as an enumeration value in the pre-production environment, or the enumeration value of the attribute tagged with an enumeration.
[0036] If the enumeration values in the full scripts of the third and fourth databases are consistent with the enumeration values of the attributes, a second version of the script is obtained.
[0037] Optionally, obtain the full script of the third database for the second version of the microservice program in the pre-production environment, including:
[0038] Export the full table script of the second relational database using the second version of the microservice program in the pre-production environment;
[0039] Export the full table script of the second non-relational database using the second version of the microservice program;
[0040] Scan the second version of the microservice program to obtain a list of the second preset objects in the user documentation;
[0041] Obtain the name, type, and value of all attributes of the second preset object, and generate and export the full script of the first database.
[0042] Optionally, the second version of the microservice program in the pre-production environment is used to export a second full-table script for the relational database, including:
[0043] Scan the second version of the microservice program to obtain a list of third preset objects that use the table, and form a third database table based on the third preset objects;
[0044] Scan the microservice resource file package of the second version microservice program to obtain all target files, and form a fourth database table based on the target files;
[0045] The union of the third and fourth database tables is determined as the second relational database full table script.
[0046] Optionally, the second version of the microservice program can be used to export a second full-table script for the NoSQL database, including:
[0047] By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export a full table of a second non-relational database.
[0048] Optionally, obtain the full script of the fourth database corresponding to the second version database of the second version microservice program, including:
[0049] When the database is a relational database, export the full script of the fourth database corresponding to the second version of the microservice program using the export command provided by the relational database; or
[0050] When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the fourth database corresponding to the second version of the microservice program.
[0051] Optional database upgrade methods also include:
[0052] If the enumeration values in the full scripts of the third and fourth databases are inconsistent with the enumeration values of the attributes, then if the enumeration value in the full script of the third database is incorrect, the second version of the microservice program is corrected; if the enumeration value in the full script of the fourth database is incorrect, the second version of the database corresponding to the second version of the microservice program is corrected.
[0053] Optionally, a database upgrade script is generated based on the scripts of the first version of the database and the scripts of the second version of the database, including:
[0054] Obtain the differences between the scripts for the first version of the database and the scripts for the second version of the database;
[0055] Generate a database upgrade script based on the differences.
[0056] Embodiments of the present invention also provide a database upgrade apparatus, the apparatus comprising:
[0057] The module is used to obtain the scripts for the first version of the database in the production environment and the second version of the database in the pre-production environment.
[0058] The processing module is used to generate a database upgrade script based on the script of the first version database and the script of the second version database.
[0059] The execution module is used to deploy the second version of the microservice program in the production environment and then execute the database upgrade script.
[0060] Embodiments of the present invention also provide a database upgrade device, including: a processor and a memory storing a computer program, wherein the computer program, when run by the processor, executes the method described above.
[0061] Embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method described above.
[0062] The above-described solution of the present invention has at least the following beneficial effects:
[0063] By obtaining the scripts for the first version of the database in the production environment and the scripts for the second version of the database in the pre-production environment, a database upgrade script is generated based on the scripts for the first and second versions of the database. The second version of the microservice program is then deployed in the production environment, and the database upgrade script is executed. This invention enables the export of corresponding scripts from the microservice program and the automatic generation of an upgrade database, thus achieving rapid and efficient database upgrades. Attached Figure Description
[0064] Figure 1 This is a flowchart illustrating the database upgrade method according to an embodiment of the present invention;
[0065] Figure 2 This is a schematic diagram of the process for generating a database upgrade script according to an embodiment of the present invention;
[0066] Figure 3 This is a schematic diagram of the process of executing the database upgrade script according to an embodiment of the present invention;
[0067] Figure 4 This is a flowchart illustrating the process of generating a deployment environment script according to an embodiment of the present invention;
[0068] Figure 5 This is a schematic diagram of the module block of the database upgrade device according to an embodiment of the present invention. Detailed Implementation
[0069] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0070] like Figure 1 As shown, an embodiment of the present invention provides a database upgrade method, the method comprising:
[0071] Step 11: Obtain the scripts for the first version of the database in the production environment and the scripts for the second version of the database in the pre-production environment;
[0072] Step 12: Generate a database upgrade script based on the scripts of the first version of the database and the scripts of the second version of the database;
[0073] Step 13: Publish the second version of the microservice program in the production environment, and then execute the database upgrade script.
[0074] like Figure 2 and Figure 3 As shown, this embodiment generates a database upgrade script based on the scripts of the first version of the database in the production environment and the scripts of the second version of the database in the pre-production environment using a full script comparison tool. Then, the second version of the microservice program is deployed in the production environment and the database upgrade script is executed, ultimately completing the database upgrade. This solves the problems of application and database incompatibility or dirty tables and data in existing technologies, provides an effective detection mechanism, ensures the cleanliness of the database and program, saves significant manpower and resources, and reduces the possibility of errors.
[0075] In an optional embodiment of the present invention, step 11, obtaining the script for the first version of the database in the production environment, includes:
[0076] Step 111: Obtain the first database full script of the first version of the microservice program in the production environment;
[0077] Step 112: Obtain the full script of the second database corresponding to the first version database of the first version microservice program;
[0078] Step 113: Obtain the enumeration value of the attribute defined as an enumeration value in the production environment or the enumeration value of the attribute tagged with an enumeration.
[0079] Step 114: If the enumeration values in the full script of the first database and the full script of the second database are consistent with the enumeration values of the attributes, obtain the first version of the script.
[0080] like Figure 4 As shown, Figure 4 The deployment environment can be a production environment or a pre-production environment. In this embodiment, the deployment environment is a production environment, microservice V1 is the first version of the microservice program in the production environment, and database V1 is the first version database corresponding to the first version of the microservice program. The full script of the first database of the first version of the microservice program in the production environment, the full script of the second database of the first version of the microservice program, and the enumeration values of the attributes defined as enumeration values or the enumeration values of the attributes tagged with enumerations in the production environment are exported and a consistency check is performed. If the check passes, that is, if they are consistent, the first version of the script is generated.
[0081] In an optional embodiment of the present invention, step 111 may include:
[0082] Step 1111: Export the first full table script of the relational database using the first version of the microservice program in the production environment;
[0083] Step 1112: Export the first non-relational database full table script through the first version of the microservice program;
[0084] Step 1113: Scan the first version of the microservice program to obtain a list of the first preset objects for the usage documentation;
[0085] Step 1114: Obtain the name, type, and value of all attributes of the first preset object, and generate and export the full script of the first database.
[0086] In this embodiment, a relational database refers to a database that uses a relational model to organize data, storing data in rows and columns; a non-relational database (NoSQL database) may include the database MongoDB.
[0087] Furthermore, step 1111 specifically includes:
[0088] Step 1111a: Scan the first version of the microservice program to obtain a list of second preset objects that use the table, and form a first database table based on the second preset objects;
[0089] Step 1111b: Scan the microservice resource file package of the first version of the microservice program to obtain all target files, and form a second database table based on the target files;
[0090] Step 1111c: Determine the union of the first database table and the second database table as the full table script of the first relational database.
[0091] This embodiment scans the entire first-version microservice program to find and obtain a list of second preset objects that use tables, parses the second preset objects, and obtains all attribute names, types, and values of the objects to form a first database table; then it scans the entire microservice resource file package of the first-version microservice program to find and obtain all target files to form a second database table; based on different database types, it combines the first and second database tables to form a union of the first and second database tables, and generates a first relational database full table script in the first-version microservice program, thus realizing the export of the first relational database full table script using the microservice program.
[0092] In a specific embodiment 1, a script is used to export the full table of a relational database through a microservice program. The partial code for the tables in the microservice program is shown below:
[0093] import…
[0094] @Table(name="tbl_account_enterprise_rel")
[0095] @Builder
[0096] @AllArgsConstructor
[0097] @NoArgsConstructor
[0098] @Data
[0099] Public class TblAccountEnterpriseRel{
[0100] @Id
[0101] private Integer id;
[0102] @Column(name = "user_id")
[0103] private String userId;
[0104] @Column(name = "eid")
[0105] private String eid;
[0106] @Column(name = "status")
[0107] private EStatus status;
[0108] }
[0109] Based on the aforementioned microservice program code, the entity structure bean objects using `@Table` are located, a list of all bean objects is obtained, and the bean objects are parsed to retrieve all attribute names, types, and enumeration types from the enumeration values, forming the first database table. In the code above, "userId" is the attribute name, "String" is the attribute type, and "EStatus" is the enumeration value. Further, the corresponding code for the enumeration values is shown below:
[0110] package net.virtue.oscar.core.mds.mapper.bo;
[0111] public enum EStatus{
[0112] ENABLED, DISABLED
[0113] }
[0114] In the microservice program, the properties defined as enumeration values or the properties tagged with enumerations are obtained. Then, based on the program code corresponding to the above enumeration values, the actual enumeration values in the database are searched and obtained. The enumeration type of the enumeration value is "ENABLED, DISABLED". The first database table is formed by the property name "userId", the property type "String" and the enumeration type "ENABLED, DISABLED" of the enumeration value "EStatus".
[0115] Next, scan the entire microservice resource file package to find all MyBatis XML mapper files, obtain the table name and type values for all resultMaps, and then find the following child elements to obtain the field names and field types to form the second database table. The partial code of the MyBatis XML mapper file is shown below:
[0116]
[0117] In this structure, the table name `type` of `resultMap` is "TblAccountEnterpriseRel", and the field name in the child element is "user_id" with a field type of "VARCHAR". Based on the table name `type` "TblAccountEnterpriseRel", the field name "user_id", and the field type "VARCHAR", a second database table is formed. Depending on the different database types, the first and second database tables are combined to form a union, and a full relational database table script is generated in the microservice program.
[0118] In an optional embodiment of the present invention, step 1112 includes:
[0119] By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export the first full table script for a non-relational database.
[0120] In this embodiment, SpringData-jpa is a module under the Spring Data framework project, which provides a simplified solution for operating the database based on the JPA (Java Persistence API) standard. In this embodiment, by combining SpringData-jpa with the MongoDB database, the document objects, as well as the enumeration values and nested objects in the document objects, are traversed to generate a first non-relational database full table script, wherein the first non-relational database full table script may include a JSON (JavaScript Object Notation) database table.
[0121] It should be noted that for non-basic type properties, such as List, Set, and custom entity structure beans, it is necessary to continue traversing their child objects to form a nested database table structure, as shown below:
[0122] {
[0123] "id":"String",
[0124] "name":"String",
[0125] "age":"int",
[0126] "email":"String",
[0127] "password":"String",
[0128] "subjectList":[{
[0129] "id":"long",
[0130] "subName":"String", ...
[0132] }], ...
[0134] In a specific embodiment 2, a script is used to export a full set of tables from a NoSQL database via a microservice program. NoSQL refers to non-relational databases, including MongoDB. The parent node portion of the document in the microservice program is shown in the following code:
[0135] @Document(collection="c_student")
[0136] public class Student{
[0137] @Id()
[0138] private String id;
[0139] @Field("name")
[0140] private String studentName;
[0141] private int age;
[0142] private String email;
[0143] private String password;
[0144] private List <subject>subjectList = new ArrayList<>
[0145] public String getId(){
[0146] return studentName;
[0147] }
[0148] public String getId(){
[0149] return id;
[0150] }
[0151] public void setId(String id){
[0152] this.id = id;
[0153] }
[0154] public void setStudentName(String studentName){
[0155] this.studentName=studentName;
[0156] }
[0157] public int getAge(){
[0158] return age;
[0159] }
[0160] Scan the entire microservice application to find entity structure bean objects using `@Document`, obtain a list of all bean objects, parse the bean objects, and retrieve all attribute names, types, and values of each object. This is then used to create a full table script for a non-relational database. In the code above, `collection="c_student"` is the table name, `studentName` is the attribute name, `String` is the attribute type, and `List` is the attribute type. <subject>This is a nested type. Furthermore, the code snippet corresponding to the table name "collection="c_student"" is as follows:
[0161]
[0162] The code for the child nodes of the nested type is shown below:
[0163] public class Subject{
[0164] private Long id;
[0165] private String subName;
[0166] public Long getId(){
[0167] return id;
[0168] }
[0169] public void setId(Long id){
[0170] this.id = id;
[0171] }
[0172] public String getSubName(){
[0173] return subName;
[0174] }
[0175] In an optional embodiment of the present invention, step 112 includes:
[0176] When the database is a relational database, export the full script of the second database corresponding to the first version of the microservice program using the export command provided by the relational database; or
[0177] When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the second database corresponding to the first version of the microservice program.
[0178] In this embodiment, the second full database script for exporting the database needs to be processed according to the database type. For relational databases, it can be exported through the command provided by the relational database, with the export command being the preferred command. For non-relational databases, the data can be exported first and then parsed by traversing the data. Non-relational databases include the database MongoDB.
[0179] In an optional embodiment of the present invention, the database upgrade method may further include:
[0180] Step 115: If the enumeration values in the full script of the first database and the full script of the second database are inconsistent with the enumeration values of the attributes, if the enumeration value in the full script of the first database is incorrect, then the first version of the microservice program is corrected; if the enumeration value in the full script of the second database is incorrect, then the first version of the database corresponding to the first version of the microservice program is corrected.
[0181] like Figure 4 As shown, if the consistency test fails, if the entity class table structure in the first version of the microservice program and / or the enumeration values in the full script of the first database are incorrect, correct the first version of the microservice program and recompare; if the full script of the second database and / or the enumeration values in the full script of the second database are incorrect, correct the first version of the database corresponding to the first version of the microservice program and recompare; in addition, it should be noted that some ignorable errors, redundant table structures and / or attributes that can be temporarily retained can be marked with an ignore tag.
[0182] In an optional embodiment of the present invention, step 11, obtaining the script for the second version database of the pre-production environment, includes:
[0183] Step 116: Obtain the full script of the third database for the second version of the microservice program in the pre-production environment;
[0184] Step 117: Obtain the full script of the fourth database corresponding to the second version database of the second version microservice program;
[0185] Step 118: Obtain the enumeration value of the attribute defined as an enumeration value or the enumeration value of the attribute tagged with an enumeration in the pre-production environment;
[0186] Step 119: If the enumeration values in the full scripts of the third and fourth databases are consistent with the enumeration values of the attributes, obtain the second version of the script.
[0187] like Figure 4 As shown, here, microservice V1 is the second version of the microservice program in the pre-production environment, and database V1 is the second version database corresponding to the second version of the microservice program. The full script of the second database of the second version of the microservice program in the pre-production environment, the full script of the third database of the second version database, and the enumeration values of the attributes defined as enumeration values or the enumeration values of the attributes tagged with enumerations in the pre-production environment are exported and a consistency check is performed. If the check passes, that is, if they are consistent, the second version script is generated.
[0188] In an optional embodiment of the present invention, step 115 includes:
[0189] Step 1161: Export the second full table script of the relational database through the second version of the microservice program in the pre-production environment;
[0190] Step 1162: Export the full table script of the second non-relational database through the second version of the microservice program;
[0191] Step 1163: Scan the second version of the microservice program to obtain a list of the second preset objects in the usage documentation;
[0192] Step 1164: Obtain the name, type, and value of all attributes of the second preset object, and generate and export the full script of the first database.
[0193] Furthermore, step 1161 specifically includes:
[0194] Step 1161a: Scan the second version of the microservice program to obtain a list of third preset objects that use the table, and form a third database table based on the third preset objects;
[0195] Step 1161b: Scan the microservice resource file package of the second version microservice program to obtain all target files, and form a fourth database table based on the target files;
[0196] Step 1161c: Determine the union of the third database table and the fourth database table as the second relational database full table script.
[0197] This embodiment scans the second-version microservice program to find and obtain a list of third preset objects that use tables, parses the third preset objects to obtain all attribute names, types, and values of the objects, forming a third database table; then scans the entire microservice resource file package of the second-version microservice program to find and obtain all target files, forming a fourth database table; finally, based on different data types, it combines the third and fourth database tables to form the union of the third and fourth database tables, generating a second relational database full table script in the second-version microservice program, thus realizing the export of a second relational database full table script from a pre-production environment second-version microservice program.
[0198] In an optional embodiment of the present invention, step 1162 specifically includes:
[0199] By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export a full table of a second non-relational database.
[0200] In this embodiment, by combining the SpringData-jpa framework with the MongoDB database, the document object and its enumeration values and nested objects are traversed to generate a second non-relational database full table script. This second non-relational database full table script can be a lightweight data exchange format.
[0201] In an optional embodiment of the present invention, step 117 may include:
[0202] When the database is a relational database, export the full script of the fourth database corresponding to the second version of the microservice program using the export command provided by the relational database; or
[0203] When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the fourth database corresponding to the second version of the microservice program.
[0204] In this embodiment, the second full database script for exporting the database needs to first determine whether the database is a relational database or a non-relational database. For relational databases, the export command can be used, preferably the export command. For non-relational databases, the data can be exported first, and then parsed out by traversing the data.
[0205] In an optional embodiment of the present invention, the database upgrade method may further include:
[0206] Step 1110: If the enumeration values in the full scripts of the third and fourth databases are inconsistent with the enumeration values of the attributes, if the enumeration values in the full scripts of the third database are incorrect, then the second version of the microservice program is corrected; if the enumeration values in the full scripts of the fourth database are incorrect, then the second version of the database corresponding to the second version of the microservice program is corrected.
[0207] like Figure 4 As shown, in this embodiment, if the consistency test fails, and the entity class table structure and / or the enumeration values of the full script of the third database in the second version microservice program are incorrect, the second version microservice program is corrected and a re-comparison is performed; if the full script of the fourth database and / or the enumeration values of the full script of the fourth database are incorrect, the third version database corresponding to the second version microservice program is corrected and a re-comparison is performed; in addition, some negligible errors, redundant but temporarily retainable table structures and / or attributes can be marked with an ignore tag.
[0208] In an optional embodiment of the present invention, step 12 includes:
[0209] Step 121: Obtain the differences between the scripts of the first version database and the scripts of the second version database;
[0210] Step 122: Generate a database upgrade script based on the differences.
[0211] like Figure 2 As shown, in this embodiment, the scripts of the first version database in the production environment and the scripts of the second version database in the pre-production environment are compared using a full script comparison tool to obtain the differences, and then a database upgrade script is generated based on the differences.
[0212] Embodiments of the present invention obtain the scripts of a first version of the database in the production environment and the scripts of a second version of the database in the pre-production environment; generate a database upgrade script based on the scripts of the first and second versions of the database; deploy the second version of the microservice program in the production environment and execute the database upgrade script. This achieves the export of database tables (scripts) based on the microservice program and further automatically generates the database upgrade script, thereby enabling rapid database upgrades. Furthermore, for different database types in the production environment, no manual coding is required; the application's database table structure can be efficiently and quickly exported, enabling database upgrades.
[0213] like Figure 5 As shown, embodiments of the present invention also provide a database upgrade device 50, the device comprising:
[0214] Module 51 is used to obtain the scripts for the first version of the database in the production environment and the scripts for the second version of the database in the pre-production environment.
[0215] Processing module 52 is used to generate a database upgrade script based on the script of the first version database and the script of the second version database.
[0216] Execution module 53 is used to deploy the second version of the microservice program in the production environment and then execute the database upgrade script.
[0217] Optional, the script to obtain the first version of the database for the production environment includes:
[0218] Obtain the first database full script of the first version of the microservice program in the production environment;
[0219] Obtain the full script of the second database corresponding to the first version database of the first version microservice program;
[0220] Obtain the enumeration value of the attribute defined as an enumeration value in the production environment, or the enumeration value of the attribute tagged with an enumeration.
[0221] If the enumeration values in the full scripts of the first database and the full scripts of the second database are consistent with the enumeration values of the attributes, a first version of the script is obtained.
[0222] Optionally, obtain the first database full script of the first version of the microservice program in the production environment, including:
[0223] Export the first full table script of the first relational database using the first version of the microservice program in the production environment;
[0224] Export the first full table script of the first non-relational database using the first version of the microservice program;
[0225] Scan the first version of the microservice program to obtain a list of the first preset objects for the user documentation;
[0226] Obtain the name, type, and value of all attributes of the first preset object, and generate and export the full script of the first database.
[0227] Optionally, export the first full table script of the relational database from the first version of the microservice application in the production environment, including:
[0228] Scan the first version of the microservice program to obtain a list of second preset objects that use the table, and form a first database table based on the second preset objects;
[0229] Scan the microservice resource file package of the first version of the microservice program to obtain all target files, and form a second database table based on the target files;
[0230] The union of the first database table and the second database table is determined as the full table script of the first relational database.
[0231] Optionally, the first version of the microservice program can be used to export the first full table script of the NoSQL database, including:
[0232] By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export the first full table script for a non-relational database.
[0233] Optionally, obtain the full script of the second database corresponding to the first version of the microservice program, including:
[0234] When the database is a relational database, export the full script of the second database corresponding to the first version of the microservice program using the export command provided by the relational database; or
[0235] When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the second database corresponding to the first version of the microservice program.
[0236] Optionally, the processing module 52 is further configured to, in the case that the enumeration values in the full script of the first database and the full script of the second database are inconsistent with the enumeration values of the attributes, correct the first version of the microservice program if the enumeration value in the full script of the first database is incorrect; and correct the first version of the database corresponding to the first version of the microservice program if the enumeration value in the full script of the second database is incorrect.
[0237] Optionally, a script to obtain a second version of the database for a pre-production environment includes:
[0238] Obtain the full script of the third database for the second version of the microservice program in the pre-production environment;
[0239] Obtain the full script of the fourth database corresponding to the second version database of the second version microservice program;
[0240] Obtain the enumeration value of the attribute defined as an enumeration value in the pre-production environment, or the enumeration value of the attribute tagged with an enumeration.
[0241] If the enumeration values in the full scripts of the third and fourth databases are consistent with the enumeration values of the attributes, a second version of the script is obtained.
[0242] Optionally, obtain the full script of the third database for the second version of the microservice program in the pre-production environment, including:
[0243] Export the full table script of the second relational database using the second version of the microservice program in the pre-production environment;
[0244] Export the full table script of the second non-relational database using the second version of the microservice program;
[0245] Scan the second version of the microservice program to obtain a list of the second preset objects in the user documentation;
[0246] Obtain the name, type, and value of all attributes of the second preset object, and generate and export the full script of the first database.
[0247] Optionally, the second version of the microservice program in the pre-production environment is used to export a second full-table script for the relational database, including:
[0248] Scan the second version of the microservice program to obtain a list of third preset objects that use the table, and form a third database table based on the third preset objects;
[0249] Scan the microservice resource file package of the second version microservice program to obtain all target files, and form a fourth database table based on the target files;
[0250] The union of the third and fourth database tables is determined as the second relational database full table script.
[0251] Optionally, the second version of the microservice program can be used to export a second full-table script for the NoSQL database, including:
[0252] By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export a full table of a second non-relational database.
[0253] Optionally, obtain the full script of the fourth database corresponding to the second version database of the second version microservice program, including:
[0254] When the database is a relational database, export the full script of the fourth database corresponding to the second version of the microservice program using the export command provided by the relational database; or
[0255] When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the fourth database corresponding to the second version of the microservice program.
[0256] Optionally, the processing module 52 is further configured to, in the case of inconsistencies between the enumeration values in the full script of the third database and the full script of the fourth database and the enumeration values of the attributes, correct the second version of the microservice program if the enumeration value in the full script of the third database is incorrect; and correct the second version of the database corresponding to the second version of the microservice program if the enumeration value in the full script of the fourth database is incorrect.
[0257] Optionally, a database upgrade script is generated based on the scripts of the first version of the database and the scripts of the second version of the database, including:
[0258] Obtain the differences between the scripts for the first version of the database and the scripts for the second version of the database;
[0259] Generate a database upgrade script based on the differences.
[0260] It should be noted that this device is the same as the method described above. All implementations in the above method embodiments are applicable to the embodiments of this device and can achieve the same technical effect.
[0261] Embodiments of the present invention also provide a database upgrade device, including: a processor and a memory storing a computer program, wherein the computer program, when executed by the processor, performs the method as described above. All implementations in the above method embodiments are applicable to this embodiment and can achieve the same technical effect.
[0262] Embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method as described above. All implementations in the above method embodiments are applicable to this embodiment and can achieve the same technical effects.
[0263] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0264] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0265] In the embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0266] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0267] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0268] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0269] Furthermore, it should be noted that in the apparatus and method of the present invention, it is obvious that the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered equivalent solutions of the present invention. Moreover, the steps performing the above-described series of processes can naturally be executed in the order described, but are not necessarily required to be executed in chronological order; some steps can be executed in parallel or independently of each other. Those skilled in the art will understand that all or any step or component of the method and apparatus of the present invention can be implemented in any computing device (including processors, storage media, etc.) or network of computing devices, in hardware, firmware, software, or a combination thereof. This is something that those skilled in the art can achieve by using their basic programming skills after reading the description of the present invention.
[0270] Therefore, the object of the present invention can also be achieved by running a program or a set of programs on any computing device. The computing device can be a known general-purpose device. Therefore, the object of the present invention can also be achieved simply by providing a program product containing program code implementing the method or apparatus. That is, such a program product also constitutes the present invention, and the storage medium storing such a program product also constitutes the present invention. Obviously, the storage medium can be any known storage medium or any storage medium developed in the future. It should also be noted that in the apparatus and method of the present invention, it is obvious that the components or steps can be decomposed and / or recombined. These decompositions and / or recombinations should be considered equivalent to the present invention. Furthermore, the steps performing the above series of processes can naturally be performed in the order described, but are not necessarily required to be performed in chronological order. Some steps can be performed in parallel or independently of each other.
[0271] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.< / subject> < / subject>
Claims
1. A database upgrade method, characterized in that, The method includes: The script to obtain the first version of the database in the production environment and the script to obtain the second version of the database in the pre-production environment; Generate a database upgrade script based on the scripts of the first version database, the scripts of the second version database, and the full script comparator. After deploying the second version of the microservice application in the production environment, the database upgrade script is then executed. The script for obtaining the first version of the database in the production environment includes: Obtain the first database full script of the first version of the microservice program in the production environment; Obtain the full script of the second database corresponding to the first version database of the first version microservice program; Obtain the enumeration value of the attribute defined as an enumeration value or the enumeration value of the attribute tagged with an enumeration in the first version of the microservice program in the production environment. If the enumerated values in the full script of the first database and the full script of the second database are consistent with the enumerated values of the attributes, the script of the first version database is obtained. The script for obtaining the first database full set of the first version of the microservice program in the production environment includes: When the database is a relational database, the first version of the microservice program in the production environment is used to export the first full table script of the relational database. When the database is a non-relational database, the first version of the microservice program is used to export the full table script of the first non-relational database. The script for obtaining the full second database corresponding to the first version of the microservice program includes: When the database is a relational database, export the full script of the second database corresponding to the first version of the microservice program using the export command provided by the relational database; or When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the second database corresponding to the first version of the microservice program.
2. The database upgrade method according to claim 1, characterized in that, When the database is a non-relational database, the step of exporting the full table script of the first non-relational database through the first version of the microservice program includes: Scan the first version of the microservice program to obtain a list of the first preset objects that use documentation annotations; Obtain the name, type, and value of all attributes of the first preset object, and generate and export the full script of the first non-relational database.
3. The database upgrade method according to claim 1, characterized in that, When the database is a relational database, the step of exporting the full set of tables of the first relational database through the first version of the microservice program in the production environment includes: Scan the first version of the microservice program to obtain a list of second preset objects using table annotations, and form a first database table based on the second preset objects; Scan the microservice resource file package of the first version of the microservice program to obtain all target files, and form a second database table based on the target files; The union of the first database table and the second database table is determined as the full table script of the first relational database.
4. The database upgrade method according to claim 1, characterized in that, When the database is a non-relational database, the step of exporting the full table script of the first non-relational database through the first version of the microservice program includes: By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export the first full table script for a non-relational database.
5. The database upgrade method according to claim 1, characterized in that, Also includes: If the enumeration values in the full script of the first database and the full script of the second database are inconsistent with the enumeration values of the attributes, if the enumeration value in the full script of the first database is incorrect, then the first version of the microservice program is corrected; if the enumeration value in the full script of the second database is incorrect, then the first version of the database corresponding to the first version of the microservice program is corrected.
6. The database upgrade method according to claim 1, characterized in that, The script for obtaining the second version of the database in the pre-production environment includes: Obtain the full script of the third database for the second version of the microservice program in the pre-production environment; Obtain the full script of the fourth database corresponding to the second version database of the second version microservice program; Obtain the enumeration value of the attribute defined as an enumeration value or the enumeration value of the attribute tagged with an enumeration in the second version of the microservice program in the pre-production environment; If the enumerated values in the full scripts of the third and fourth databases are consistent with the enumerated values of the attributes, the script of the second version database is obtained.
7. The database upgrade method according to claim 6, characterized in that, Obtain the full script of the third database for the second version of the microservice program in the pre-production environment, including: Export the full table script of the second relational database using the second version of the microservice program in the pre-production environment; Export the full table script of the second non-relational database using the second version of the microservice program; Scan the second version of the microservice program to obtain a list of second preset objects that use documentation annotations; Obtain the name, type, and value of all attributes of the second preset object, and generate and export the full script of the first database.
8. The database upgrade method according to claim 7, characterized in that, Exporting the second version of the microservice program in the pre-production environment, including: Scan the second version of the microservice program to obtain a list of third preset objects that use table annotations, and form a third database table based on the third preset objects; Scan the microservice resource file package of the second version microservice program to obtain all target files, and form a fourth database table based on the target files; The union of the third and fourth database tables is determined as the second relational database full table script.
9. The database upgrade method according to claim 7, characterized in that, Using the second version of the microservice program, export the full table script for the second non-relational database, including: By combining the SpringData-jpa framework for manipulating data with the MongoDB database, the script iterates through document objects, their enumeration values, and nested objects to generate and export a full table of a second non-relational database.
10. The database upgrade method according to claim 6, characterized in that, Obtain the full scripts for the fourth database corresponding to the second version of the microservice program, including: When the database is a relational database, export the full script of the fourth database corresponding to the second version of the microservice program using the export command provided by the relational database; or When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the fourth database corresponding to the second version of the microservice program.
11. The database upgrade method according to claim 6, characterized in that, Also includes: If the enumeration values in the full scripts of the third and fourth databases are inconsistent with the enumeration values of the attributes, then if the enumeration value in the full script of the third database is incorrect, the second version of the microservice program is corrected; if the enumeration value in the full script of the fourth database is incorrect, the second version of the database corresponding to the second version of the microservice program is corrected.
12. The database upgrade method according to claim 1, characterized in that, Based on the scripts from the first and second versions of the database, and the full script comparator, a database upgrade script is generated, including: The differences between the scripts in the first version database and the scripts in the second version database are obtained through the full script comparator. Generate a database upgrade script based on the differences.
13. A database upgrade device, characterized in that, The device includes: The module is used to obtain the scripts for the first version of the database in the production environment and the second version of the database in the pre-production environment. The processing module is used to generate a database upgrade script based on the script of the first version database, the script of the second version database, and the full script comparator. The execution module is used to deploy the second version of the microservice program in the production environment and then execute the database upgrade script; The script for obtaining the first version of the database in the production environment includes: Obtain the first database full script of the first version of the microservice program in the production environment; Obtain the full script of the second database corresponding to the first version database of the first version microservice program; Obtain the enumeration value of the attribute defined as an enumeration value or the enumeration value of the attribute tagged with an enumeration in the first version of the microservice program in the production environment. If the enumerated values in the full script of the first database and the full script of the second database are consistent with the enumerated values of the attributes, the script of the first version database is obtained. The script for obtaining the first database full set of the first version of the microservice program in the production environment includes: When the database is a relational database, the first version of the microservice program in the production environment is used to export the first full table script of the relational database. When the database is a non-relational database, the first version of the microservice program is used to export the full table script of the first non-relational database. The script for obtaining the full second database corresponding to the first version of the microservice program includes: When the database is a relational database, export the full script of the second database corresponding to the first version of the microservice program using the export command provided by the relational database; or When the database is a non-relational database, export the data from the non-relational database, traverse the data to parse out the full script of the second database corresponding to the first version of the microservice program.
14. A database upgrade device, characterized in that, include: A processor, a memory storing a computer program, wherein the computer program, when executed by the processor, performs the method as described in any one of claims 1 to 12.
15. A computer-readable storage medium, characterized in that, A storage instruction that, when executed on a computer, causes the computer to perform the method as described in any one of claims 1 to 12.
Citation Information
Patent Citations
Structural difference processing method and system based on MYSQL
CN104881455A
Method, apparatus and storage medium for mapping class and database
CN109299332A