A method and apparatus for version upgrade of a database
By automatically obtaining and comparing the structured data of the database, the errors and complex problems caused by manual recording of incremental statements and cross-version upgrades are solved, and the database version upgrade of sequence and accuracy is achieved.
Patent Information
- Application Number
- CN202210756603.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-29
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2042-06-29
AI Technical Summary
The existing database version upgrade method relies on manual recording of improvement points to form incremental statements, which are prone to errors or conflicts. Cross-version upgrades are cumbersome and complicated, and cross-version upgrades cannot be achieved directly.
By obtaining structured data of the running version and the target version, automate differential comparisons and converting them into incremental statements, considering dependencies such as foreign key constraints to ensure the orderliness and accuracy of incremental statements.
It realizes automatic database version upgrade without manual collation, reduces the probability of errors, simplifies cross-version upgrade operations, and improves the accuracy and efficiency of upgrades.
Smart Images

Figure CN114969054B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the technical field of databases, and in particular, to a method, apparatus, computing device, and computer-readable storage medium for upgrading the version of a database. Background Art
[0002] With the development of computer technology, more and more technologies are applied in the financial field, and traditional finance is gradually transforming into financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, higher requirements are also put forward for technologies.
[0003] A database is the key data storage of an application system. When developers update and upgrade the application system, they often perform corresponding updates and upgrades on the database of the application system. The existing method for upgrading the version of a database is as follows: developers make a series of improvements to the database of version v1 to obtain the database of version v2, record this series of improvements during the improvement process, and convert this series of improvements into incremental statements; the user device installed with the database of version v1 obtains this incremental statement and executes this incremental statement on the basis of the database of version v1, so as to realize the update and upgrade of the database version and obtain the database of version v2.
[0004] In the above method, it is necessary for developers to manually record this series of improvements to obtain incremental statements. If multiple developers participate in the R & D, each developer records their own improvement points, and the total improvement points are summarized to form incremental statements based on the total improvement points. The more developers participate, or the more improvement points there are, the more likely it is that the formed incremental statements will have errors, omissions, or conflicts.
[0005] Moreover, in the above method, since the incremental statement is obtained based on the improvement points recorded by developers when improving the database v1, this incremental statement can only reflect the improvements between consecutive versions. Executing this incremental statement on the user device installed with the database of version v1 can only obtain the database of version v2. If you want to upgrade the database of version v1 on the user device to version v3, you need to first obtain the database of version v2 based on the incremental statement of v1-v2, and then obtain the database of version v3 based on the incremental statement of v2-v3. The cross-version upgrade process is very cumbersome and complex. If the incremental statement of v1-v2 or v2-v3 is lost, the cross-version upgrade from v1-v3 cannot be realized. Summary of the Invention
[0006] Embodiments of the present invention provide a method for upgrading the version of a database, which is used to automatically upgrade the running version database, without manual upgrade, saving manpower and time, and simplifying the operation of cross-version upgrade.
[0007] In a first aspect, an embodiment of the present invention provides a method for upgrading the version of a database, including:
[0008] Obtain the first structured data of the running version database in the running state and the second structured data of the target version database as the upgrade target; wherein, the structured data is used to classify and represent the data in the database through various set object types;
[0009] Perform a difference comparison on the first structured data and the second structured data according to each set object type to obtain difference structured data; wherein, when performing a difference comparison on a table object, if it is determined through the second structured data that there is a foreign key constraint in the target version database for the first table to reference the second table, then after performing the difference comparison on the second table through the first structured data and the second structured data, perform the difference comparison on the first table through the first structured data and the second structured data;
[0010] Convert the difference structured data into incremental statements; the incremental statements are used to upgrade the running version database to the target version database.
[0011] Since the first structured data can reflect the structured state of the running version database and the second structured data can reflect the structured state of the target version database, directly obtaining the first structured data and the second structured data and performing a difference comparison on the first structured data and the second structured data can obtain difference structured data that can reflect the state difference between the running version database and the target version database. Converting the difference structured data into incremental statements can perform version upgrade based on the incremental statements. When performing a difference comparison on a table object, if it is determined through the second structured data that there is a foreign key constraint in the target version database for the first table to reference the second table, then after performing the difference comparison on the second table through the first structured data and the second structured data, perform the difference comparison on the first table through the first structured data and the second structured data. Considering the situation where the table has a foreign key constraint, the obtained difference structured data can ensure orderliness, and the final incremental statements can be executed sequentially. The entire process is completed automatically without manual sorting and summarization, reducing the burden of human and material resources, reducing the error probability during the process of manually sorting incremental statements based on improvement points, ensuring the orderliness of the execution of incremental statements and the accuracy of the upgrade. And it simplifies the operation of cross-version upgrade.
[0012] Optionally, obtaining the first structured data of the running version database in the running state includes:
[0013] Query the metadata of each set object type corresponding to the running version database in each information table, and determine the first structured data of the running version database according to the metadata of each set object type.
[0014] By the above method, the steps of obtaining the first structured data are simplified, and the efficiency of obtaining structured data is improved.
[0015] Optionally, query the metadata of each set object type corresponding to the running version database in each information table, including:
[0016] Query the metadata of the table objects included in the running version database through the table information table;
[0017] Query the metadata of the column objects of any table included in the running version database through the column information table;
[0018] Query the metadata of the constraint objects of any table included in the running version database through the constraint information table;
[0019] Query the metadata of the index objects of any table included in the running version database through the index information table;
[0020] Query the metadata of the sequence objects included in the running version database through the sequence information table;
[0021] Query the metadata of the view objects included in the running version database through the view information table.
[0022] The obtained metadata is as comprehensive as possible, which can ensure more comprehensive differential structured data when performing subsequent differential comparisons. Upgrading based on the comprehensive differential structured data can improve the accuracy of version upgrade.
[0023] Optionally, obtain the second structured data of the target version database as the upgrade target, including:
[0024] Parse the status statement of the target version database as the upgrade target, and determine the second structured data of the target version database according to the parsing result.
[0025] Since the target version database and the running version database may not be located on the same server, the method of parsing the status statement is adopted instead of querying to obtain the second structured data, which can ensure cross-environment data security.
[0026] Optionally, parse the status statement of the target version database as the upgrade target, and determine the second structured data of the target version database according to the parsing result, including:
[0027] Obtain the status statement of the target version database as the upgrade target;
[0028] For any table creation statement in the status statement, extract the metadata of the table object at the first position of the table creation statement; extract the metadata of the constraint object of the table at the second position of the table creation statement; extract the metadata of the index object of the table at the third position of the table creation statement, and extract the metadata of the column object of the table at the fourth position of the table creation statement;
[0029] For any sequence creation statement in the status statement, extract the metadata of the sequence object at the fifth position of the sequence creation statement;
[0030] For any view creation statement in the status statement, extract the metadata of the view object at the sixth position of the view creation statement.
[0031] The obtained metadata is as comprehensive as possible, which can ensure more comprehensive differential structured data when performing subsequent differential comparisons. Upgrading based on the comprehensive differential structured data can improve the accuracy of version upgrade.
[0032] Optionally, perform a differential comparison on the first structured data and the second structured data according to each set object type to obtain differential structured data, including:
[0033] Perform a differential comparison of sequence objects through the first structured data and the second structured data;
[0034] Perform a differential comparison of table objects through the first structured data and the second structured data;
[0035] Perform a differential comparison of view objects through the first structured data and the second structured data.
[0036] The process of differential comparison should be sequential, so that the obtained incremental statements can be executed in sequence. Improve the accuracy of version upgrade.
[0037] Optionally, perform a differential comparison of table objects through the first structured data and the second structured data, including:
[0038] Perform a differential comparison of column objects through the first structured data and the second structured data;
[0039] Perform a differential comparison of constraint objects through the first structured data and the second structured data;
[0040] Perform a differential comparison of index objects through the first structured data and the second structured data.
[0041] The process of differential comparison should be sequential, so that the obtained incremental statements can be executed in sequence. Improve the accuracy of version upgrade.
[0042] In a second aspect, an embodiment of the present invention further provides a version upgrade device for a database, including:
[0043] An acquisition unit, configured to acquire first structured data of a running version database in a running state and second structured data of a target version database as an upgrade target; wherein, the structured data is used to classify and represent the data in the database through each set object type;
[0044] A comparison unit, configured to perform a difference comparison on the first structured data and the second structured data according to each set object type to obtain difference structured data; wherein, when performing a difference comparison on a table object, if it is determined through the second structured data that there is a foreign key constraint in the target version database that references a second table for a first table, then after performing a difference comparison on the second table through the first structured data and the second structured data, perform a difference comparison on the first table through the first structured data and the second structured data;
[0045] A conversion unit, configured to convert the difference structured data into incremental statements; the incremental statements are used to upgrade the running version database to the target version database.
[0046] Optionally, the acquisition unit is specifically configured to:
[0047] Query metadata of each set object type corresponding to the running version database in each information table, and determine the first structured data of the running version database according to the metadata of each set object type.
[0048] Optionally, the acquisition unit is specifically configured to:
[0049] Query metadata of table objects included in the running version database through a table information table;
[0050] Query metadata of column objects of any table included in the running version database through a column information table;
[0051] Query metadata of constraint objects of any table included in the running version database through a constraint information table;
[0052] Query metadata of index objects of any table included in the running version database through an index information table;
[0053] Query metadata of sequence objects included in the running version database through a sequence information table;
[0054] Query metadata of view objects included in the running version database through a view information table.
[0055] Optionally, the obtaining unit is specifically configured to:
[0056] Parse the status statement of the target version database that is the upgrade target, and determine the second structured data of the target version database according to the parsing result.
[0057] Optionally, the obtaining unit is specifically configured to:
[0058] Obtain the status statement of the target version database that is the upgrade target;
[0059] For any table creation statement in the status statement, extract the metadata of the table object at the first position of the table creation statement; extract the metadata of the constraint object of the table at the second position of the table creation statement; extract the metadata of the index object of the table at the third position of the table creation statement, and extract the metadata of the column object of the table at the fourth position of the table creation statement;
[0060] For any sequence creation statement in the status statement, extract the metadata of the sequence object at the fifth position of the sequence creation statement;
[0061] For any view creation statement in the status statement, extract the metadata of the view object at the sixth position of the view creation statement.
[0062] Optionally, the comparison unit is specifically configured to:
[0063] Perform a difference comparison of sequence objects through the first structured data and the second structured data;
[0064] Perform a difference comparison of table objects through the first structured data and the second structured data;
[0065] Perform a difference comparison of view objects through the first structured data and the second structured data.
[0066] Optionally, the comparison unit is specifically configured to:
[0067] Perform a difference comparison of column objects through the first structured data and the second structured data;
[0068] Perform a difference comparison of constraint objects through the first structured data and the second structured data;
[0069] Perform a difference comparison of index objects through the first structured data and the second structured data.
[0070] In a third aspect, an embodiment of the present invention further provides a computing device, including:
[0071] A memory for storing a computer program;
[0072] A processor for calling the computer program stored in the memory and executing the database version upgrade method listed in any of the above manners according to the obtained program.
[0073] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium storing a computer-executable program for causing a computer to execute the database version upgrade method listed in any of the above manners. Description of the Drawings
[0074] To more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for description in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention, and those of ordinary skill in the art can also obtain other drawings based on these drawings without creative efforts.
[0075] Figure 1 A schematic flowchart of database version upgrade provided by an embodiment of the present invention;
[0076] Figure 2 A schematic flowchart of obtaining first structured data provided by an embodiment of the present invention;
[0077] Figure 3a A schematic diagram of metadata provided by an embodiment of the present invention;
[0078] Figure 3b A schematic diagram of metadata provided by an embodiment of the present invention;
[0079] Figure 3c A schematic diagram of metadata provided by an embodiment of the present invention;
[0080] Figure 3d A schematic diagram of metadata provided by an embodiment of the present invention;
[0081] Figure 3e A schematic diagram of metadata provided by an embodiment of the present invention;
[0082] Figure 3f A schematic diagram of metadata provided by an embodiment of the present invention;
[0083] Figure 3g A schematic diagram of metadata provided by an embodiment of the present invention;
[0084] Figure 3h A schematic diagram of metadata provided by an embodiment of the present invention;
[0085] Figure 3i Schematic diagram of a kind of metadata provided by an embodiment of the present invention;
[0086] Figure 4 Flow schematic diagram of obtaining a second structured data provided by an embodiment of the present invention;
[0087] Figure 5 Schematic diagram of a kind of status statement provided by an embodiment of the present invention;
[0088] Figure 6 Schematic diagram of a kind of second structured data provided by an embodiment of the present invention;
[0089] Figure 7 Flow schematic diagram of comparing the differences between a first structured data and a second structured data provided by an embodiment of the present invention;
[0090] Figure 8a Schematic diagram of a kind of first structured data provided by an embodiment of the present invention;
[0091] Figure 8b Schematic diagram of a kind of second structured data provided by an embodiment of the present invention;
[0092] Figure 9 Flow schematic diagram of comparing the differences between a first structured data and a second structured data provided by an embodiment of the present invention;
[0093] Figure 10 Flow schematic diagram of comparing the differences between table objects in a first structured data and table objects in a second structured data provided by an embodiment of the present invention;
[0094] Figure 11 Schematic diagram of a device for version upgrade of a database provided by an embodiment of the present invention;
[0095] Figure 12 Schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Detailed implementation manners
[0096] To make the purpose, implementation manners and advantages of the present application clearer, the following will clearly and completely describe the exemplary implementation manners of the present application with reference to the accompanying drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only a part of the embodiments of the present application, rather than all of the embodiments.
[0097] Based on the exemplary embodiments described in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope protected by the appended claims of this application. In addition, although the disclosure in this application is introduced according to one or several exemplary instances, it should be understood that each aspect of these disclosures can also constitute a complete implementation manner alone.
[0098] It should be noted that the brief description of the terms in this application is only for the convenience of understanding the following described embodiments, rather than intending to limit the embodiments of this application. Unless otherwise specified, these terms should be understood in their ordinary and common meanings.
[0099] In this application, the terms "first", "second", "third", etc. in the specification, claims and the above-mentioned drawings are used to distinguish similar or like objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise indicated (Unless otherwise indicated). It should be understood that such terms can be interchanged under appropriate circumstances, for example, it can be implemented in an order other than those given in the illustration or description of the embodiments of this application.
[0100] In addition, the terms "comprising" and "having" and any variations thereof are intended to cover but not exclude inclusion. For example, a product or device comprising a series of components does not necessarily have to be limited to those clearly listed components, but may include other components not clearly listed or inherent to these products or devices.
[0101] In the existing methods for upgrading the version of a database, developers need to record the improvement points during the improvement process and form incremental statements based on the improvement points. For example, developers made a series of modifications on the basis of the v1 version of the database, such as adding m rows and reducing n columns... to obtain the v2 version of the database. A total of 1000 improvement points were recorded during this process, and incremental statements were obtained based on these 1000 improvement points. Thus, for other user devices installed with the v1 version of the database, only by obtaining the incremental statements can the v1 version of the database be upgraded to obtain the v2 version of the database.
[0102] The improvement points may come from the records of multiple developers. Then, when summarizing these improvement points, the order of the improvement points needs to be considered, and the order of statement execution also needs to be considered during the process of forming incremental statements, which is very time-consuming and laborious, and is extremely prone to errors, omissions or conflicts.
[0103] Moreover, the acquisition of incremental statements in the above method depends on the records of R & D personnel during the R & D process. And R & D personnel must improve on the basis of a version to obtain a continuous version database. Suppose the version upgrade process of a certain database by R & D personnel is: v1 - v2 - v3. Then, R & D personnel can only improve the v1 version of the database to obtain v2, and it is impossible to directly obtain v3 after improving the v1 version of the database. Therefore, R & D personnel can only record the first improvement point during the upgrade from v1 to v2, and obtain the first incremental statement based on the first improvement point; record the second improvement point during the upgrade from v2 to v3, and obtain the second incremental statement based on the second improvement point. If a user device wants to directly upgrade from the v1 version to the v3 version, it can only first obtain the first incremental statement, upgrade to the v2 version, then obtain the second incremental statement, and upgrade to the v3 version. The method for the user device to achieve cross - version upgrade is very cumbersome and complex. If the first incremental statement or the second incremental statement is lost, then for this user device, it cannot be upgraded to v3.
[0104] An embodiment of the present invention provides a method for upgrading the version of a database, which does not require R & D personnel to record improvement points during R & D, and form incremental statements based on the improvement points. Instead, it uses a method of describing the state to extract the structured data of the running version database in the running state and the target version database as the upgrade target, and directly obtains incremental statements based on the structured data, reducing the error probability during the process of manually sorting out incremental statements based on improvement points, ensuring the sequentiality of the execution of incremental statements and the accuracy of the upgrade. And it simplifies the operation of cross - version upgrade.
[0105] Figure 1 A possible method for upgrading the version of a database provided by an embodiment of the present invention is shown, including:
[0106] Step 101, obtain the first structured data of the running version database in the running state and the second structured data of the target version database as the upgrade target; wherein, the structured data is used to classify and represent the data in the database through various set object types.
[0107] Step 102, perform a difference comparison on the first structured data and the second structured data according to each set object type to obtain difference structured data; wherein, when performing a difference comparison on a table object, if it is determined through the second structured data that there is a foreign key constraint in the target version database referring to a second table for a first table, then after performing a difference comparison on the second table through the first structured data and the second structured data, perform a difference comparison on the first table through the first structured data and the second structured data.
[0108] Step 103: Convert the differential structured data into incremental statements, which are used to upgrade the running version database to the target version database.
[0109] In step 101, the running version database represents the structural state of the database to be upgraded currently. For example, it is a database of version v1. The target version database is the upgrade target of the running version database. For example, it is a database of version v2, v3, v4, etc. The embodiments of the present invention do not limit this.
[0110] The running version database runs on any server. For example, a database of version v1 runs on a user's terminal device. This database of version v1 is to be upgraded. The target version database can run on another server or may not be running. For example, a database of version v3 runs on a user's tablet computer. Or, for example, the database of version v3 is not running on a certain server, but is obtained by a developer improving the database of version v2 on a test machine. The above are only examples, and the embodiments of the present invention do not limit this.
[0111] The embodiments of the present invention do not limit the method for obtaining the first structured data. For example, the query method or the parsing method can be used. The query method refers to querying the metadata of each set object type corresponding to the running version database in each information table, and determining the first structured data of the running version database according to the metadata of each set object type. The parsing method refers to parsing the status statement of the running version database and determining the first structured data of the running version database according to the parsing result.
[0112] The embodiments of the present invention do not limit the method for obtaining the second structured data. For example, the query method or the parsing method can be used. The query method refers to querying the metadata of each set object type corresponding to the target version database in each information table, and determining the second structured data of the target version database according to the metadata of each set object type. The parsing method refers to parsing the status statement of the target version database and determining the second structured data of the target version database according to the parsing result.
[0113] Among them, the structured data is classified and characterized for the data in the database through various set object types. The embodiments of the present invention do not limit the set object types, for example, including any one or more of the following: sequence object, table object, column object, index object, constraint object, and view object. Classifying and characterizing the data in the running version database according to the above set object types, then the first structured data includes at least any one of the sequence object, table object, column object, index object, constraint object, and view object; classifying and characterizing the data in the target version database according to the above set object types, then the second structured data includes at least any one of the sequence object, table object, column object, index object, constraint object, and view object.
[0114] In step 102, according to each set object type, the first structured data and the second structured data are compared for differences to obtain differential structured data. For example, the first structured data includes a sequence object, a table object, and a column object, and the second structured data includes a sequence object, a table object, and a column object. Then, when comparing for differences, the sequence objects of the first structured data are compared with the sequence objects of the second structured data; the table objects of the first structured data are compared with the table objects of the second structured data; the column objects of the first structured data are compared with the column objects of the second structured data.
[0115] It should be noted that when forming incremental statements, the execution order of the statements should be considered. Then, when comparing for differences, the orderliness of the comparison should be emphasized, so as not to cause omissions or conflicts in the incremental statements. For example, when there is a dependency relationship between the first table and the second table, and the change of the first table depends on the change of the second table, then in the formed incremental statements, the statement corresponding to the second table should be before the statement corresponding to the first table. In this way, when executing the incremental statements, the incremental statement corresponding to the second table is executed first, and then the incremental statement corresponding to the first table is executed. When comparing for differences, the second table should be compared for differences first, and then the first table should be compared for differences.
[0116] Specifically, in the process of comparing for differences, traverse the table objects in the second structured data. If there is a foreign key constraint of the first table referring to the second table, it means that the change of the first table depends on the change of the second table. Then, after comparing the differences of the second table through the first structured data and the second structured data, compare the differences of the first table through the first structured data and the second structured data. In this way, the obtained incremental statements have orderliness. Based on this incremental statement for upgrading, the target version database can be obtained.
[0117] In step 103, the differential structured data is converted into incremental statements, and the incremental statements are used to upgrade the running version database to the target version database.
[0118] The embodiments of the present invention do not limit the manner of converting differential structured data into incremental statements. Different languages have different conversion methods, and those skilled in the art can choose according to requirements and actual situations.
[0119] For example, a running version database v1 runs on user device A, and a target version database v3 runs on user device B. User device A can execute the methods of steps 101-103 to obtain the first structured data of v1 and the second structured data of v3 respectively. After performing differential comparison, differential structured data is obtained, and then the differential structured data is converted into incremental statements. Then, when user device A executes these incremental statements, v1 can be upgraded to v3.
[0120] It can be seen that the method provided by the embodiments of the present invention can run on any user device, and this user device can complete automatic upgrade by itself through steps 101-103. Moreover, there is no step for R & D personnel to record improvement points and form incremental statements based on the improvement points. Instead, the concept of version increment is weakened, and a state description method is adopted. This user device completes the version upgrade by itself without the assistance of R & D personnel. There is no need to obtain incremental statements for upgrading from v1 to v2 and from v2 to v3, and cross-version upgrade can be achieved.
[0121] Since the first structured data can reflect the structured state of the running version database and the second structured data can reflect the structured state of the target version database, directly obtaining the first structured data and the second structured data, and performing differential comparison on the first structured data and the second structured data to obtain the differential structured data can reflect the state difference between the running version database and the target version database. Converting the differential structured data into incremental statements can perform version upgrade based on the incremental statements. When performing differential comparison on table objects, if it is determined through the second structured data that there is a foreign key constraint in the target version database for the first table to reference the second table, after performing differential comparison on the second table through the first structured data and the second structured data, and then performing differential comparison on the first table through the first structured data and the second structured data, considering the situation where the table has a foreign key constraint, the obtained differential structured data can ensure orderliness, and the final incremental statements can be executed sequentially. The whole process is completed automatically without manual collation and summary, reducing the burden of human and material resources, reducing the error probability during the process of manually sorting out incremental statements based on improvement points, ensuring the orderliness of incremental statement execution and the accuracy of upgrade. And it simplifies the operation of cross-version upgrade.
[0122] In some embodiments, since the running version database is a running library, the query method can simplify the steps of obtaining structured data and improve the efficiency of obtaining structured data. The steps of obtaining the first structured data by the query method are introduced in detail below.
[0123] The running version database is a relational database. Metadata of each set object type in the running library is stored in the relational database, so it can be obtained through query. Different relational databases may use different query methods. Taking the running version database as a Mysql database as an example, the steps of obtaining the first structured data by the query method are introduced as Figure 2 shown.
[0124] Step 201: Query the metadata of the table objects included in the running version database through the table information table.
[0125] Metadata of each table object of each database is stored in the table information table information_schema.TABLES. Therefore, in the table information table, with the restriction condition: TABLE_SCHEMA is the name demo of the running version database, the metadata of each table object included in the running version database demo can be obtained. As Figure 3a shown, the metadata of two table objects, table_name001 and table_name002, is obtained. Among them, for any table object, the metadata of the table object is marked: engine name, character set, and the current auto-increment sequence value of the table.
[0126] Step 202: Query the metadata of the column objects of any table included in the running version database through the column information table.
[0127] Metadata of each column object of each database is stored in the column information table information_schema.COLUMNS. Therefore, in the column information table, with the restriction conditions: TABLE_SCHEMA is the name demo of the running version database, and TABLE_NAME is the name of any table object, such as table_name001, the metadata of each column object included in table_name001 of the running version database demo can be obtained. As Figure 3b shown, the metadata of each column object in table_name001 is obtained, and the names of each column object are marked in the COLUMN_NAME column. Among them, for any column object, the metadata of the column object is marked: sorting position, default value, whether it is allowed to be null, data type and length, character set, whether it is the primary key, whether it is auto-incremented, and remarks.
[0128] Step 203: Query the metadata of the constraint objects of any table included in the running version database through the constraint information table.
[0129] The constraint information table information_schema.TABLE_CONSTRAINTS stores the constraint names and constraint types of the constraint objects of each database. Therefore, in the constraint information table, with the restriction conditions: TABLE_SCHEMA is the name of the running version database demo, and TABLE_NAME is the name of any table object, such as table_name001, the constraint names and constraint types of the constraint objects included in table_name001 of the running version database demo can be obtained. As Figure 3c shown, the CONSTRAINT_NAME column indicates the constraint names of the constraint objects, and the CONSTRAINT_TYPE column indicates the constraint types of the constraint objects. The constraint types include foreign key constraints, primary key constraints, and unique constraints.
[0130] If the constraint type of a certain constraint object is a foreign key constraint, obtain the first metadata of the constraint object from the reference constraint information table and the key column usage information table. As Figure 3d shown, obtain the update and delete action information of the constraint object from the reference constraint information table information_schema.REFERENTIAL_CONSTRAINTS; as Figure 3e shown, obtain the external associated table and external associated column information of the constraint object from the key column usage information table information_schema.KEY_COLUMN_USAGE.
[0131] It can be seen from Figure 3c that there is a foreign key constraint for the table object table_name001; it can be seen from Figure 3e that there is a foreign key constraint for the column object reference_id of the table object table_name001, and this foreign key constraint references the column object keyname of the table object table_name002. Therefore, when performing difference comparison, the difference comparison of the table object table_name002 should be performed first, and then the difference comparison of the table object table_name001.
[0132] If the constraint type of a certain constraint object is a primary key constraint or a unique constraint, obtain the second metadata of the constraint object from the key column usage information table. As Figure 3f shown, obtain the columns associated with the constraint object and the position sequence number information of the columns from the key column usage information table information_schema.KEY_COLUMN_USAGE.
[0133] Step 204: Query the metadata of the index object of any table included in the running version database through the index information table.
[0134] The first index information table information_schema.INNODB_SYS_INDEXES stores the index ID values of the index objects of each database. Therefore, in the first index information table, the restriction condition is that table_id is equal to the table ID value. For example, if the table ID value of table table_name001 is 1262, the index ID values of the index objects included in table_name001 of the running version database demo can be obtained. As Figure 3g shown, the NAME column indicates the names of the index objects, and the INDEX_ID column indicates the index ID values of the index objects. Then, according to the index ID value, the metadata of the index object: the associated column name and the position sequence number of the column in the index can be found from the second index information table information_schema.INNODB_SYS_FIELDS. As Figure 3h shown.
[0135] Step 205: Query the metadata of the view object included in the running version database through the view information table.
[0136] The view information table information_schema.VIEWS stores the metadata of the view objects of each database. Therefore, in the view information table, the restriction conditions are that TABLE_SCHEMA is the name of the running version database, which is demo, and TABLE_NAME is the name of any table object. Then, the metadata of the view objects included in table_name001 of the running version database demo can be obtained. As Figure 3i shown, the metadata of the view objects in the running version database demo is obtained: view name, source SQL, algorithm, and owner.
[0137] Step 206: Query the metadata of the sequence object included in the running version database through the sequence information table.
[0138] The MySQL database does not support querying the metadata of sequence objects, but other relational databases support it. For example, Oracle or PostgreSQL, etc. This will not be elaborated one by one here.
[0139] The obtained metadata is as comprehensive as possible, which can ensure that more comprehensive differential structured data can be obtained during subsequent differential comparison. Upgrading based on the comprehensive differential structured data can improve the accuracy of version upgrade.
[0140] In some embodiments, since the target version database and the running version database are not necessarily located on the same host, if the query method is still used to obtain the second structured data, the server installing the running version database needs to access the server installing the target version database, which affects data security. Therefore, in order to ensure cross-environment data security, in this embodiment, the query method is not used to obtain the second structured data, but the parsing method is used.
[0141] The parsing method is to parse the status statement of the target version database that is the upgrade target, and determine the second structured data of the target version database according to the parsing result. The steps of obtaining the second structured data through the parsing method are introduced in detail below, as Figure 4 shown.
[0142] Step 401: Obtain the status statement of the target version database that is the upgrade target.
[0143] Step 402: For any table creation statement in the status statement, extract the metadata of the table object at the first position of the table creation statement; extract the metadata of the constraint object of the table at the second position of the table creation statement; extract the metadata of the index object of the table at the third position of the table creation statement, and extract the metadata of the column object of the table at the fourth position of the table creation statement.
[0144] Step 403: For any sequence creation statement in the status statement, extract the metadata of the sequence object at the fifth position of the sequence creation statement.
[0145] Step 404: For any view creation statement in the status statement, extract the metadata of the view object at the sixth position of the view creation statement.
[0146] In step 401, obtain the status statement of the target version database that is the upgrade target. For example, the running version database v1 is installed on the user device A, and the target version database v3 is installed on the user device B. The user device A or the user device B exports the structure of the target version database v3 to obtain the status statement of the target version database v3. The status statement contains one or more pieces of information of the sequence object, table object, column object, index object, constraint object, and view object. However, different from the metadata in each information table in the query method, the status statement here is unstructured data.
[0147] For example, if the target version database v3 is a MySQL database, the obtained status statement is as Figure 5As shown. Among them, it contains a lot of information about the table object: table name table_name001, engine InnoDB, character set utf8, etc.; it also contains column identifier id, column type type, namespace namespace, column name name, path path, status status, creation time created_at, update time updated_at, etc. There are also primary key constraints, unique index idx_u_table_name001_ns_n and ordinary index idx_table_name001_p information. These information are the expected status of table table_name001.
[0148] It can be seen that this is unstructured data. Steps 402 - 404 are the process of parsing the status statement.
[0149] In step 402, the semicolon is used as the identifier to split the status statement. Taking the Figure 5 status statement shown as an example, in Figure 5 lines 1 - 15 form a statement, which is named statement 1 for convenient description later; lines 16 - 33 form a statement, which is named statement 2 here.
[0150] Judge the type of the statement according to the beginning of the statement. If the beginning of the statement conforms to the CREATE TABLE pattern, then the statement is a table creation statement; if the beginning of the statement conforms to the CREATE xxxx VIEW pattern, then the statement is a view creation statement; if the beginning of the statement conforms to the CREATE SEQUENCE pattern, then the statement is a sequence creation statement.
[0151] In Figure 5 the example, statement 1 is a table creation statement; statement 2 is a view creation statement; Figure 5 There is no sequence creation statement.
[0152] For any table creation statement, extract the metadata of the table object, the metadata of the constraint object, the metadata of the index object, and the metadata of the column object at the first position, second position, third position, and fourth position of the table creation statement respectively.
[0153] (1) In Figure 5 the example, after extracting the CREATE TABLE keyword, take the word before the left parenthesis as the name of the table object: table_name001. Take the string after the right parenthesis (on line 15) as the table attribute string to be parsed, and match it according to the name = value pattern to parse the table attribute string, and get that the engine name of this table object is InnoDB and the character set is utf8. Thus, the metadata of this table object is obtained.
[0154] (2)The content in parentheses is segmented by commas as delimiters, and each part after segmentation is a column object, an index object, or a constraint object. When the character starts with the keywords PRIMARY KEY / UNIQUE KEY / CONSTRAINT, it enters the constraint object parsing; when the character starts with the keyword KEY, it enters the index object parsing; otherwise, it enters the column object parsing.
[0155] Among them, when performing constraint object parsing, if it starts with PRIMARY KEY, record the metadata of the primary key constraint: use PRIMARY as the name of the constraint object, and the content in the parentheses after the keyword PRIMARY KEY as the name of the column where the constraint object is located; use the name of the table object obtained in the first position as the name of the table where the constraint object is located; use PRIMARY KEY as the constraint type of the constraint object. For example, in Figure 5 line 11 of [], the name of the column where the constraint object is located can be extracted as "id", and table_name001 obtained when parsing the table object is also the name of the table where the constraint object is located; it can also be determined that the constraint type of the constraint object is PRIMARY KEY.
[0156] Among them, when performing constraint object parsing, if it starts with UNIQUE KEY, record the metadata of the unique constraint: use the content between the keyword UNIQUE KEY and the left parenthesis as the name of the constraint object, and the content in the parentheses after UNIQUE KEY as the name of the column where the constraint object is located; use the name of the table object obtained in the first position as the name of the table where the constraint object is located; use UNIQUE KEY as the constraint type of the constraint object. For example, in Figure 5 line 12 of [], the name of the constraint object can be extracted as "idx_u_table_name001_ns_n"; the names of the columns where the constraint object is located are "namespace" and "name", and table_name001 obtained when parsing the table object is also the name of the table where the constraint object is located; it can also be determined that the constraint type of the constraint object is UNIQUE KEY.
[0157] Among them, when parsing the constraint object, if it starts with CONSTRAINT, record the metadata of the foreign key constraint: the content between the keyword CONSTRAINT and FOREIGN KEY is used as the name of the constraint object, and the content in the parentheses after the keyword FOREIGN KEY is used as the name of the column where the constraint object is located; the name of the table object obtained in the first position is used as the name of the table where the constraint object is located; FOREIGN KEY is used as the constraint type of the constraint object; the characters between the keyword REFERENCES and the left parenthesis are used as the name of the table referenced by the constraint object; the content in the parentheses after the keyword REFERENCES is the name of the column referenced by the constraint object; the word after the keyword ON UPDATE is used as the update action; the word after the keyword ON DELETE is used as the delete action. For example, in Figure 5 at line 14, it is possible to extract that the name of the constraint object is "fk_table_name001_id"; the name of the column where the constraint object is located is "reference_id"; the name of the table referenced by the constraint object is table_name002; the name of the column referenced by the constraint object is id; table_name001 obtained when parsing the table object is also the name of the table where the constraint object is located; it can also be determined that the constraint type of the constraint object is FOREIGN KEY.
[0158] (3)When the character starts with the keyword KEY, enter the index object parsing.
[0159] The content between the keyword KEY and the left parenthesis is used as the name of the index object; the content in the parentheses is used as the name of the column where the index object is located; the name of the table object obtained in the first position is used as the name of the table where the constraint object is located. For example, in Figure 5 at line 13, it is possible to extract that the name of the index object is "idx_table_name001_p"; the name of the column where the index object is located is "path"; table_name001 obtained when parsing the table object is also the name of the table where the index object is located.
[0160] (4)Except for characters starting with the keywords PRIMARY KEY / UNIQUE KEY / CONSTRAINT and KEY, all will enter the column object parsing.
[0161] The first word in the parentheses is used as the name of the column object. For example, Figure 5 at line 2, the name of the column object is "id"; the second word is used as the data type of the column object. For example, Figure 5On the second line, the data type of the column object is "bigint"; if the keyword NULL exists, the value of "whether null is allowed" for this column object is "yes", if the keyword NOT NULL exists, the value of "whether null is allowed" for this column object is "no"; if the keyword DEFAULT exists, take the first complete word or string after it as the value of "default value"; if the keyword COMMENT exists, take the first complete word or string after it as the value of "comment"; if the keyword AUTO_INCREMENT exists, the "auto-increment sequence value" of this column object is yes, otherwise it is no; the remaining unparsed content is the additional value.
[0162] The above method can be used to Figure 5 parse the 2nd - 10th lines as shown, and obtain the metadata of each column object in this table.
[0163] In step 403, for any sequence creation statement in the status declaration statement, extract the metadata of the sequence object at the fifth position in the sequence creation statement.
[0164] Take the first word after the keyword SEQUENCE as the name of the sequence object; take the first numerical value after the keyword INCREMENT BY as the "step value" of this sequence object, if there is no keyword INCREMENT BY, the "step value" of this sequence object is 1; take the first numerical value after the keyword START WITH as the "starting value" of this sequence object, if there is no keyword START WITH, the "starting value" of this sequence object is 0; take the first numerical value after the keyword MINVALUE as the "minimum value" of this sequence object, if there is no keyword MINVALUE, the "minimum value" of this sequence object is -1, indicating no limit; take the first numerical value after the keyword MAXVALUE as the "maximum value" of this sequence object, if there is no keyword MAXVALUE, the "maximum value" of this sequence object is -1, indicating no limit; if the keyword NOCYCLE exists, set the "whether to cycle" of this sequence object to no, otherwise it is yes.
[0165] Since the Mysql database does not support the extraction of metadata of sequence objects, therefore in Figure 5 the example, there is no sequence creation statement, and thus the above information cannot be extracted. However, other relational databases can. This will not be elaborated here.
[0166] Step 404, for any view creation statement in the status declaration statement, extract the metadata of the view object at the sixth position in the view creation statement.
[0167] After extracting the keyword VIEW, take the word before the keyword AS as the name of the view object; take all the content after the keyword AS as the source SQL content; take the word after the keyword ALGORITHM as the algorithm value.
[0168] For example, parsing lines 17 - 33 in Figure 5 can obtain the metadata of a series of views.
[0169] After parsing in the above - mentioned manner, the second structured data is obtained, as shown in Figure 6 It can be seen that tree - shaped data is obtained, that is, a kind of structured data.
[0170] After obtaining the first structured data by the query method and the second structured data by the parsing method, the first structured data and the second structured data may have different formats, so the formats can be unified for easy comparison.
[0171] In some embodiments, when comparing the differences between the first structured data and the second structured data, first compare the differences of the table objects, and then compare the differences of the views.
[0172] The specific comparison order can be as follows, as shown in Figure 7 .
[0173] Step 701, compare the differences of the sequence objects through the first structured data and the second structured data.
[0174] Step 702, compare the differences of the table objects through the first structured data and the second structured data.
[0175] Step 703, compare the differences of the view objects through the first structured data and the second structured data.
[0176] Among them, the comparison of the differences of the sequence objects in step 701 can be placed before or after any step, as long as it is ensured that the differences of the table objects are compared first and the differences of the views are compared later. Those skilled in the art can freely choose.
[0177] Among them, in step 702, the following steps are included: compare the differences of the column objects through the first structured data and the second structured data; compare the differences of the constraint objects through the first structured data and the second structured data; compare the differences of the index objects through the first structured data and the second structured data. The above comparisons are not in a specific order, and those skilled in the art can freely choose.
[0178] During the process of version upgrade, if the upgrade fails due to errors in executing incremental statements or other reasons, then to ensure transactionality, it is necessary to roll back the executed upgrade process. Therefore, in the existing technology, developers not only need to manually organize incremental statements according to a series of improvements, but also need to manually organize rollback statements according to a series of improvements.
[0179] In the process of forming rollback statements, the execution order of the statements needs to be considered. The more developers involved in the research and development, or the more improvement points, the more likely it is that errors, omissions, or conflicts will occur in the formed incremental statements / rollback statements.
[0180] An embodiment of the present invention provides a method for obtaining rollback statements, which directly and automatically obtains rollback statements during the process of differential comparison.
[0181] The following uses a specific embodiment to introduce the above-mentioned differential comparison process.
[0182] Figure 8a Shows a schematic diagram of a possible first structured data; Figure 8b Shows a schematic diagram of a possible second structured data.
[0183] Figure 9 Shows a comparison flowchart for differentially comparing the first structured data and the second structured data. v1 represents the running version database; v2 represents the target version database.
[0184] Take Figure 8a the first structured data shown by Figure 8b and the second structured data shown as an example to introduce the comparison process of differential comparison in detail.
[0185] (1) It is judged that there are no sequence objects in both v1 and v2, so the table object comparison is entered.
[0186] (2) It is judged that there is a table object in v1 or there is a table object in v2. Yes, so the table objects with the same name in v1 and v2 are found, and table_name001 and table_name002 are found.
[0187] It is judged whether all the metadata of table_name001 and table_name002 are equal. The conclusion is that they are not equal, so the detailed comparison of the table objects is entered. The detailed comparison of the table objects is described in detail below and will not be elaborated here.
[0188] Find the table objects that exist in v1 but do not exist in v2. In this example, there are none; find the table objects that do not exist in v1 but exist in v2. In this example, there are none.
[0189] (3) Determine if there is a view object in v1 or v2. If yes, find the view objects with the same name in v1 and v2; 0 objects are found, proceed to the next step.
[0190] Find the view objects that exist in v1 but not in v2. 0 views are found, proceed to the next step.
[0191] Find the view objects that do not exist in v1 but exist in v2. 1 view is found: all_data, generate the structured data for creating the view all_data.
[0192] Figure 10 Shown is a comparison flow chart for comparing the table objects in the first structured data and the table objects in the second structured data. v1 represents the running version database; v2 represents the target version database.
[0193] Take Figure 8a the schematic first structured data and Figure 8b the schematic second structured data as an example to introduce in detail the comparison process for the differences in table objects.
[0194] (1) Determine if the table table_name001 has column definition data in v1. Therefore, find the column objects with the same name in v1 and v2 for the table table_name001. The column objects are found: column identifier id, type type, namespace namespace, path path, status status, reference identifier reference_id, creation time created_at, update time updated_at.
[0195] Traverse the column objects to compare whether all the metadata between v1 and v2 is equal. The conclusion is that they are equal.
[0196] Find the column objects that exist in v1 but not in v2 for the table table_name001; 0 columns are found, proceed to the next step.
[0197] Find the column objects that do not exist in v1 but exist in v2 for the table table_name001; the column object is found: name, generate the structured data for creating the name column of the table table_name001.
[0198] (2) Determine if the table table_name001 has column definition data in v1. Find the index objects with the same name in v1 and v2 for the table table_name001. The index object is found: idx_u_table_name001_ns_n.
[0199] Traverse the index objects to compare whether all the metadata between v1 and v2 is equal. The conclusion is that they are equal.
[0200] Find the index objects that exist in v1 but not in v2 for table table_name001; 0 index objects are found, proceed to the next step.
[0201] Find the index objects that do not exist in v1 but exist in v2 for table table_name001. The index object found is: idx_table_name001_p. Generate the structural data for creating the idx_table_name001_p index for table table_name001.
[0202] (3) Determine if there is constraint definition data for table table_name001 in v1. Find the constraint objects with the same name in v1 and v2 for table table_name001. The constraint objects found are: PRIMARY, table_name001_FK.
[0203] Traverse the constraint objects to compare whether all metadata between v1 and v2 are equal. The conclusion is that they are equal.
[0204] Find the constraint objects that exist in v1 but not in v2 for table table_name001; 0 constraint objects are found, proceed to the next step.
[0205] Find the constraint objects that do not exist in v1 but exist in v2 for table table_name001; 0 constraints are found.
[0206] Compare the differences between table_name002 in v1 and v2 in the same way. After completion, return to the comparison step of view objects.
[0207] Based on the above comparison results, the differential structured data obtained is:
[0208] Differential structured data 1: New column added to table table_name001: name; Object: Column; Belonging table: table_name001; Operation: Add; Data:
[0209] 1. {
[0210] 2. "name":"name",
[0211] 3. "data_type":"varchar(255)",
[0212] 4. "nullable":false,
[0213] 5. "default":null,
[0214] 6. "comment": null,
[0215] 7. "auto_increment": false,
[0216] 8. "extra": null
[0217] 9.}
[0218] Differential structured data 2: Add an index idx_u_table_name001_n to the new data table table_name001; Object: Index; Belonging table: table_name001; Operation: Add; Data:
[0219] 1. {
[0220] 2. "name": "idx_table_name001_pidx_u_table_name001_n",
[0221] 3. "unique": false true,
[0222] 4. "columns":
[0223] 5. "namepath" 6. ]
[0225] 7.}
[0226] Differential structured data 3: Add a new data view: all_data; Object: View; Operation: Add; Data:
[0227] 1. {
[0228] 2. "name": "all_data",
[0229] It should be noted that there seems to be an error in "unique": false true in the original text. It should probably be "unique": false.3. "sql": "select `tn1`.`id` AS `id`, `tn1`.`type` AS `type`, `tn1`.`namespace` AS `namespace`, `tn1`.`name` AS `name`, `tn1`.`path` AS `path`, `tn1`.`status` AS `status`, `tn1`.`reference_id` AS `reference_id`, `tn1`.`created_at` AS `created_at`, `tn1`.`updated_at` AS `updated_at`, `tn2`.`keyname` AS `keyname` from (`table_name001` `tn1` left join `table_name002` `tn2` on ((`tn1`.`reference_id` = `tn2`.`keyname`)))",
[0230] 4. "algorithm": null
[0231] 5.}
[0232] Convert the above 3 differential structured data into incremental statements. Taking the database as Mysql as an example, the incremental SQL statements are as follows:
[0233] ALTER TABLE table_name001 ADD `name` varchar(255) NOT NULL;
[0234] ALTER TABLE table_name001 ADD UNIQUE INDEX idx_table_name001_pidx_u_table_name001_n(`namepath`);
[0235] CREATE OR REPLACE
[0236] VIEW `all_data` AS
[0237] select
[0238] `tn1`.`id` AS `id`,
[0239] `tn1`.`type` AS `type`,
[0240] `tn1`.`namespace` AS `namespace`,
[0241] `tn1`.`name` AS `name`,
[0242] `tn1`.`path` AS `path`,
[0243] `tn1`.`status` AS `status`,
[0244] `tn1`.`reference_id` AS `reference_id`,
[0245] `tn1`.`created_at` AS `created_at`,
[0246] `tn1`.`updated_at` AS `updated_at`,
[0247] `tn2`.`keyname` AS `keyname`
[0248] from
[0249] (`table_name001` `tn1`
[0250] left join `table_name002` `tn2` on
[0251] ((`tn1`.`reference_id` = `tn2`.`keyname`)))
[0252] The rollback SQL statements are as follows:
[0253] ALTER TABLE table_name001 DROP COLUMN `name`;
[0254] ALTER TABLE table_name001 DROP INDEX idx_table_name001_pidx_u_table_name001_n;
[0255] DROP VIEW `all_data`
[0256] Since we perform the comparison in sequence during the difference comparison process, first comparing the table objects and then the view objects; in the comparison of table objects, first check whether any table object has a foreign key constraint. If so, first perform the difference comparison of the referenced table of the foreign key constraint, and then perform the difference comparison of the table object. The incremental SQL statements obtained in this way can be executed in sequence. Therefore, by executing the incremental SQL statements on the basis of the running version database, it can be upgraded to the target version database without caring about how many version increments there are between the running version database and the target version database. If the upgrade fails during the process, executing the rollback statement can roll back to the running version database.
[0257] Based on the same technical concept, Figure 11 Exemplarily shows the structure of a database version upgrade device provided by an embodiment of the present invention, and this structure can execute the process of database version upgrade.
[0258] As Figure 11 shown, the device specifically includes:
[0259] An acquisition unit 1101, configured to acquire first structured data of a running version database in a running state and second structured data of a target version database as an upgrade target; wherein, the structured data is a classified representation of the data in the database through each set object type;
[0260] A comparison unit 1102, configured to perform a difference comparison on the first structured data and the second structured data according to each set object type to obtain difference structured data; wherein, when performing the difference comparison on the table object, if it is determined through the second structured data that there is a foreign key constraint in the target version database that references a second table for a first table, then after performing the difference comparison of the second table through the first structured data and the second structured data, perform the difference comparison of the first table through the first structured data and the second structured data;
[0261] A conversion unit 1103, configured to convert the difference structured data into incremental statements; the incremental statements are used to upgrade the running version database to the target version database.
[0262] Optionally, the acquisition unit 1101 is specifically configured to:
[0263] Query the metadata of each set object type corresponding to the running version database in each information table, and determine the first structured data of the running version database according to the metadata of each set object type.
[0264] Optionally, the acquisition unit 1101 is specifically configured to:
[0265] Query the metadata of the table objects included in the running version database through the table information table;
[0266] Query the metadata of the column objects of any table included in the running version database through the column information table;
[0267] Query the metadata of the constraint objects of any table included in the running version database through the constraint information table;
[0268] Query the metadata of the index objects of any table included in the running version database through the index information table;
[0269] Query the metadata of the sequence objects included in the running version database through the sequence information table;
[0270] Query the metadata of the view objects included in the running version database through the view information table.
[0271] Optionally, the obtaining unit 1101 is specifically configured to:
[0272] Parse the status statement of the target version database that is the upgrade target, and determine the second structured data of the target version database according to the parsing result.
[0273] Optionally, the obtaining unit 1101 is specifically configured to:
[0274] Obtain the status statement of the target version database that is the upgrade target;
[0275] For any table creation statement in the status statement, extract the metadata of the table object at the first position of the table creation statement; extract the metadata of the constraint object of the table at the second position of the table creation statement; extract the metadata of the index object of the table at the third position of the table creation statement, and extract the metadata of the column object of the table at the fourth position of the table creation statement;
[0276] For any sequence creation statement in the status statement, extract the metadata of the sequence object at the fifth position of the sequence creation statement;
[0277] For any view creation statement in the status statement, extract the metadata of the view object at the sixth position of the view creation statement.
[0278] Optionally, the comparison unit 1102 is specifically configured to:
[0279] Perform a difference comparison of sequence objects through the first structured data and the second structured data;
[0280] Perform a difference comparison of table objects through the first structured data and the second structured data;
[0281] Perform a difference comparison of view objects through the first structured data and the second structured data.
[0282] Optionally, the comparison unit 1102 is specifically configured to:
[0283] Perform a difference comparison of column objects through the first structured data and the second structured data;
[0284] Perform a difference comparison of constraint objects through the first structured data and the second structured data;
[0285] Perform a difference comparison of index objects through the first structured data and the second structured data.
[0286] Based on the same technical concept, an embodiment of the present application provides a computer device, as Figure 12 shown, including at least one processor 1201 and a memory 1202 connected to the at least one processor. In the embodiment of the present application, the specific connection medium between the processor 1201 and the memory 1202 is not limited. Figure 12 Taking the connection between the processor 1201 and the memory 1202 through a bus as an example. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0287] In the embodiment of the present application, the memory 1202 stores instructions executable by at least one processor 1201. By executing the instructions stored in the memory 1202, the at least one processor 1201 can perform the steps of the above database version upgrade method.
[0288] Among them, the processor 1201 is the control center of the computer device, and can connect various parts of the computer device through various interfaces and lines. By running or executing the instructions stored in the memory 1202 and calling the data stored in the memory 1202, the database version upgrade can be performed. Optionally, the processor 1201 may include one or more processing units. The processor 1201 may integrate an application processor and a modulation and demodulation processor. Among them, the application processor mainly processes the operating system, user interface, application programs, etc., and the modulation and demodulation processor mainly processes wireless communication. It can be understood that the above modulation and demodulation processor may not be integrated into the processor 1201. In some embodiments, the processor 1201 and the memory 1202 can be implemented on the same chip, and in some embodiments, they can also be separately implemented on independent chips.
[0289] The processor 1201 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application specific integrated circuit (ASIC), a field programmable gate array, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and may implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application may be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
[0290] The memory 1202, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The memory 1202 may include at least one type of storage medium, for example, it may include flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (RAM), a static random access memory (SRAM), a programmable read-only memory (PROM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic memory, a magnetic disk, an optical disk, and so on. The memory 1202 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 1202 in the embodiments of the present application may also be a circuit or any other device capable of implementing a storage function, for storing program instructions and / or data.
[0291] Based on the same inventive concept, the embodiments of the present invention also provide a computer-readable storage medium storing a computer-executable program for causing a computer to execute the method for upgrading the version of the database listed in any of the above manners.
[0292] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0293] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices produce means for implementing the functions specified in one Figure One one flow or multiple flows and / or blocks Figure One one block or multiple blocks.
[0294] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including instruction means that implement the functions specified in one Figure One one flow or multiple flows and / or blocks Figure One one block or multiple blocks.
[0295] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, so that the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one Figure One one flow or multiple flows and / or blocks Figure One one block or multiple blocks.
[0296] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application is also intended to include these changes and modifications.
Claims
1. A method for version upgrade of a database, characterized in that Including: Obtain the first structured data of the running version database in the running state and the second structured data of the target version database as the upgrade target; wherein, the structured data is a classified representation of the data in the database through each set object type; Perform a difference comparison on the first structured data and the second structured data according to each set object type to obtain difference structured data; wherein, when performing a difference comparison on a table object, if it is determined through the second structured data that there is a foreign key constraint in the target version database that references a second table for a first table, then after performing the difference comparison on the second table through the first structured data and the second structured data, perform the difference comparison on the first table through the first structured data and the second structured data; Convert the difference structured data into incremental statements; the incremental statements are used to upgrade the running version database to the target version database; Among them, the obtaining of the second structured data of the target version database as the upgrade target includes: obtaining the status statement of the target version database as the upgrade target; For any table creation statement in the status statement, extract the metadata of the table object at the first position of the table creation statement; extract the metadata of the constraint object of the table at the second position of the table creation statement; extract the metadata of the index object of the table at the third position of the table creation statement, and extract the metadata of the column object of the table at the fourth position of the table creation statement; For any sequence creation statement in the status statement, extract the metadata of the sequence object at the fifth position of the sequence creation statement; For any view creation statement in the status statement, extract the metadata of the view object at the sixth position of the view creation statement.
2. The method according to claim 1, wherein Obtaining the first structured data of the running version database in the running state includes: Query the metadata of each set object type corresponding to the running version database in each information table, and determine the first structured data of the running version database according to the metadata of each set object type.
3. The method according to claim 2, wherein Querying the metadata of each set object type corresponding to the running version database in each information table includes: Query the metadata of the table object included in the running version database through the table information table; Query the metadata of the column object of any table included in the running version database through the column information table; Query the metadata of the constraint object of any table included in the running version database through the constraint information table; Query the metadata of the index object of any table included in the running version database through the index information table; Query the metadata of the sequence object included in the running version database through the sequence information table; Query the metadata of the view object included in the running version database through the view information table.
4. The method according to claim 1, wherein Performing a difference comparison on the first structured data and the second structured data according to each set object type to obtain difference structured data includes: Perform a difference comparison on the sequence object through the first structured data and the second structured data; Perform a difference comparison of table objects through the first structured data and the second structured data; Perform a difference comparison of view objects through the first structured data and the second structured data.
5. The method according to claim 4, characterized in that Performing a difference comparison of table objects through the first structured data and the second structured data includes: Perform a difference comparison of column objects through the first structured data and the second structured data; Perform a difference comparison of constraint objects through the first structured data and the second structured data; Perform a difference comparison of index objects through the first structured data and the second structured data.
6. A version upgrade device for a database, characterized in that, Including: An acquisition unit for acquiring the first structured data of the running version database in the running state and the second structured data of the target version database as the upgrade target; wherein, the structured data is a classified representation of the data in the database through each set object type; A comparison unit for performing a difference comparison of the first structured data and the second structured data according to each set object type to obtain difference structured data; wherein, when performing a difference comparison of table objects, if it is determined through the second structured data that there is a foreign key constraint in the target version database that references a second table for a first table, after performing a difference comparison of the second table through the first structured data and the second structured data, perform a difference comparison of the first table through the first structured data and the second structured data; A conversion unit for converting the difference structured data into incremental statements; the incremental statements are used to upgrade the running version database to the target version database; The acquisition unit is further specifically configured to acquire a status statement of the target version database as the upgrade target; for any table creation statement in the status statement, extract the metadata of the table object at the first position of the table creation statement; extract the metadata of the constraint object of the table at the second position of the table creation statement; extract the metadata of the index object of the table at the third position of the table creation statement, and extract the metadata of the column object of the table at the fourth position of the table creation statement; for any sequence creation statement in the status statement, extract the metadata of the sequence object at the fifth position of the sequence creation statement; for any view creation statement in the status statement, extract the metadata of the view object at the sixth position of the view creation statement.
7. A computing device, characterized in that, Including: A memory for storing computer programs; A processor for calling the computer program stored in the memory and executing the method according to any one of claims 1 to 5 according to the obtained program.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer-executable program, and the computer-executable program is used to cause a computer to execute the method according to any one of claims 1 to 5.
9. A computer program product, characterized in that, The computer program product stores instructions, and when the computer reads and executes the instructions, the computer is caused to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for verifying data of electronic map
CN103309888A
Database cluster difference comparison and data synchronization method and system and medium
CN112579613A