Database Script Control Method, System, Device, Storage Medium and Program Product

By determining the baseline sequence of script versions in the database, matching and executing a full set of scripts, and comparing the differences in database scripts, the production accident problem caused by inconsistent database versions is solved, and the differential scripts are automatically identified and the risks of manual intervention and misoperation are reduced.

CN115408111BActive Publication Date: 2025-07-01CCB FINTECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211184508.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-27
Publication Date
2025-07-01
Estimated Expiration
2042-09-27

AI Technical Summary

Technical Problem

In the prior art, production accidents occur frequently due to inconsistent database versions. Operation and maintenance personnel have safety hazards and risks of misoperation when manually managing script versions, and it is difficult to detect version differences in time.

Method used

By determining the version baseline sequence of the target database script, creating a target container and matching the version baseline from the full script collection, generating a matching script collection, executing a matching script in the target container, comparing the difference between the target database script and the database instance script, and realizing dynamic differentiated analysis.

Benefits of technology

It reduces manual intervention, avoids operation and maintenance personnel changing production environment scripts on site, promptly discovering problems, avoiding production accidents, significantly reducing the probability of production events, and supports customer customization needs to prevent script conflicts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115408111B_ABST
    Figure CN115408111B_ABST
Patent Text Reader

Abstract

The present application discloses a method, system, device, storage medium and program product for database script management and control, which determines a target database script in a target environment and obtains a script version baseline sequence of the target environment; determines a target database corresponding to the target database script and creates a target container corresponding to the target database; obtains a full set of scripts of the target database, the full set of scripts includes one or more reference database scripts, and each reference database script has a corresponding reference script version baseline; matches each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set; executes each reference database script in the matching script set in the target container to obtain a database instance script; compares the target database script with the database instance script to generate difference information between the two, which can timely discover problems, avoid the occurrence of production accidents, and significantly reduce the probability of production events.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of script processing, and particularly to a database script control method, a database script control system, an electronic device, a computer-readable storage medium, and a computer program product. Background Art

[0002] With the continuous iteration of the system, database scripts need to be continuously changed to adapt to new business requirements. With the continuous increase in database script changes, combined with multiple environments such as development, testing, and production, and multiple different production versions of multiple customers, it poses continuous challenges to database script management.

[0003] In the process of database script management, the following problems mainly exist:

[0004] 1) The operation and maintenance personnel change the production environment script on-site, resulting in out-of-control version management. Such problems are often not discovered in time and pose significant security risks.

[0005] 2) In the process of system development, from the development environment to the testing environment, and then to the production environment, it is necessary to manually identify and manage version differences, which is prone to errors, resulting in database script differences and affecting environment migration.

[0006] 3) Customer customized development forms new script branches, combined with customer independent development, resulting in some scripts not being included in version control, causing version differences and triggering script conflicts.

[0007] Usually, a large part of production accidents are caused by inconsistent database versions, especially manual misoperations by operation and maintenance personnel, differences in table structure, field types, accidental deletion of indexes, adjustment of partitions, etc., which bring losses to actual production and operation. Summary of the Invention

[0008] The present application provides a database script control method, system, device, storage medium, and program product to solve the problem of production accidents caused by inconsistent database versions in related technologies.

[0009] According to the first aspect of the present application, a database script control method is provided. The method includes:

[0010] Determine the target database script in the target environment, and obtain the script version baseline sequence of the target environment;

[0011] Determine the target database corresponding to the target database script, and create a target container corresponding to the target database;

[0012] Obtain the full set of scripts of the target database, where the full set of scripts includes one or more reference database scripts, and each reference database script has a corresponding reference script version baseline;

[0013] Match each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence, where the matching script set includes the reference script version baseline that matches each script version baseline and the corresponding reference database script;

[0014] Execute each reference database script in the matching script set in the target container to obtain a database instance script;

[0015] Compare the target database script with the database instance script to generate the difference information between the two.

[0016] According to the second aspect of the present application, a database script control system is provided, and the system includes:

[0017] A target database script determination module, configured to determine a target database script in a target environment;

[0018] A baseline sequence acquisition module, configured to acquire a script version baseline sequence of the target environment;

[0019] A target database determination module, configured to determine the target database corresponding to the target database script;

[0020] A target container creation module, configured to create a target container corresponding to the target database;

[0021] A full set of scripts acquisition module, configured to acquire the full set of scripts of the target database, where the full set of scripts includes one or more reference database scripts, and each reference database script has a corresponding reference script version baseline;

[0022] A matching script set determination module, configured to match each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence, where the matching script set includes the reference script version baseline that matches each script version baseline and the corresponding reference database script;

[0023] A script execution module, configured to execute each reference database script in the matching script set in the target container to obtain a database instance script;

[0024] A script difference analysis module, configured to compare the target database script with the database instance script to generate the difference information between the two.

[0025] According to a third aspect of the present application, there is provided an electronic device, the electronic device comprising:

[0026] at least one processor; and

[0027] a memory communicatively connected to the at least one processor; wherein,

[0028] the memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the method of the first aspect above.

[0029] According to a fourth aspect of the present application, there is provided a computer-readable storage medium storing computer instructions for implementing the method of the first aspect above when executed by a processor.

[0030] According to a fifth aspect of the present application, there is provided a computer program product comprising computer-executable instructions for implementing the method of the first aspect above when executed.

[0031] In this embodiment, a script version baseline is adopted to maintain database scripts. After obtaining the target database script of the target environment and the corresponding script version baseline sequence, the target database corresponding to the target database script can be determined, and a target container corresponding to the target database can be created. Then, a matching script set corresponding to the script version baseline sequence is matched from the full-scale script set of the target database, and a database instance script is obtained by executing the matching script set in the target container. By comparing the database instance script with the target database script of the target environment, the differences between the two can be obtained, thereby realizing the dynamic differential analysis of database scripts, quickly identifying the script differences of databases in different environments, reducing errors, and providing a basis for data environment migration and version online. It can also meet the customer's customized requirements, support the customer to independently develop database scripts and then identify the differential scripts to prevent script conflicts.

[0032] In addition, by the above method of automatically identifying differential scripts, this embodiment can reduce manual intervention, avoid on-site changes to production environment scripts by operation and maintenance personnel, reduce human judgment errors, be able to detect problems in a timely manner, avoid the occurrence of production accidents, and can significantly reduce the probability of production events. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] To more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0034] Figure 1 It is a flowchart of an embodiment of a database script control method provided in Embodiment 1 of the present application;

[0035] Figure 2 It is a flowchart of an embodiment of a database script control method provided in Embodiment 2 of the present application;

[0036] Figure 3 It is a flowchart of an embodiment of generating a full - volume script set provided in Embodiment 2 of the present application;

[0037] Figure 4 It is a schematic diagram of a full - volume version baseline provided in Embodiment 2 of the present application;

[0038] Figure 5 It is a schematic diagram of version baseline comparison provided in Embodiment 2 of the present application;

[0039] Figure 6 It is a structural block diagram of an embodiment of a database script control system provided in Embodiment 3 of the present application;

[0040] Figure 7 It is a structural schematic diagram of an electronic device provided in Embodiment 4 of the present application. Detailed implementation manners

[0041] To enable those skilled in the art to better understand the solutions of the present application, the following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, rather than all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0042] It should be noted that the terms "first", "second", etc. in the description, claims and above-mentioned drawings of this application are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances, so that the embodiments of this application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0043] In addition, it should also be noted that in the following embodiments of this application, the acquisition, storage, use, processing, etc. of data all comply with the relevant regulations of national laws and regulations.

[0044] Embodiment 1

[0045] Figure 1 It is a flowchart of an embodiment of a database script control method provided for Embodiment 1 of this application. This embodiment can be applied to a database script control system, and the database script control system can be set in a server for controlling database scripts.

[0046] As Figure 1 shown, this embodiment may include the following steps:

[0047] Step 101, determine the target database script in the target environment, and obtain the script version baseline sequence of the target environment.

[0048] Among them, the target environment can be the target database environment that needs to be compared and analyzed, and can include a development environment, a test environment, a production environment, or a database environment deployed for a specific customer, etc.

[0049] A database script is a collection of statements for creating database objects, that is, after the server executes the database script, the corresponding database is generated. In one implementation, the latest database script of the target environment can be exported from the script file of the target environment as the target database script.

[0050] In this embodiment, the script version baseline sequence of the target environment can also be obtained. The script version baseline sequence can include multiple script version baselines arranged in chronological order, and each script version baseline has a corresponding database script. In this embodiment, each version of the database script is managed by managing each script version baseline.

[0051] In one implementation, the target database script and the script version baseline sequence can be obtained from the script file of the target environment.

[0052] Step 102: Determine the target database corresponding to the target database script, and create a target container corresponding to the target database.

[0053] In one implementation, the target database script may contain a database identifier. Therefore, the database identifier can be extracted from the target database script, and the database corresponding to the database identifier is used as the target database.

[0054] After determining the target database, a target container corresponding to the target database can be created. Among them, the target container is the database container environment corresponding to the target database.

[0055] The initial state of the target container contains a blank database instance, and the database script can be executed in the blank database instance subsequently.

[0056] In one implementation, the corresponding target container can be created by obtaining the container configuration information of the target database.

[0057] Step 103: Obtain the full set of scripts of the target database.

[0058] Among them, the full set of scripts may include one or more reference database scripts, and each reference database script has a corresponding reference script version baseline. The reference database script is the database script under control in the target database, and may include, for example, the initial database script and the changed database script for each change.

[0059] Each time a database script of the target database is added to the control, the script version baseline of the database script can be generated according to the set baseline generation rule as the reference script version baseline. Then, the database script with the reference script version baseline is stored in the full set of scripts.

[0060] Among them, the script version baseline can carry various information, and the script version baselines can be sorted according to the information carried by the script version baseline.

[0061] Step 104: Match each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence.

[0062] After obtaining the full set of scripts, the script version baselines in the script version baseline sequence for the target environment can be searched from the full set of scripts, and the corresponding reference database scripts found are composed into a matching script set. That is, the matching script set can include the reference script version baselines that match each script version baseline and the corresponding reference database scripts.

[0063] Step 105: Execute each reference database script in the matching script set in the target container to obtain a database instance script.

[0064] In the target container, each reference database script in the matching script set can be executed in sequence in a blank database instance, and finally a database instance script is obtained.

[0065] Step 106: Compare the target database script with the database instance script to generate the difference information between the two.

[0066] After obtaining the database instance script exported from the target container, the target database script in the target environment can be compared with this database instance script to obtain the difference information between the two.

[0067] Exemplarily, the difference information can include but is not limited to at least one of a difference report and an incremental script.

[0068] Based on different requirements, difference reports in different formats can be generated, such as HTML, XML, or JSON, etc., for manual reading and machine checking. The difference report can include the script differences of various types of scripts.

[0069] The incremental script is an incremental script generated based on the difference formed relative to the target environment with the database instance script exported after the execution of the target container. The incremental script is an executable script.

[0070] In this embodiment, script version baselines are used to maintain database scripts. After obtaining the target database script of the target environment and the corresponding script version baseline sequence, the target database corresponding to the target database script can be determined, and a target container corresponding to the target database can be created. Then, a matching script set corresponding to the script version baseline sequence is matched from the full set of scripts of the target database, and a database instance script is obtained by executing the matching script set in the target container. Comparing the database instance script with the target database script of the target environment can obtain the difference between the two, thereby realizing the dynamic differential analysis of database scripts, quickly identifying the script differences of databases in different environments, reducing errors, and providing a basis for data environment migration and version online. It can also meet the customer's customization requirements, support the customer to independently develop database scripts and then identify the differential scripts to prevent script conflicts.

[0071] In addition, through the above method of automatically identifying differential scripts, this embodiment can reduce manual intervention, avoid on-site script changes to the production environment by operation and maintenance personnel, reduce human judgment errors, detect problems in a timely manner, avoid the occurrence of production accidents, and significantly reduce the probability of production incidents.

[0072] Embodiment 2

[0073] Figure 2 FIG. is a flowchart of an embodiment of a database script control method provided in Embodiment 2 of this application. This embodiment will be described in more detail on the basis of Embodiment 1. As Figure 2 shown, this embodiment may include the following steps:

[0074] Step 201, determine the target database script in the target environment.

[0075] The target environment may be a target database environment that needs to be compared and analyzed, and may include a development environment, a test environment, a production environment, or a database environment deployed for a specific customer, etc.

[0076] In one implementation, the latest database script of the target environment may be exported from the script file of the target environment as the target database script. Among them, the database script is a collection of statements for creating database objects, that is, after the server executes the database script, the corresponding database is generated. Among them, database objects may include, but are not limited to: databases, data tables, indexes, views, triggers, functions, etc. Then the database script may include, but is not limited to, statements for establishing databases, data tables, stored procedures, triggers, and statements for data query and custom functions, etc.

[0077] Step 202, obtain the script version baseline sequence of the target environment.

[0078] Among them, the script version baseline sequence may include the script version baselines of the initial database script and the incremental database script (or called the change database script) sorted in chronological order.

[0079] In one implementation, the script version baseline sequence may be read from the script file of the target environment. In one embodiment, each time the target environment obtains a database script, the corresponding script version baseline may be extracted from the database script and the script version baseline may be recorded. In another embodiment, if the script version baseline carried in the database script cannot be found, the script version baseline may be generated according to the set baseline generation rule and the script version baseline may be recorded.

[0080] When recording the script version baseline, the recorded script version baseline may be recorded in chronological order.

[0081] The script version baseline can be represented by a script version baseline identifier. Exemplarily, the script version baseline identifier can at least include the following: data classification, system name, version number, version baseline establishment date, file name suffix, etc. Among them, the system name can be the English abbreviation of the system or the combination of the first Chinese characters. The version number can be dynamically determined according to the actual update frequency. If it is less than the previous number, it is filled with 0 in front, and 1 can be added for subsequent changes. For example, if the script version baseline identifier is M_XXXXX_0001_20210522.SQL, it means that the data classification is MYSQL, the system name is XXXXX, the version number is version 0001, and the version baseline establishment date is May 22, 2021. It corresponds to the version baseline of MYSQL, XXXXX system, version 0001, and May 22, 2021.

[0082] It should be noted that the naming method of the script version baseline can be changed according to requirements, and it is not limited to the above naming method, but it needs to meet two standards: continuous and ordered.

[0083] Step 203: Determine the target database corresponding to the target database script.

[0084] In one implementation, the target database script can contain a database identifier. Therefore, the database identifier can be extracted from the target database script, and the database corresponding to the database identifier can be used as the target database.

[0085] Step 204: Create a target container corresponding to the target database.

[0086] After the target database is determined, a target container corresponding to the target database can be created. Among them, the target container is the database container environment corresponding to the target database. The initial state of the target container contains a blank database instance. This is to ensure the integrity and verifiability of the script. The script needs to actually run in the database instance. Therefore, the container environment needs to contain an actual database instance.

[0087] It should be noted that the target container can be a dynamic resource environment. The term "dynamic" can be expressed as dynamically pulling and starting when needed. After starting, the database instance is automatically ready. After executing the script and completing subsequent steps, it can be released according to requirements.

[0088] In one embodiment, the step of creating a target container corresponding to the target database can include the following steps:

[0089] Execute the environment preparation instruction to pull the container configuration related to the target database from the preset configuration library; based on the container configuration, execute the start instruction to complete the preparation of the container environment.

[0090] Specifically, corresponding container configurations can be pre-configured for each database and stored in a configuration library. After determining the target database, an environment preparation instruction can be used to trigger the search for the container configuration corresponding to the target database in the configuration library, and then a startup instruction can be used to trigger the creation of the target container based on the container configuration, thereby completing the preparation of the container environment.

[0091] Step 205: Obtain the full set of scripts of the target database.

[0092] After determining the target database, the full set of scripts pre-generated for the target database can be obtained. The full set of scripts can include one or more reference database scripts, and each reference database script has a corresponding reference script version baseline. The reference database script can exemplarily include an initial database script and a change database script (or incremental database script).

[0093] In one embodiment, as Figure 3 shown, the full set of scripts of the target database can be generated in the following manner:

[0094] S1: Obtain the initial database script, determine the initial version baseline based on the initial database script, and add the initial database script carrying the initial version baseline to the full set of scripts.

[0095] The initial database script is the target database structure information, which can include full set of database creation scripts such as database name, table name, view, fields, field attributes, and indexes. For example, the initial database script can include creation statements for database, table, view, index, space, log, resources, etc.

[0096] It should be noted that the initial database script referred to in this embodiment is not exactly the same as the online script in the initial stage of system construction. It can be the full set of scripts obtained by bringing the scripts under the control of this embodiment during the system life cycle. The role of the initial database script is to establish the initial version baseline, and subsequent script versions are incrementally iterated based on this.

[0097] In one implementation, the step of determining the initial version baseline based on the initial database script can further include the following steps:

[0098] Import the initial database script into a preset configuration library to establish the initial version baseline corresponding to the initial database script in the configuration library.

[0099] After importing the initial database script into the configuration library, the initial database script no longer changes, and the initial version baseline is also the first established and stable version baseline.

[0100] S2. Obtain the change database scripts for each change respectively, determine the corresponding change version baselines based on the change database scripts respectively, and add the change database scripts carrying the corresponding change version baselines to the full script set.

[0101] Specifically, when determining the corresponding change version baseline based on the change database script, the change database script can be imported into the configuration library to establish the change version baseline corresponding to the change database script in the configuration library. Among them, the change database script is an incremental script and will not change after being imported into the configuration library and establishing the change version baseline. Subsequent iterations are still incremental scripts, and new change version baselines are established.

[0102] The change database script can include, but is not limited to, creation statements and change statements for tables, views, indexes, spaces, logs, resources, etc. However, it should be noted that the deletion statements need to be independently controlled to prevent data loss.

[0103] It should be noted that the full script set is dynamically maintained and updated. By continuously collecting change database scripts, generating the script version baselines corresponding to the change database scripts, and then storing the change database scripts and the corresponding script version baselines in the full script set, the management of database scripts is realized.

[0104] For example, as Figure 4 shown in the schematic diagram of the full version baseline, the initial version baseline V1 was established on May 22, 2021 through the initial database script. For each subsequent change, the version baseline is incremented by 1. For example, in Figure 4 on June 15, 2021, a change database script was added to the initial database script, and the corresponding change version baseline V2 was established; then on July 30, 2021, a change database script was submitted on the basis of version V2, and the change version baseline V3 corresponding to the change database script was established, and so on. The last submitted change database script was on January 30, 2022, and the corresponding change version baseline Vn was established. Since the change database scripts are continuous, after the initial version baseline is established, all subsequent changes need to be included in the scope of change version baseline control, so as to achieve baseline management.

[0105] Different from traditional configuration management, in this embodiment, each change is not made to the same database script file, but a new change database script is established, and the version baseline of the new change database script is formed.

[0106] In implementation, the data acquisition unit can be used to connect to the target database and obtain the corresponding full script set. The connection information corresponding to the connection can include, for example, database category, database connection, database user name, and login password information, etc.

[0107] Step 206: Match each script version baseline in the full script set to generate a matching script set that matches the script version baseline sequence.

[0108] The matching script set includes the reference script version baseline that matches each script version baseline, the corresponding reference database script, and the corresponding reference script version baseline.

[0109] The process of step 206 can be completed outside the target container or inside the target container. When it is completed inside the target container, in one embodiment, step 206 may include the following steps:

[0110] Send the full script set and the script version baseline sequence to the target container; in the target container, match each script version baseline in the full script set to generate a matching script set that matches the script version baseline sequence.

[0111] In this embodiment, determine the matching script set in the target container. Specifically, import both the full script set and the script version baseline sequence into the target container, and then perform baseline matching in the target container to find the reference database scripts that match each script version baseline in the script version baseline sequence, and form the matching script set.

[0112] In a further embodiment, the information carried in the script version baseline may include version order information (such as the version number and baseline establishment date in the above text). The version order information carried in each script version baseline can be used to determine the matching order of each script version baseline. Then, the step of generating the matching script set may further include the following process:

[0113] In the order of the version order information, sequentially search for each script version baseline in the script version baseline sequence in the full script set; add the reference script version baseline that is the same as the script version baseline found in the full script set and the corresponding reference database script to the matching script set.

[0114] Specifically, it can start matching from the first script version baseline (i.e., the initial version baseline). After successful matching, add the corresponding reference database to the matching script set, and then perform the matching of the second script version baseline, and so on.

[0115] In a further embodiment, if a certain script version baseline in the script version baseline sequence cannot find the corresponding reference script version baseline in the full script set, then the step of generating the matching script set may further include the following process:

[0116] Obtain the last reference script version baseline in the obtained matching script set, and add the next reference version baseline of the last reference script version baseline and the corresponding reference database script in the full script set to the matching script set.

[0117] That is, add the next reference version baseline to be matched in the full script set and the corresponding reference database script to the matching script set.

[0118] For example, in Figure 5 , what needs to be compared are the full version baselines (V1, V2,..., Vn) of the target database and the script version baseline sequence (V1, V2,..., Vk) of the target environment. The script corresponding to the version baseline Vk of the target environment is changed from the script of the version baseline Vm of the target database. In the target environment, Vm is re-changed to obtain Vk, and the content of this re-change includes the new change from Vm to Vk and the unrecognized changes that were not included in the change control scope in the previous versions.

[0119] When performing baseline comparison, first search for V1 in the script version baseline sequence in the full version baseline. When V1 is found, add V1 and the corresponding script to the matching script set, and continue to search for V2, and so on. When Vk is found and it is found that Vk does not exist in the full version baseline, it means that Vk is a re-change based on the target environment. At this time, find Vm corresponding to Vk in the full version baseline, and add Vm to the matching script set as a matching script.

[0120] Step 207, in the target container, based on the version order information, sequentially execute each reference database script, and obtain the database instance script exported from the target container after all the reference database scripts in the matching script set are executed.

[0121] Among them, when step 206 is completed inside the target container, the operation of step 207 can be directly performed after determining the matching script set. If step 206 is completed outside the target container, after determining the matching script set, the matching script set needs to be imported into the target container.

[0122] In the target container, each reference database script in the matching script set can be sequentially executed in a blank database instance, and finally the database instance script is obtained. Specifically, first execute the initial database script corresponding to the initial version baseline, then execute the changed database script corresponding to the changed version baseline obtained after the first change, then execute the changed database script of the second change, and so on, until the execution of the last changed database script is completed, and the database instance script is obtained.

[0123] Step 208: Compare the target database script with the database instance script to generate at least one of a difference report and an incremental script.

[0124] In one embodiment, step 208 may further include the following steps:

[0125] Structurally process the target database script and the database instance script respectively, and compare the structurally processed target database script and database instance script one by one according to the script type to determine the differences of each script type, and generate at least one of a difference report and an incremental script.

[0126] Exemplarily, the script type may include but is not limited to: data tables, views, fields, indexes, etc. Then, the difference report may include but is not limited to the following information: difference information such as table names, views, fields, field attributes, and indexes. It should be noted that based on different requirements, different formats of difference reports can be generated, such as HTML, XML, or JSON, etc., for manual reading and machine checking.

[0127] The incremental script is an incremental script generated based on the database instance script exported after the target container is executed and formed by the differences relative to the target environment, and the incremental script is an executable script.

[0128] This embodiment has the following beneficial effects:

[0129] First, it can reduce manual intervention, avoid on-site script changes to the production environment by operation and maintenance personnel, discover problems in a timely manner, and avoid the occurrence of production accidents, which can significantly reduce the probability of production incidents.

[0130] Second, it can quickly identify the differences between database scripts in different environments, reduce errors, and provide a basis for data environment migration.

[0131] Third, at the same time, it can meet the customer's customization needs, support the identification of difference scripts after the customer's independent development, and prevent script conflicts.

[0132] Embodiment Three

[0133] Figure 6 The structural block diagram of an embodiment of a database script control system provided in Embodiment Three of this application may include the following modules:

[0134] The target database script determination module 301 is used to determine the target database script in the target environment;

[0135] The baseline sequence acquisition module 302 is used to acquire the script version baseline sequence of the target environment;

[0136] A target database determination module 303, configured to determine a target database corresponding to the target database script;

[0137] A target container creation module 304, configured to create a target container corresponding to the target database;

[0138] A full - volume script set acquisition module 305, configured to acquire a full - volume script set of the target database, where the full - volume script set includes one or more reference database scripts, and each reference database script has a corresponding reference script version baseline;

[0139] A matching script set determination module 306, configured to match each script version baseline in the script version baseline sequence in the full - volume script set, and generate a matching script set that matches the script version baseline sequence, where the matching script set includes a reference script version baseline that matches each script version baseline and a corresponding reference database script;

[0140] A script execution module 307, configured to execute each reference database script in the matching script set in the target container to obtain a database instance script;

[0141] A script difference analysis module 308, configured to compare the target database script with the database instance script to generate difference information between the two.

[0142] In one embodiment, the target container creation module 304 is specifically configured to:

[0143] Execute an execution environment preparation instruction to pull container configurations related to the target database from a preset configuration library;

[0144] Based on the container configuration, execute a start instruction to complete the preparation of the container environment.

[0145] In one embodiment, the reference script version baseline carries version order information; the script execution module 307 is specifically configured to:

[0146] In the target container, based on the version order information, sequentially execute the reference database scripts in order, and obtain the database instance script exported by the target container after all the reference database scripts in the matching script set have been executed.

[0147] In one embodiment, the matching script set determination module 306 is further configured to:

[0148] Send the full - volume script set and the script version baseline sequence to the target container;

[0149] In the target container, each script version baseline in the full script set is matched to generate a matching script set that matches the script version baseline sequence.

[0150] In one embodiment, both the script version baseline and the reference script version baseline have version order information; the matching script set determination module 306 is specifically configured to:

[0151] Search for each script version baseline in the script version baseline sequence in the full script set in sequence according to the sequence of the version order information;

[0152] Add the reference script version baseline that is the same as the script version baseline found in the full script set and the corresponding reference database script to the matching script set.

[0153] In one embodiment, the matching script set determination module 306 is further configured to:

[0154] If a reference script version baseline that is the same as the script version baseline cannot be found in the full script set, obtain the reference script version baseline that is the last in the matching script set;

[0155] Add the next reference version baseline of the last reference script version baseline in the full script set and the corresponding reference database script to the matching script set.

[0156] In one embodiment, the difference information includes at least one of a difference report and an incremental script, and the script difference analysis module 308 is specifically configured to:

[0157] Structurally process the target database script and the database instance script respectively, and compare the structurally processed target database script and the database instance script one by one according to the script type to determine the differences of each script type, and generate at least one of a difference report and an incremental script, where the script types include data tables, views, fields, and indexes.

[0158] In one embodiment, the target database determination module 303 is specifically configured to:

[0159] Obtain a database identifier from the target database script;

[0160] Use the database corresponding to the database identifier as the target database.

[0161] In one embodiment, it may further include a full script set generation module for:

[0162] Obtain an initial database script, determine an initial version baseline based on the initial database script, and add the initial database script carrying the initial version baseline to a full-scale script set;

[0163] Respectively obtain changed database scripts for each change, respectively determine changed version baselines based on the changed database scripts, and add the changed database scripts carrying the corresponding changed version baselines to the full-scale script set.

[0164] In one embodiment, the full-scale script set generation module is further configured to:

[0165] Import the initial database script into a preset configuration library to establish an initial version baseline corresponding to the initial database script in the configuration library.

[0166] In one embodiment, the baseline sequence acquisition module 302 is specifically configured to:

[0167] Read the script version baseline sequence from the script file of the target environment.

[0168] A database script control system provided by an embodiment of the present application can execute a database script control method in Embodiment 1 or Embodiment 2 of the present application, and has corresponding functional modules and beneficial effects for executing the method.

[0169] Embodiment 4

[0170] Figure 7 FIG. shows a schematic structural diagram of an electronic device 10 that can be used to implement the method embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.

[0171] As Figure 7As shown, the electronic device 10 includes at least one processor 11 and a memory communicatively connected to the at least one processor 11, such as read-only memory (ROM) 12, random access memory (RAM) 13, etc. The memory stores a computer program executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, ROM 12, and RAM 13 are connected to each other via a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.

[0172] Multiple components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disc, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.

[0173] The processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the methods described in Embodiment 1 or Embodiment 2.

[0174] In some embodiments, the method described in Embodiment 1 or Embodiment 2 can be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method described in Embodiment 1 or Embodiment 2 above can be executed. Alternatively, in other embodiments, the processor 11 can be configured to execute the method described in Embodiment 1 or Embodiment 2 by any other appropriate means (e.g., by means of firmware).

[0175] The various embodiments of the systems and techniques described above in this specification can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems-on-chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that receives data and instructions from, and transmits data and instructions to, a storage system, at least one input device, and at least one output device.

[0176] The computer programs for implementing the methods of this application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The computer programs can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.

[0177] In the context of this application, a computer-readable storage medium can be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0178] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the electronic device. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0179] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area network (LAN), wide area network (WAN), blockchain network, and the Internet.

[0180] The computing system can include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system and solves the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.

[0181] It should be understood that various forms of the processes shown above can be used, with steps reordered, added, or deleted. For example, the steps recited in this application can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of this application can be achieved, and no limitation is imposed herein.

[0182] The above specific implementation manners do not constitute a limitation on the protection scope of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principle of this application shall be included within the protection scope of this application.

Claims

1. A database script control method, characterized in that, The method includes: Determine a target database script in a target environment, and obtain a script version baseline sequence of the target environment; Determine a target database corresponding to the target database script, and create a target container corresponding to the target database; Obtain a full set of scripts of the target database, where the full set of scripts includes one or more reference database scripts, and each reference database script has a corresponding reference script version baseline; Match each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence, where the matching script set includes the reference script version baselines that match each script version baseline and the corresponding reference database scripts; Execute each reference database script in the matching script set in the target container to obtain a database instance script; Compare the target database script with the database instance script to generate difference information between the two.

2. The method according to claim 1, wherein The creating a target container corresponding to the target database includes: Execute an environment preparation instruction to pull container configurations related to the target database from a preset configuration library; Based on the container configurations, execute a start instruction to complete the preparation of the container environment.

3. The method according to claim 1 or 2, characterized in that, The reference script version baseline carries version order information; The executing each reference database script in the matching script set in the target container to obtain a database instance script includes: In the target container, based on the version order information, sequentially execute the reference database scripts in order, and obtain the database instance script exported by the target container after all the reference database scripts in the matching script set have been executed.

4. The method according to claim 3, wherein The matching each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence includes: Send the full set of scripts and the script version baseline sequence to the target container; In the target container, match each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence.

5. The method according to claim 1, characterized in that Both the script version baseline and the reference script version baseline have version order information; the matching each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence includes: Sequentially search for each script version baseline in the script version baseline sequence in the full set of scripts in the order of the version order information; Add the reference script version baseline that is the same as the script version baseline found in the full set of scripts and the corresponding reference database script to the matching script set.

6. The method according to claim 5, characterized in that, The matching each script version baseline in the script version baseline sequence in the full set of scripts to generate a matching script set that matches the script version baseline sequence further includes: If a reference script version baseline identical to the script version baseline cannot be found in the full script set, obtain the last reference script version baseline in the matching script set; In the full script set, add the next reference version baseline of the last reference script version baseline and the corresponding reference database script to the matching script set.

7. The method according to claim 1, characterized in that, The difference information includes at least one of a difference report and an incremental script. Comparing the target database script with the database instance script to generate the difference information between the two includes: Structurally process the target database script and the database instance script respectively, and compare the structurally processed target database script and database instance script one by one according to the script type to determine the differences of each script type, and generate at least one of a difference report and an incremental script, where the script types include data tables, views, fields, and indexes.

8. The method according to claim 1, characterized in that, Determining the target database corresponding to the target database script includes: Obtain the database identifier from the target database script; Use the database corresponding to the database identifier as the target database.

9. The method according to claim 8, wherein The full script set of the target database is generated in the following manner: Obtain the initial database script, determine the initial version baseline based on the initial database script, and add the initial database script carrying the initial version baseline to the full script set; Obtain the changed database scripts for each change respectively, determine the change version baselines based on the changed database scripts respectively, and add the changed database scripts carrying the corresponding change version baselines to the full script set.

10. The method according to claim 9, wherein Determining the initial version baseline based on the initial database script includes: Import the initial database script into a preset configuration library to establish the initial version baseline corresponding to the initial database script in the configuration library.

11. The method according to claim 1, characterized in that Obtaining the script version baseline sequence of the target environment includes: Read the script version baseline sequence from the script file of the target environment.

12. A database script control system, characterized in that, The system includes: A target database script determination module for determining the target database script in the target environment; A baseline sequence acquisition module for acquiring the script version baseline sequence of the target environment; A target database determination module for determining the target database corresponding to the target database script; A target container creation module for creating a target container corresponding to the target database; A full script set acquisition module for acquiring the full script set of the target database, where the full script set includes one or more reference database scripts, and each reference database script has a corresponding reference script version baseline; A matching script set determination module for matching each script version baseline in the script version baseline sequence in the full script set to generate a matching script set that matches the script version baseline sequence, where the matching script set includes the reference script version baselines that match each script version baseline and the corresponding reference database scripts; A script execution module, configured to execute each reference database script in the matched script set in the target container to obtain a database instance script; A script difference analysis module, configured to compare the target database script with the database instance script to generate difference information between the two.

13. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and when the computer program is executed by the at least one processor, the at least one processor is enabled to execute the method according to any one of claims 1-11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the method according to any one of claims 1-11 when executed by a processor.

15. A computer program product, the computer program product includes computer-executable instructions, and the computer-executable instructions are used to implement the method according to any one of claims 1-11 when executed.

Citation Information

Patent Citations

  • Database version changing method and device, storage medium and electronic device

    CN114840489A

  • Database management and control method and device, computer equipment and storage medium

    CN114880306A