Database change method and system, electronic device, and storage medium

By acquiring and verifying change order information, generating and executing automated scripts, the inefficiency caused by manual database change verification and rollback is solved, achieving highly efficient and automated database management.

CN117171139BActive Publication Date: 2026-03-24CHINA CONSTRUCTION BANK
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-22
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

In existing technologies, the automation level of database changes, change verification, and change rollback is low, relying on manual script writing, which is labor-intensive and inefficient.

Method used

By obtaining change information from change orders, performing correctness verification based on preset semantic analysis rules, generating change scripts, verification scripts, and rollback scripts, automatically executing database changes and performing verification, and rolling back to the original state if it fails.

Benefits of technology

It automates database changes, change verification, and change rollback, reducing the consumption of human resources and improving efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117171139B_ABST
    Figure CN117171139B_ABST
Patent Text Reader

Abstract

The application provides a database change method and system, an electronic device and a storage medium, obtains a change work order for a target database, and extracts change information in the change work order; correctness of the change information is verified based on preset semantic analysis rules; if the verification is passed, change scripts, verification scripts and rollback scripts are generated based on the change information; the target database is changed by executing the change scripts; it is judged whether the target database change is successful by executing the verification scripts; if yes, it is determined that the target database change is completed; if no, the target database is rolled back to the state before the change scripts are executed by executing the rollback scripts. In the scheme, the target database is changed by executing the change scripts, it is judged whether the target database change is successful by executing the verification scripts, and the change is rolled back by executing the rollback scripts if the change is not successful, so that the purposes of automatically executing the database change, change verification and change rollback are achieved, and the problem of low efficiency caused by high labor cost is solved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database change, and discloses a database change method and system, an electronic device and a storage medium. BACKGROUND

[0002] With the continuous development of cloud computing and big data technology, MPP cloud data warehouse supports increasingly large business scale, and application developers have an increasing demand for database changes in the whole line production environment.

[0003] In the prior art, the automation degree of database change, change verification and change rollback is low, and relies on manual script execution, which consumes manpower and is inefficient.

[0004] Therefore, how to realize the automation of database change, change verification and change rollback is a problem that needs to be solved at present. SUMMARY

[0005] Therefore, the embodiments of the present application provide a database change method and system, an electronic device and a storage medium to realize the purpose of automatically executing database change, change verification and change rollback.

[0006] To achieve the above purpose, the embodiments of the present application provide the following technical solutions:

[0007] The first aspect of the embodiments of the present application discloses a database change method, which comprises:

[0008] Obtaining a change work order for a target database, and extracting change information in the change work order;

[0009] Correctness verification of the change information based on a preset semantic analysis rule;

[0010] If the change information passes the correctness verification, generating a change script, a verification script and a rollback script based on the change information;

[0011] Executing the change script to change the target database;

[0012] Executing the verification script to determine whether the target database change is successful;

[0013] If yes, determining that the target database change is completed;

[0014] If no, executing the rollback script to roll back the target database to a state before the change script is executed.

[0015] Preferably, the change information at least includes a host IP, a change scenario, a change type, a change object name and respective change parameter values, the correctness verification on the change information is based on preset semantic analysis rules, and includes the following steps:

[0016] verifying whether the host IP exists;

[0017] if the host IP exists, for each change parameter value, corresponding verification information is obtained, and it is judged whether the change parameter value matches the verification information;

[0018] if each change parameter value matches the corresponding verification information, an audit script is generated based on the change scenario, the change type and the change object name;

[0019] the audit script is executed, and it is judged whether a change object corresponding to the change object name exists in the target database;

[0020] if yes, and the change type is modification or deletion, it is determined that the change information passes the correctness verification;

[0021] if no, and the change type is addition, it is determined that the change information passes the correctness verification.

[0022] Preferably, the generation of the audit script based on the change scenario, the change type and the change object name includes the following steps:

[0023] a preset query statement set corresponding to the change scenario is obtained;

[0024] a query statement corresponding to the change type is obtained from the preset query statement set;

[0025] the change object name and the query statement are spliced to obtain a complete query statement;

[0026] the audit script is generated based on the complete query statement.

[0027] Preferably, if the change information passes the correctness verification, a change script, a verification script and a rollback script are generated based on the change information, including the following steps:

[0028] if the change information passes the correctness verification, respective change statements, verification statements and rollback statements are extracted from a preset statement set based on the change information;

[0029] the change statements, the verification statements and the rollback statements are spliced based on the change information to obtain complete change statements, verification statements and rollback statements, respectively;

[0030] Based on the complete change statement, the verification statement and the rollback statement, a change script, a verification script and a rollback script are respectively generated.

[0031] Preferably, the method further comprises:

[0032] If error information is generated during execution of the change script or the verification script, the error information is displayed.

[0033] When a rollback instruction input by a user is received, the rollback script is executed to rollback the target database to a state before the change script is executed.

[0034] The second aspect of the embodiment of the application discloses a database change system, which comprises:

[0035] An acquisition module is configured to acquire a change work order for a target database and extract change information in the change work order.

[0036] A verification module is configured to perform correctness verification on the change information based on a preset semantic analysis rule.

[0037] A generation module is configured to generate a change script, a verification script and a rollback script based on the change information if the change information passes the correctness verification.

[0038] An execution module is configured to execute the change script to change the target database, execute the verification script to determine whether the change of the target database is successful, and execute the rollback script to rollback the target database to a state before the change script is executed if the change of the target database is not successful.

[0039] Preferably, the change information comprises at least a host IP, a change scenario, a change type, a change object name and respective change parameter values, and the verification module comprises:

[0040] A verification unit is configured to verify whether the host IP exists, acquire corresponding verification information for each change parameter value if the host IP exists, and determine whether the change parameter value matches the verification information.

[0041] A generation unit is configured to generate an audit script based on the change scenario, the change type and the change object name if each change parameter value matches corresponding verification information.

[0042] The execution unit is used for executing the audit script, judging whether the change object corresponding to the change object name exists in the target database, if yes, and the change type is modification or deletion, determining that the change information passes the correctness check, if no, and the change type is addition, determining that the change information passes the correctness check.

[0043] Preferably, the generation unit is specifically used for:

[0044] Obtaining a preset query statement set corresponding to the change scenario;

[0045] Obtaining a query statement corresponding to the change type from the preset query statement set;

[0046] Splicing the change object name and the query statement to obtain a complete query statement;

[0047] Generating an audit script based on the complete query statement.

[0048] The third aspect of the embodiment of the application discloses a storage medium for storing a computer program, when the computer program is executed, specifically for implementing the database change method as any one of the first aspect of the embodiment of the application.

[0049] The fourth aspect of the embodiment of the application discloses an electronic device, comprising a memory and a processor.

[0050] The memory is used for storing a computer program;

[0051] The processor is used for executing the computer program, specifically for implementing the database change method as any one of the first aspect of the embodiment of the application.

[0052] Based on the database change method and system, the electronic equipment and the storage medium provided by the above embodiments of the present application, a change work order for a target database is obtained, and change information in the change work order is extracted; the change information is subjected to correctness verification based on preset semantic analysis rules; if the change information passes the correctness verification, change scripts, verification scripts and rollback scripts are generated based on the change information; the target database is changed by executing the change scripts; it is judged whether the change of the target database is successful by executing the verification scripts; if yes, it is determined that the change of the target database is completed; if no, the target database is rolled back to the state before the change scripts are executed by executing the rollback scripts. In the present solution, change scripts, verification scripts and rollback scripts are generated based on the change information in the change work order, the target database is changed by executing the change scripts, it is judged whether the change of the target database is successful by executing the verification scripts, and the change is rolled back by executing the rollback scripts if the change is not successful, so as to realize the purposes of automatically executing database change, change verification and change rollback, and solve the problem of low efficiency due to high labor cost. BRIEF DESCRIPTION OF DRAWINGS

[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of the provided drawings.

[0054] Figure 1 The flowchart of the database change method disclosed by the embodiments of the present application;

[0055] Figure 2 The flowchart of the correctness verification by semantic analysis disclosed by the embodiments of the present application;

[0056] Figure 3 The flowchart of the generation of the verification scripts disclosed by the embodiments of the present application;

[0057] Figure 4 The flowchart of the generation of the change scripts disclosed by the embodiments of the present application;

[0058] Figure 5 The flowchart of the generation of the rollback scripts disclosed by the embodiments of the present application;

[0059] Figure 6 The architecture diagram of the database change system disclosed by the embodiments of the present application;

[0060] Figure 7 The architecture diagram of the electronic equipment disclosed by the embodiments of the present application. DETAILED DESCRIPTION

[0061] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by a person of ordinary skill in the art without creative work are within the protection scope of the present application.

[0062] In the present application, the term “comprising”, “containing” or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or equipment including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or equipment. Without more limitation, the element defined by the sentence “including a…” does not exclude the presence of other identical elements in the process, method, article or equipment including the element.

[0063] In order to facilitate the understanding of the technical solutions of the present application, the technical terms appearing in the present application are explained:

[0064] MPP cloud data warehouse: Massive Parallel Processing (MPP) cloud data warehouse is the only integration point for enterprise-level management and decision-making data, and is also the most important and basic support platform for management and analysis under the current financial technology architecture. It has gradually replaced the traditional GreenPlum (GP) data warehouse product. Compared with the GP data warehouse, the MPP cloud data warehouse has the following advantages: 1. Virtualization technology is adopted, which can effectively avoid high availability problems caused by hardware failures; 2. Storage and computing are separated, hierarchical storage can effectively reduce data redundancy; 3. Services can be flexibly expanded, which can effectively solve the problem of the upper limit of the size of the GP single cluster.

[0065] Database change: Implement relevant change operations on the database to realize the needs of application developers for adding / modifying objects, permissions and other database-related requirements, and ensure the normal operation of the development work of the upstream and downstream applications of the database.

[0066] As known from the background art, in the prior art, the application developers submit change work orders, which are audited by manual review. After the audit is passed, scripts are generated to implement database changes. However, the verification and rollback stages of the changes still rely on manual script verification and rollback, which consumes manpower and is inefficient.

[0067] Therefore, the database change method and system, the electronic device and the storage medium disclosed by the embodiment of the present application realize the purposes of automatically executing database change, change verification and change rollback, and solve the problems of low efficiency and high labor cost.

[0068] As shown in the flowchart of the database change method disclosed by the embodiment of the present application, the method mainly includes the following steps: Figure 1

[0069] Step S101: Obtain a change order for a target database, and extract change information in the change order.

[0070] It should be noted that the target database is specifically an MPP cloud warehouse. Compared with a common database, the MPP cloud warehouse has a higher demand for automatic changes such as table space change and schema change (i.e., mode change), and has a lower demand for changes such as database table, view, index and column, because these can be changed by the user to which the table belongs.

[0071] Therefore, the change operation for the database mentioned in the embodiment of the present application is exemplarily described by taking table space change as an example, but is not limited to table space change.

[0072] In step S101, the change order is initiated by an application developer. Exemplarily, taking table space change as an example, the change information contained in the change order is as follows:

[0073]

[0074]

[0075] Specifically, the change information is as follows:

[0076] “Host IP”: “xxx.xxx.xxx.xxx” indicates that the change should be implemented on the host with IP xxx.xxx.xxx.xxx.

[0077] “Change scenario” indicates that the change scenario of the demand form is “table space change”.

[0078] The value of “Demand details” is a list carrying various demands of the change, including:

[0079] “Change type”: “New”, indicating that the change type is to newly create a table space. ​

[0080] "tablespace name": "tbs_test_example_01", indicates that the name of the newly created tablespace must be tbs_test_example_01.

[0081] "number of pre-stored tables": "10000", indicates that the total number of tables expected to be stored in the tablespace is 10000.

[0082] "total amount of pre-stored data (TB)": "150", indicates that the storage amount expected to be stored in the tablespace is 150 TB.

[0083] "cos tenant information" is a dictionary type, indicating that the tablespace needs to be built in the bucket of the cos tenant.

[0084] It should be noted that the bucket is a basic element for storing data in the database, which can be understood as a storage unit in the database.

[0085] The detailed information of the cos tenant is as follows:

[0086] ACCOUNT: user1@company.com, indicates that the account name of the cos tenant is user1@company.com.

[0087] PATH: "user1_path", indicates that the tablespace needs to exist in the user1_path path.

[0088] KEY: ["user1_key_id", "user1_key"], used for cos verification, indicates that the key_id of the cos account is user1_key_id and the key is user1_key.

[0089] COMMENT: "user1 data warehouse - financial knowledge graph application", indicates that the created tablespace path on the cos has a comment "user1 data warehouse - financial knowledge graph application".

[0090] Step S102: correctness verification of the change information based on the preset semantic analysis rule.

[0091] In the specific implementation process of step S102, if the change information at least includes host IP, change scenario, change type, change object name and each change parameter value, the specific process of correctness verification is as follows:

[0092] Step S11: verify whether the host IP exists.

[0093] It should be noted that the database runs in the host, and the host IP needs to be included in the change information to find the target database to be changed, therefore, it is necessary to verify whether the host IP exists to ensure that the target database is found.

[0094] Step S12: If the host IP exists, for each change parameter value, the corresponding verification information is obtained, and it is judged whether the change parameter value matches the verification information.

[0095] It should be noted that if the host IP does not exist, error information that the host IP does not exist is generated and displayed.

[0096] The change parameter value is used to represent the change requirement, and different change scenarios correspond to different change parameter values, for example, the specific values of "pre-stored table quantity (table)", "pre-stored data total quantity (TB)", and "cos tenant information" in "demand details" in the change information corresponding to the above table space change scenario are change parameter values.

[0097] Each change parameter value has corresponding verification information, for example, the verification information corresponding to "pre-stored table quantity (table)" is a pre-set pre-stored table quantity threshold.

[0098] Correspondingly, it is judged whether the change parameter value matches the verification information, that is, whether the pre-stored table quantity exceeds the pre-stored table quantity threshold, if it exceeds, it does not match, if it does not exceed, it matches.

[0099] Step S13: If each change parameter value matches the corresponding verification information, an audit script is generated based on the change scenario, the change type, and the change object.

[0100] It should be noted that if any change parameter value matches the corresponding verification information, error information corresponding to the change parameter value is generated and displayed.

[0101] In the specific implementation process of step S13, it includes:

[0102] 1. Obtain a pre-set query statement set corresponding to the change scenario.

[0103] 2. Obtain a query statement corresponding to the change type from the pre-set query statement set.

[0104] For example, the query statement corresponding to the change type of adding, modifying, and deleting is a query statement for querying whether the change object exists in the target database.

[0105] 3. Concatenate the change object name and the query statement to obtain a complete query statement.

[0106] For example, in the table space change, the change object is a table space, and the table space name is concatenated with the query statement.

[0107] 4. Generating an audit script based on the complete query statement.

[0108] Step S14: executing the audit script to determine whether the change object corresponding to the change object name exists in the target database, if yes, and the change type is modification or deletion, it is determined that the change information passes the correctness verification, if no, and the change type is addition, it is determined that the change information passes the correctness verification.

[0109] In the specific implementation process of step S14, the host IP is connected to the target database, the audit script is executed, and it is queried whether the change object corresponding to the change object name exists in the target database.

[0110] It can be understood that when the change type is modification or deletion, the change object corresponding to the change object name needs to exist in the target database, so as to modify or delete the change object.

[0111] When the change type is modification or deletion, the change object corresponding to the change object name does not exist in the target database, error information of non-existing modification or deletion object is generated and displayed.

[0112] When the change type is addition, the change object corresponding to the change object name needs to not exist in the target database, so as to avoid the problem of repeated addition.

[0113] When the change type is addition, the change object corresponding to the change object name exists in the target database, error information of repeated addition object is generated and displayed.

[0114] Taking the correctness verification of the change information in the change work order as an example, as shown in FIG. 1, it is a flowchart for correctness verification by using semantic analysis disclosed by the embodiment of the present application, through semantic analysis and rule matching technology, the correctness of each parameter value of the form is analyzed, if incorrect, corresponding error information is directly generated, and the specific process is as follows: Figure 2

[0115] (1) The change scene is obtained from the change information, the change scene is identified as a table space change through the change scene, and the SCENARIO_TYPE variable is assigned.

[0116] (2) The semantic analysis is performed according to the list.

[0117] It should be noted that one change work order can have multiple change information, and the multiple change information is stored in the form of a list, and the semantic analysis is performed according to the order in the list.

[0118] The semantic analysis includes the following processes:

[0119] (2.1) Filtering the spaces in the change information. ​

[0120] (2.2) Get the host IP in the change information, and determine whether the host IP exists.

[0121] If the host IP exists in the existing IP list, continue the following process, otherwise report an error of host IP error MASTER IP ERROR.

[0122] (2.3) Get the target database name DB_NAME corresponding to the change information, and determine whether the target database name DB_NAME exists in the existing database list DB LIST.

[0123] If the target database name DB_NAME exists in the existing database list DB LIST, continue the following process, otherwise report an error of target database name error DB NAME ERROR.

[0124] (2.4) Get the cos tenant in the change information, and determine whether the cos tenant COS USER exists in the existing user list USER LIST.

[0125] If the cos tenant COS USER exists in the existing user list USER LIST, continue the following process, otherwise report an error of cos tenant information error COS USER ERROR.

[0126] (2.5) Get the pre-stored table quantity EXP TABLE COUNT in the change information, and determine whether the pre-stored table quantity EXP TABLE COUNT is lower than the threshold, if so, continue the following process, otherwise report an error of pre-stored table quantity error EXP TABLE COUNT ERROR.

[0127] (2.6) Get the total amount of data EXP DATA VOL in the change information, and determine whether the total amount of pre-stored data EXP DATA VOL is lower than the threshold, if so, continue the following process, otherwise report an error of total amount of pre-stored data error EXP DATA VOL ERROR.

[0128] (2.7) After confirming that there is no error in the above process, get the table space name TBS NAME and the change type TBS ALTER TYPE from the change information.

[0129] Then, generate an audit script based on the change scenario SCENARIO TYPE, the table space name TBS NAME and the change type TBS ALTER TYPE.

[0130] Connect the host through the host IP, and connect the target database through the target database name DB NAME to execute the audit script in real time to query whether the table space corresponding to the table space name TBS NAME already exists.

[0131] If yes, generate TBS_NAME_ERROR error information indicating table space duplication.

[0132] If no, determine that the change information passes the correctness check, and end semantic analysis.

[0133] As shown in Figure 3 the flowchart for generating an audit script disclosed in the embodiment of the application.

[0134] Obtain the change scenario and the change type from the change information, and assign them to the SCENARIO_TYPE variable and the TBS_ALTER_TYPE variable, respectively.

[0135] For example, the change scenario is table space change, and the change type is addition.

[0136] According to the table space change scenario in the SCENARIO_TYPE variable, obtain the corresponding preset query statement set SELECT STATEMENT, and according to the change type in the TBS_ALTER_TYPE variable, select the corresponding query statement SELECT * FROM pg_tablespace from the preset query statement set SELECT STATEMENT.

[0137] Obtain the table space name from the change information and assign it to the TBS_NAME variable, and based on the TBS_NAME variable and the query statement SELECT * FROM pg_tablespace, splice a complete query statement:

[0138] SELECT * FROM pg_tablespace WHERE spcname = 'TBS_NAME'.

[0139] Generate an audit script based on the complete query statement.

[0140] Step S103: If the change information passes the correctness check, generate a change script, a verification script and a rollback script based on the change information.

[0141] In the specific implementation process of step S103, it includes:

[0142] If the change information passes the correctness check, extract the corresponding change statement, verification statement and rollback statement from the preset statement set based on the change information.

[0143] Based on the change information, splice the change statement, the verification statement and the rollback statement to obtain complete change statement, verification statement and rollback statement.

[0144] Based on the complete change statement, the verification statement and the rollback statement, the change script, the verification script and the rollback script are respectively generated.

[0145] It should be noted that the verification script and the above-mentioned audit script have the same execution principle, and are used for querying whether the change object exists in the target database, and the verification script and the audit script are both generated by using the query statement, and the generation process is the same, therefore, the generation process of the verification script is referred to the generation process of the audit script, which will not be repeated here.

[0146] The embodiment of the application respectively illustrates the specific process of generating the change script and the rollback script, as follows:

[0147] As shown in Figure 4 The flow chart for generating the change script disclosed by the embodiment of the application.

[0148] The change scenario and the change type are obtained from the change information, and are respectively assigned to the SCENARIO_TYPE variable and the TBS_ALTER_TYPE variable.

[0149] For example, the change scenario is the table space change, and the change type is the new addition.

[0150] According to the table space change scenario in the SCENARIO_TYPE variable, the corresponding preset new creation statement set CREATE TABLESPACE STATEMENT is obtained, and according to the change type in the TBS_ALTER_TYPE variable, the corresponding new creation statement CREATE TABLESPACE is selected from the preset new creation statement set CREATE TABLESPACE STATEMENT.

[0151] The table space name, the cos tenant name, the pre-stored table quantity and the pre-stored data total amount are obtained from the change information, and are respectively assigned to the TBS_NAME variable, the COS_USER variable, the EXP_TABLE_COUNT variable and the EXP_DATA_VOL variable.

[0152] The optimal bucket number is calculated according to the EXP_TABLE_COUNT variable and the EXP_DATA_VOL variable, and is assigned to the BUCKET_NUM variable.

[0153] Based on the new creation statement CREATE TABLESPACE, the BUCKET_NUM variable, the TBS_NAME variable, the COS_USER variable, the EXP_TABLE_COUNT variable and the EXP_DATA_VOL variable, the complete new creation statement is spliced:

[0154] CREATE TABLESPACE TBS_NAME LOCATION COS_USER.PATH WITH COS_USER.KEYbucket_num=BUCKET_NUM.

[0155] It should be noted that the bucket is a basic element for storing data in the database, which can be understood as a storage unit in the database.

[0156] As Figure 5 shown, a flowchart for generating a rollback script disclosed in the embodiment of the application.

[0157] The change scenario and the change type are obtained from the change information and are respectively assigned to the SCENARIO_TYPE variable and the TBS_ALTER_TYPE variable.

[0158] For example, the change scenario is table space change, and the change type is addition.

[0159] According to the table space change scenario in the SCENARIO_TYPE variable, the corresponding preset rollback statement set DROP STATEMENT is obtained, and according to the change type in the TBS_ALTER_TYPE variable, the corresponding rollback statement DROP TABLESPACE is selected from the preset rollback statement set DROP STATEMENT.

[0160] The table space name is obtained from the change information and is assigned to the TBS_NAME variable, and based on the TBS_NAME variable and the rollback statement DROP TABLESPACE, a complete rollback statement DROP TABLESPACE TBS_NAME is spliced.

[0161] Based on the complete rollback statement, an audit script is generated.

[0162] Step S104: performing the change script to change the target database.

[0163] In step S104, the change script changes the target database according to the change information, and the change of the target database mainly includes: creating, deleting and modifying users, user groups, table spaces, schemas (Schema), database user permissions, etc.

[0164] In an embodiment, if error information is generated during execution of the change script, the error information is displayed to the user, and when a rollback instruction input by the user is received, the rollback script is executed to rollback the target database to a state before the change script is executed.

[0165] Step S105: The verification script determines whether the target database change is successful. If yes, step S106 is performed, and if no, step S107 is performed.

[0166] In step S105, the verification script determines whether the database change is successful by querying the target database to determine whether the change object exists and is modified.

[0167] For example, if a table space is added after the change script is executed, the verification script queries whether the table space exists in the target database. If yes, the change is successful, and if no, the change fails.

[0168] In an embodiment, if an error message is generated during the execution of the verification script, the error message is displayed to the user. When a rollback instruction input by the user is received, the rollback script is executed to roll back the target database to the state before the change script is executed.

[0169] Step S106: It is determined that the target database change is complete.

[0170] Step S107: The rollback script is executed to roll back the target database to the state before the change script is executed.

[0171] In an embodiment, if an error message is generated during the execution of the verification script, the error message is displayed to the user, thereby notifying the user of the rollback failure.

[0172] Based on the database change method disclosed in the above embodiment of the present application, the change work order for the target database is obtained, and the change information in the change work order is extracted. The change information is subjected to correctness verification based on a preset semantic analysis rule. If the change information passes the correctness verification, the change script, the verification script, and the rollback script are generated based on the change information. The change script is executed to change the target database. The verification script is executed to determine whether the target database change is successful. If yes, it is determined that the target database change is complete. If no, the rollback script is executed to roll back the target database to the state before the change script is executed. In the present solution, the change script, the verification script, and the rollback script are generated based on the change information in the change work order. The change script is executed to change the target database. The verification script is executed to determine whether the target database change is successful. If the change is not successful, the rollback script is executed to change the rollback, thereby achieving the purposes of automatically performing the database change, change verification, and change rollback, and solving the problem of low efficiency due to the consumption of manpower.

[0173] Based on the database change method disclosed in the above embodiment of the present application, as shown in FIG. Figure 6 The database change system 600 includes an acquisition module 601, a verification module 602, a generation module 603, and an execution module 604.

[0174] The acquisition module 601 is configured to acquire a change work order for a target database and extract change information in the change work order.

[0175] The verification module 602 is configured to perform correctness verification on the change information based on a preset semantic analysis rule.

[0176] In an embodiment, the change information at least includes a host IP, a change scenario, a change type, a change object name, and respective change parameter values. Correspondingly, the verification module 602 includes:

[0177] The verification unit is configured to verify whether the host IP exists. If the host IP exists, for each change parameter value, corresponding verification information is acquired, and it is determined whether the change parameter value matches the verification information.

[0178] The generation unit is configured to, if each change parameter value matches the corresponding verification information, generate an audit script based on the change scenario, the change type, and the change object name.

[0179] In an embodiment, the generation unit is specifically configured to:

[0180] Acquire a preset query statement set corresponding to the change scenario.

[0181] Acquire a query statement corresponding to the change type from the preset query statement set.

[0182] Splice the change object name and the query statement to obtain a complete query statement.

[0183] Generate the audit script based on the complete query statement.

[0184] The execution unit is configured to execute the audit script, determine whether a change object corresponding to the change object name exists in the target database, and determine that the change information passes the correctness verification if the change object exists and the change type is modification or deletion, or if the change object does not exist and the change type is addition.

[0185] The generation module 603 is configured to, if the change information passes the correctness verification, generate a change script, a verification script, and a rollback script based on the change information.

[0186] In an embodiment, the generation module 603 is specifically configured to:

[0187] If the change information passes the correctness verification, extract respective change statements, verification statements, and rollback statements from a preset statement set based on the change information.

[0188] Based on the change information, the change statement, the verification statement and the rollback statement are spliced respectively to obtain complete change statement, verification statement and rollback statement.

[0189] Based on the complete change statement, the verification statement and the rollback statement, the change script, the verification script and the rollback script are generated respectively.

[0190] The execution module 604 is configured to execute the change script to change the target database, execute the verification script to determine whether the change of the target database is successful, and if so, determine that the change of the target database is completed, and if not, execute the rollback script to rollback the target database to the state before the change script is executed.

[0191] In an embodiment, the database change system 600 further comprises:

[0192] The error reporting module is configured to display error information if the error information is generated during the execution of the change script or the verification script.

[0193] When the rollback instruction input by the user is received, the rollback script is executed to rollback the target database to the state before the change script is executed.

[0194] Based on the database change system disclosed in the above embodiments of the present application, the change work order for the target database is obtained, and the change information in the change work order is extracted. The change information is verified for correctness based on the preset semantic analysis rule. If the change information passes the correctness verification, the change script, the verification script and the rollback script are generated based on the change information. The change script is executed to change the target database. The verification script is executed to determine whether the change of the target database is successful. If so, it is determined that the change of the target database is completed. If not, the rollback script is executed to rollback the target database to the state before the change script is executed. In the present solution, the change script, the verification script and the rollback script are generated based on the change information in the change work order. The change script is executed to change the target database. The verification script is executed to determine whether the change of the target database is successful. If the change is not successful, the rollback script is executed to rollback the change, thereby achieving the purposes of automatically executing the database change, change verification and change rollback, and solving the problem of low efficiency due to the consumption of manpower.

[0195] The embodiments of the present application further provide an electronic device, please refer to Figure 7 The electronic device comprises a memory 701 and a processor 702.

[0196] The memory 701 is configured to store a computer program.

[0197] The processor 702 is configured to execute the computer program, and specifically configured to implement the database change method provided in any of the embodiments of the present application.

[0198] The application further provides a computer storage medium for storing a computer program, the computer program being executed to implement the database changing method provided in any of the embodiments of the application.

[0199] Each of the embodiments in the specification is described in a progressive manner, and the same or similar parts of each of the embodiments can be referred to each other. Each of the embodiments focuses on the difference from other embodiments. In particular, for the system or system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the related parts can be referred to the part of the method embodiments. The above-described system and system embodiments are merely illustrative, and the units described as separate components can be or can not be physically separated, and the components shown as units can be or can not be physical units, that is, they can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment according to actual needs. Those skilled in the art can understand and implement without creative labor.

[0200] The skilled person can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed herein can be realized in electronic hardware, computer software or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been described in the above description in general. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0201] The above description of the disclosed embodiments enables a person skilled in the art to implement or use the present application. Various modifications to the embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A database modification method, characterized in that, The method includes: Obtain change orders for the target database and extract change information from the change orders; The correctness of the changed information is verified based on preset semantic analysis rules; If the change information passes the correctness check, then based on the change information, a change script, a verification script, and a rollback script are generated; The change script is executed to modify the target database; The verification script is executed to determine whether the target database change was successful. If so, confirm that the target database change is complete; If not, execute the rollback script to revert the target database to its state before the change script was executed; The change information includes at least the host IP address, change scenario, change type, name of the changed object, and values ​​of each change parameter. The correctness verification of the change information based on preset semantic analysis rules includes: Verify that the host IP address exists; If the host IP exists, for each of the changed parameter values, obtain the corresponding verification information and determine whether the changed parameter value matches the verification information; If each of the changed parameter values ​​matches the corresponding verification information, an audit script is generated based on the changed scenario, the changed type, and the changed object name. Execute the audit script to determine whether the target database contains a change object corresponding to the change object name; If so, and the change type is modification or deletion, then the change information is determined to have passed the correctness check; If not, and the change type is "new", then the change information is determined to have passed the correctness check.

2. The method according to claim 1, characterized in that, The step of generating an audit script based on the change scenario, the change type, and the name of the changed object includes: Obtain the set of preset query statements corresponding to the changed scenario; Obtain the query statement corresponding to the change type from the preset query statement set; The name of the object to be changed is concatenated with the query statement to obtain the complete query statement; Generate an audit script based on the complete query statement.

3. The method according to claim 1, characterized in that, If the change information passes the correctness check, then based on the change information, a change script, a verification script, and a rollback script are generated, including: If the change information passes the correctness check, then based on the change information, the corresponding change statement, verification statement and rollback statement are extracted from the preset statement set respectively; Based on the change information, the change statement, the verification statement, and the rollback statement are concatenated to obtain the complete change statement, verification statement, and rollback statement; Based on the complete change statement, verification statement, and rollback statement, a change script, a verification script, and a rollback script are generated respectively.

4. The method according to claim 1, characterized in that, The method further includes: If an error message is generated during the execution of the change script or the verification script, the error message will be displayed. When a rollback command is received from the user, the rollback script is executed to revert the target database to the state before the change script was executed.

5. A database modification system, characterized in that, The system includes: The acquisition module is used to acquire change orders for the target database and extract change information from the change orders; The verification module is used to verify the correctness of the changed information based on preset semantic analysis rules; The generation module is used to generate a change script, a verification script, and a rollback script based on the change information if the change information passes the correctness verification. The execution module is used to execute the change script to modify the target database; execute the verification script to determine whether the target database change is successful; if yes, determine that the target database change is complete; if no, execute the rollback script to roll back the target database to the state before the change script was executed. The change information includes at least the host IP, change scenario, change type, change object name, and values ​​of each change parameter. The verification module includes: The verification unit is used to verify whether the host IP exists; if the host IP exists, for each of the changed parameter values, the corresponding verification information is obtained, and it is determined whether the changed parameter value matches the verification information. The generation unit is used to generate an audit script based on the change scenario, the change type, and the change object name if each of the changed parameter values ​​matches the corresponding verification information. An execution unit is used to execute the audit script and determine whether a change object corresponding to the change object name exists in the target database; if yes, and the change type is modification or deletion, then the change information is determined to pass the correctness check; if no, and the change type is addition, then the change information is determined to pass the correctness check.

6. The system according to claim 5, characterized in that, The generation unit is specifically used for: Obtain the set of preset query statements corresponding to the changed scenario; Obtain the query statement corresponding to the change type from the preset query statement set; The name of the object to be changed is concatenated with the query statement to obtain the complete query statement; Generate an audit script based on the complete query statement.

7. A storage medium, characterized in that, Used to store computer programs, which, when executed, are specifically used to implement the database modification method as described in any one of claims 1 to 4.

8. An electronic device, characterized in that, include: Memory and processor; The memory is used to store computer programs; The processor is used to execute the computer program, specifically to implement the database modification method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Database data change method and device

    CN112883050A

  • Data change SQL statement auditing method and device

    CN114065288A

  • Database change method and device, electronic equipment and storage medium

    CN115701599A