Method, device, equipment and medium for synchronous execution of SQL script test environment
By obtaining the latest submission record hash value of the code warehouse and comparing the SQL script difference information during the continuous integration process, SQL scripts are executed synchronously, which solves the problem of abnormal parameters caused by differences in test environments and achieves the accuracy and reliability of data changes. flexibility, improving deployment efficiency and traceability.
Patent Information
- Application Number
- CN202411054463.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-08-02
AI Technical Summary
The existing technology fails to effectively consider the differences in test environments during the SQL script synchronization process, resulting in abnormal target database parameters and the inability to verify whether there are problems with the online SQL script.
During the continuous integration process, use the task deployment configuration information of the Jenkins build task to obtain the latest submission record hash value of the code warehouse, determine the difference information from the preset SQL script submission record table, and perform the SQL script synchronization execution process, including full and Differential rollback mechanism ensures that the latest SQL script is used for each deployment.
It improves the accuracy and reliability of data changes, improves task deployment efficiency and traceability of operation execution results, and ensures the consistency of the test environment data structure and data.
Smart Images

Figure CN118585457B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software testing, and in particular to a method, device, equipment and medium for synchronously executing a SQL script test environment. Background Art
[0002] In the actual software development and testing process, there are usually multiple test environments for testing and verification at different stages. To achieve different requirements, multiple SQL (Structured Query Language) scripts will be executed. Due to differences in different test environments or failure to notify SQL script changes in a timely manner, there may be situations where SQL scripts are not executed correctly, resulting in abnormal test environments.
[0003] In the existing technical solution, the structure of the source database and the target database are compared to automatically obtain the synchronized SQL script, and then the SQL script is executed in the target database to complete the structure synchronization. The data synchronization is to fully export the source database and then import it into the target database. This method does not take into account the differences in the test environment. If some parameters in the parameter configuration table are different in different test environments, full data synchronization will cause the target database to obtain related parameters abnormally, and it is also impossible to verify whether there are problems with the online SQL script. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a method, device, equipment and medium for a SQL script synchronous execution test environment, which can not only improve the accuracy and reliability of data changes, but also improve the efficiency of task deployment and the traceability of operation execution results. The specific scheme is as follows:
[0005] In a first aspect, the present application provides a method for synchronously executing a SQL script in a test environment, comprising:
[0006] In the process of continuous integration, the code information under the code repository address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest submission record of the server is obtained;
[0007] Determine whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and obtain a corresponding first determination result;
[0008] If the first judgment result indicates existence, determine whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table to obtain a corresponding second judgment result;
[0009] If the second judgment result indicates inconsistency, the target difference information between the target hash value and the target submission record information is obtained, and the target difference information and the task deployment configuration information are used to complete the corresponding SQL script synchronization execution process.
[0010] Optionally, the code information under the code repository address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest local submission record of the server is obtained, including:
[0011] Pull the code information under the code repository address of the current system based on the system name and code branch in the task deployment configuration information;
[0012] By storing the code information in the code pull path corresponding to the current test environment, querying the local code submission record of the server of the current test environment;
[0013] Based on the code submission record, a target hash value of the latest submission record locally on the server is obtained.
[0014] Optionally, after obtaining the corresponding first judgment result, the method further includes:
[0015] When the first judgment result indicates that it does not exist, a new record information is added to the preset SQL script submission record table based on the target hash value;
[0016] Or, query the target submission record information with the latest creation time in the preset SQL script submission record table, and obtain the SQL script file submitted to the Gitlab code repository of the current system according to the target submission record information, so as to save the SQL script file to the script file storage path corresponding to the server of the current test environment;
[0017] Or, the SQL script file is traversed and run at the database address corresponding to the current test environment, and when the operation fails, the corresponding SQL rollback script is traversed and executed.
[0018] Optionally, after obtaining the corresponding second judgment result, the method further includes:
[0019] If the second judgment result indicates that the target hash value is consistent with the target submission record information, the deployment operation of the current Jenkins build task is terminated and completed based on the preset code package deployment mode configuration information;
[0020] When a task deployment fails, check the corresponding deployment log to find the cause.
[0021] Optionally, if the second judgment result indicates inconsistency, obtaining target difference information between the target hash value and the target submission record information includes:
[0022] If the second judgment result indicates inconsistency, determining whether the SQL script information corresponding to the target hash value and the SQL script information corresponding to the target submission record information are the same by comparison, so as to obtain a corresponding third judgment result;
[0023] When the third judgment result indicates that the SQL script corresponding to the target hash value is different from the SQL script corresponding to the target submission record information, the corresponding target difference information is obtained.
[0024] Optionally, the using the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronous execution process includes:
[0025] By parsing the target difference information, a corresponding target execution script file and a target fallback script file are obtained;
[0026] When the current rollback mode is determined to be a full rollback based on the rollback parameters in the task deployment configuration information, the SQL rollback script corresponding to the target submission record information saved in the script file storage path of the current test environment is traversed and run, and the SQL execution script corresponding to the target hash value is run;
[0027] When it is determined that the current rollback mode is differential rollback based on the rollback parameters in the task deployment configuration information, the target execution script file is traversed and run in the current test environment, and the target rollback script file is traversed and run when the execution fails.
[0028] Optionally, the method further includes:
[0029] If the SQL execution script corresponding to the target hash value is successfully executed, or the target execution script file is successfully traversed and executed in the current test environment, a new record information is added to the preset SQL script submission record table based on the target hash value;
[0030] If the SQL execution script corresponding to the target hash value fails to be executed, then after traversing and executing the SQL rollback script corresponding to the target hash value, the SQL execution script corresponding to the target submission record information is executed.
[0031] In a second aspect, the present application provides a device for a SQL script synchronous execution test environment, comprising:
[0032] The hash value acquisition module is used to store the code information under the code repository address of the current system to the corresponding code pull path through the task deployment configuration information of the current Jenkins build task during the continuous integration process, and obtain the target hash value of the latest submission record on the server;
[0033] The first judgment module is used to judge whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and obtain a corresponding first judgment result;
[0034] A second judgment module is used to judge whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table if the first judgment result indicates existence, so as to obtain a corresponding second judgment result;
[0035] The synchronous execution process completion module is used to obtain the target difference information between the target hash value and the target submission record information if the second judgment result shows inconsistency, and use the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronous execution process.
[0036] In a third aspect, the present application provides an electronic device, including:
[0037] Memory, used to store computer programs;
[0038] The processor is used to execute the computer program to implement the steps of the aforementioned method for synchronously executing the SQL script test environment.
[0039] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, which, when executed by a processor, implements the steps of the aforementioned method for synchronously executing a test environment with a SQL script.
[0040] It can be seen that in this application, in the process of continuous integration, the code information under the code warehouse address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest submission record of the server is obtained; it is judged whether there is a record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and the corresponding first judgment result is obtained; if the first judgment result shows that it exists, it is judged whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table to obtain the corresponding second judgment result; if the second judgment result shows that it is inconsistent, the target difference information between the target hash value and the target submission record information is obtained, and the corresponding SQL script synchronization execution process is completed using the target difference information and the task deployment configuration information. That is, in this application, by connecting the SQL script execution process to the continuous integration process, it is ensured that each task deployment pulls the latest submitted SQL script, and at the same time, synchronization is completed by comparing the target hash value of the latest submission record in the current code warehouse with the difference information between the target submission record information of the latest submission record saved in the preset SQL script submission record table. This not only improves the accuracy and reliability of data changes, but also improves the efficiency of task deployment and the traceability of operation execution results. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0042] Figure 1 A method flow chart of a SQL script synchronous execution test environment provided by this application;
[0043] Figure 2 A flowchart of a method for synchronous execution of a SQL script test environment provided by this application;
[0044] Figure 3 A schematic diagram of a code segment for obtaining a target hash value provided by this application;
[0045] Figure 4 A schematic diagram of a code segment for obtaining target submission record information provided by this application;
[0046] Figure 5 A schematic diagram of a code segment for difference information processing provided by this application;
[0047] Figure 6 A schematic diagram of the device structure of a SQL script synchronous execution test environment provided by this application;
[0048] Figure 7 A structural diagram of an electronic device provided for this application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] In the existing technical solutions, the synchronized SQL is automatically obtained by comparing the structures of the source database and the target database, and then the SQL script is executed in the target database to complete the structural synchronization. The data synchronization is to export the source database in full and then import it into the target database. This method does not take into account the differences in the test environment. If some parameters in the parameter configuration table are different in different test environments, full data synchronization will cause the target database to obtain related parameters abnormally, and it is also impossible to verify whether there is a problem with the online SQL script. To this end, the present application provides a solution for the synchronous execution of SQL scripts in the test environment, which can not only improve the accuracy and reliability of data changes, but also improve the efficiency of task deployment and the traceability of operation execution results.
[0051] See also Figure 1 As shown, an embodiment of the present invention discloses a method for synchronously executing a SQL script test environment, comprising:
[0052] Step S11: During the continuous integration process, the code information under the code repository address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest submission record of the server is obtained.
[0053] In this embodiment, it is necessary to understand that before starting, a SQL script submission record table needs to be created in advance to record the newly added submission record ID (Identity document), system name, code branch, test environment, creation time, creator and other fields, that is, the preset SQL script submission record table. At the same time, a new configuration file is added, and the configuration content includes the gitlab code warehouse address remote_url of different systems, the server address corresponding to different test environments, the database address, the code pull path local_path, and the script file storage path file_path.
[0054] Afterwards, combined Figure 2 As shown, the newly added SQL script synchronous execution method is obtained, and the input parameters are system name, code branch, test environment, fallback mode and other parameters, that is, task deployment configuration information. Take Jenkins (a Java-based independent program that can be run immediately, including Windows, Mac OS X and other Unix-like operating systems) build task as an example. The task deployment configuration information of the current Jenkins build task stores the code information under the code warehouse address of the current system to the corresponding code pull path, and obtains the target hash value of the latest local submission record of the server, including: based on the system name and code branch in the task deployment configuration information, pull the code information under the code warehouse address remote_url of the current system; by storing the code information in the code pull path local_path corresponding to the current test environment, query the local code submission record of the server of the current test environment; based on the code submission record, obtain the target hash value of the latest local submission record of the server. It can be understood that the code warehouse address and the code pull path can be queried from the pre-created configuration file. Specifically, the target hash value is a 40-bit hash value, and the target hash value is assigned to commit_id. The specific code segment is as follows Figure 3 shown.
[0055] In addition, you also need to save the SQL script file corresponding to the commit_id submission record locally on the current server.
[0056] It should be understood that the scripts pulled in this embodiment are based on SQL scripts (ddl and dml scripts) written according to the writing specifications and submitted by developers to the code repository, including numbered and classified execution scripts and corresponding rollback scripts of the execution scripts. They can be executed in the preset numbering order, and the execution scripts and rollback scripts are distinguished according to the classification, without considering the execution order and classification issues.
[0057] Step S12: determine whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and obtain a corresponding first determination result.
[0058] Combination Figure 2 As shown, in this embodiment, after obtaining the target hash value, it is determined whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table.
[0059] In a specific implementation, when the first judgment result obtained indicates that it does not exist, that is, after the corresponding first judgment result is obtained, it also includes: when the first judgment result does not exist, 1), based on the target hash value, a new record information is added to the preset SQL script submission record table. It should be understood that when adding a new record, the saved submission record ID is commit_id, the system name, code branch and test environment are task deployment configuration information, the creation time = the time of the new operation, and the creator = the operator.
[0060] 2), or, query the target submission record information with the latest creation time in the preset SQL script submission record table, and obtain the SQL script file submitted by the Gitlab code repository of the current system according to the target submission record information, so as to save the SQL script file to the script file storage path corresponding to the server of the current test environment. The specific code segment is as follows Figure 4 shown.
[0061] 3), or, traverse and run the SQL script file at the database address corresponding to the current test environment, and traverse and execute the corresponding SQL fallback script when the operation fails. Specifically, search the SQL script file in the target submission record information folder corresponding to step 2) for the corresponding test environment database address configured in the configuration file, traverse and run the SQL execution script, traverse and execute the SQL fallback script if the operation fails, and end the task if the operation succeeds.
[0062] Step S13: If the first judgment result indicates existence, determine whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table to obtain a corresponding second judgment result.
[0063] Combination Figure 2 As shown, in this embodiment, it should be understood that when the first judgment result indicates existence, the target hash value, commit_id, and the ID of the latest commit record in the current test environment, current system, current code branch creation time in the preset SQL script commit record table are checked to obtain the second judgment result. That is, if there is record information corresponding to the target hash value in the table, it is further determined whether the signature information is consistent.
[0064] Furthermore, after obtaining the corresponding second judgment result, it also includes: if the second judgment result indicates that the target hash value is consistent with the target submission record information, then the deployment operation of the current Jenkins build task is terminated and completed based on the preset code package deployment method configuration information; when the task deployment fails, the cause is checked by viewing the corresponding deployment log. It should be understood that since each build deployment will determine whether to execute the SQL script synchronization method based on the selected parameters in the task configuration, and choose to call the SQL script synchronization method, the code package deployment will be performed only if the method is successfully executed, and the deployment will fail if the execution fails. The deployment log can be checked to check the cause of the failure to ensure that each deployment uses the latest SQL script to synchronize the test environment.
[0065] Step S14: If the second judgment result indicates inconsistency, the target difference information between the target hash value and the target submission record information is obtained, and the target difference information and the task deployment configuration information are used to complete the corresponding SQL script synchronization execution process.
[0066] Specific, combined Figure 2 As shown, in this embodiment, if the second judgment result shows inconsistency, the latest record ID of the creation time of the current code branch of the current test environment current system in the preset SQL script submission record table is queried, that is, the target submission record information is assigned to commit_id_old, and then the SQL scripts in the commit_id and commit_id_old submission records are compared to see whether there is a difference. If there is no difference, the task is terminated; if there is a difference, the subsequent steps are executed. The specific code segment is as follows Figure 5 shown.
[0067] That is to say, in this embodiment, if the second judgment result shows inconsistency, the target difference information between the target hash value and the target submission record information is obtained, including: if the second judgment result shows inconsistency, judging by comparison whether the SQL script information corresponding to the target hash value and the SQL script information corresponding to the target submission record information are the same, so as to obtain a corresponding third judgment result; when the third judgment result shows that the SQL script corresponding to the target hash value and the SQL script corresponding to the target submission record information are different, the corresponding target difference information is obtained.
[0068] Furthermore, the difference file diff.txt obtained by parsing is the target difference information. The difference SQL script file name and file content are obtained by segmenting the file content, and the target execution script file and target rollback script file corresponding to the difference content are generated (for example, according to the difference file analysis, the execution script under the original submission record is to create the A table A1, A2 fields, and the new submission record is to create the A table A1, A3, A4 fields. According to the difference result analysis, after the A table is changed, the A2 field needs to be deleted, and the A3 and A4 fields need to be added. According to the difference result, an execution script for adding A3, A4 and deleting A2 fields and a rollback script for deleting A3, A4 and adding A2 fields will be generated). That is, the use of the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronous execution process includes: by parsing the target difference information, the corresponding target execution script file and target rollback script file are obtained.
[0069] Afterwards, when the current rollback mode is determined to be a full rollback based on the rollback parameters in the task deployment configuration information, the SQL rollback script corresponding to the target submission record information commit_id_old saved in the script file storage path file_path of the current test environment is traversed and run, and the SQL execution script corresponding to the target hash value commit_id is run;
[0070] When the current fallback mode is determined to be differential fallback based on the fallback parameters in the task deployment configuration information, the target execution script of the differential content is obtained and run in the corresponding test environment database, and the target fallback script of the differential content is executed if the run fails. That is, the target execution script file is traversed and run in the current test environment, and the target fallback script file is traversed and run if the run fails.
[0071] In addition, in this embodiment, it also includes: if the SQL execution script corresponding to the target hash value is successfully executed, or the target execution script file is successfully traversed and run in the current test environment, then according to 2) in step S12, a new SQL script submission record is added and the task is ended; if the SQL execution script corresponding to the target hash value fails to be executed, then after traversing and running the SQL rollback script corresponding to the target hash value, the SQL execution script corresponding to the target submission record information is run.
[0072] In the specific implementation process, the above steps can be applied to a variety of continuous deployment tools or platforms. In addition, in summary, in this embodiment, in the process of building a deployment code package, by executing the SQL script synchronization method, multiple records submitted by the code repository are compared to obtain whether there are changes in the SQL script, that is, difference information, and automatically complete the synchronization execution of the latest SQL script in the test environment according to the changes and the corresponding fallback method. In this way, the following beneficial effects exist:
[0073] 1) When SQL scripts are changed, they can be executed synchronously to multiple test environment databases, improving deployment efficiency, reducing manual maintenance costs, and ensuring the data structure and data consistency of the test environment;
[0074] 2) Different rollback modes for SQL script execution can be flexibly converted according to specific test situations, and only the difference parts can be changed to improve test efficiency;
[0075] 3) Multiple SQL change execution records can be traced, which is convenient for subsequent troubleshooting of execution failures and verification of whether the SQL scripts provided by the developer are correct.
[0076] It can be seen that in the embodiment of the present application, in the process of continuous integration, the code information under the code warehouse address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest submission record of the server is obtained; it is judged whether there is a record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and the corresponding first judgment result is obtained; if the first judgment result shows that it exists, it is judged whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table to obtain the corresponding second judgment result; if the second judgment result shows that it is inconsistent, the target difference information between the target hash value and the target submission record information is obtained, and the target difference information and the task deployment configuration information are used to complete the corresponding SQL script synchronization execution process. That is, in this application, by connecting the SQL script execution process to the continuous integration process, it is ensured that each task deployment pulls the latest submitted SQL script, and at the same time, synchronization is completed by comparing the target hash value of the latest submission record in the current code warehouse with the difference information between the target submission record information of the latest submission record saved in the preset SQL script submission record table. This not only improves the accuracy and reliability of data changes, but also improves the efficiency of task deployment and the traceability of operation execution results.
[0077] See also Figure 6 As shown, the embodiment of the present application also discloses a device for synchronously executing a SQL script test environment, including:
[0078] The hash value acquisition module 11 is used to store the code information under the code repository address of the current system to the corresponding code pull path through the task deployment configuration information of the current Jenkins build task during the continuous integration process, and obtain the target hash value of the latest submission record of the server locally;
[0079] The first judgment module 12 is used to judge whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and obtain a corresponding first judgment result;
[0080] The second judgment module 13 is used to judge whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table if the first judgment result indicates existence, so as to obtain a corresponding second judgment result;
[0081] The synchronous execution process completion module 14 is used to obtain the target difference information between the target hash value and the target submission record information if the second judgment result shows inconsistency, and use the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronous execution process.
[0082] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0083] It can be seen that in the embodiment of the present application, in the process of continuous integration, the code information under the code warehouse address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest submission record of the server is obtained; it is judged whether there is a record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and the corresponding first judgment result is obtained; if the first judgment result shows that it exists, it is judged whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table to obtain the corresponding second judgment result; if the second judgment result shows that it is inconsistent, the target difference information between the target hash value and the target submission record information is obtained, and the target difference information and the task deployment configuration information are used to complete the corresponding SQL script synchronization execution process. That is, in this application, by connecting the SQL script execution process to the continuous integration process, it is ensured that each task deployment pulls the latest submitted SQL script, and at the same time, synchronization is completed by comparing the target hash value of the latest submission record in the current code warehouse with the difference information between the target submission record information of the latest submission record saved in the preset SQL script submission record table. This not only improves the accuracy and reliability of data changes, but also improves the efficiency of task deployment and the traceability of operation execution results.
[0084] In some specific embodiments, the hash value acquisition module 11 can be specifically used to: pull the code information under the code repository address of the current system based on the system name and code branch in the task deployment configuration information; query the local code submission record of the server of the current test environment by storing the code information in the code pulling path corresponding to the current test environment; and obtain the target hash value of the latest local submission record of the server based on the code submission record.
[0085] In some specific embodiments, the device for synchronously executing the SQL script test environment can also be used to: when the first judgment result indicates that it does not exist, add a record information to the preset SQL script submission record table based on the target hash value; or, query the preset SQL script submission record table for the target submission record information with the latest creation time, and obtain the SQL script file submitted to the Gitlab code repository of the current system according to the target submission record information, so as to save the SQL script file to the script file storage path corresponding to the server of the current test environment; or, traverse and run the SQL script file at the database address corresponding to the current test environment, and traverse and execute the corresponding SQL fallback script when the operation fails.
[0086] In some specific embodiments, the device for synchronously executing the SQL script test environment can also be used to: if the second judgment result indicates that the target hash value is consistent with the target submission record information, terminate and complete the deployment operation of the current Jenkins build task based on the preset code package deployment method configuration information; when the task deployment fails, check the corresponding deployment log to find the cause.
[0087] In some specific embodiments, the synchronous execution process completion module 14 can be specifically used to: if the second judgment result shows inconsistency, then determine whether the SQL script information corresponding to the target hash value and the SQL script information corresponding to the target submission record information are the same by comparison, so as to obtain a corresponding third judgment result; when the third judgment result shows that the SQL script corresponding to the target hash value and the SQL script corresponding to the target submission record information are not the same, obtain the corresponding target difference information.
[0088] In some specific embodiments, the synchronous execution process completion module 14 can be specifically used to: obtain the corresponding target execution script file and target rollback script file by parsing the target difference information; when the current rollback mode is determined to be a full rollback based on the rollback parameters in the task deployment configuration information, traverse and run the SQL rollback script corresponding to the target submission record information saved in the script file storage path of the current test environment, and run the SQL execution script corresponding to the target hash value; when the current rollback mode is determined to be a difference rollback based on the rollback parameters in the task deployment configuration information, traverse and run the target execution script file in the current test environment, and traverse and run the target rollback script file when the operation fails.
[0089] In some specific embodiments, the device for synchronously executing the SQL script test environment can also be specifically used to: if the SQL execution script corresponding to the target hash value is successfully executed, or the target execution script file is successfully traversed and run in the current test environment, then a new record information is added to the preset SQL script submission record table based on the target hash value; if the SQL execution script corresponding to the target hash value fails to be executed, then after traversing and running the SQL fallback script corresponding to the target hash value, the SQL execution script corresponding to the target submission record information is run.
[0090] Furthermore, the present application also discloses an electronic device. Figure 7 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.
[0091] Figure 7A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the method for synchronously executing a SQL script test environment disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0092] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0093] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0094] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the method of synchronously executing a SQL script test environment executed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.
[0095] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the method for synchronously executing a SQL script test environment disclosed above is implemented. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the above embodiments, and no further description will be given here.
[0096] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0097] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0098] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0099] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0100] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for synchronously executing a SQL script in a test environment, characterized in that: include: In the process of continuous integration, the code information under the code repository address of the current system is stored in the corresponding code pull path through the task deployment configuration information of the current Jenkins build task, and the target hash value of the latest submission record of the server is obtained; Determine whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and obtain a corresponding first judgment result; wherein the preset SQL script submission record table includes a corresponding submission record ID field, a system name field, a code branch field, a test environment field, a creation time field, and a creator field; If the first judgment result indicates existence, determine whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table to obtain a corresponding second judgment result; If the second judgment result indicates inconsistency, obtaining target difference information between the target hash value and the target submission record information, and using the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronization execution process; The step of using the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronous execution process includes: By parsing the target difference information, a corresponding target execution script file and a target fallback script file are obtained; When the current rollback mode is determined to be a full rollback based on the rollback parameters in the task deployment configuration information, the SQL rollback script corresponding to the target submission record information saved in the script file storage path of the current test environment is traversed and run, and the SQL execution script corresponding to the target hash value is run; When it is determined that the current rollback mode is differential rollback based on the rollback parameters in the task deployment configuration information, the target execution script file is traversed and run in the current test environment, and the target rollback script file is traversed and run when the execution fails; Also includes: If the SQL execution script corresponding to the target hash value is successfully executed, or the target execution script file is successfully traversed and executed in the current test environment, a new record information is added to the preset SQL script submission record table based on the target hash value; If the SQL execution script corresponding to the target hash value fails to be executed, then after traversing and executing the SQL rollback script corresponding to the target hash value, the SQL execution script corresponding to the target submission record information is executed; The task deployment configuration information of the current Jenkins build task is used to store the code information under the code repository address of the current system to the corresponding code pull path, and the target hash value of the latest submission record of the server is obtained, including: Pull the code information under the code repository address of the current system based on the system name and code branch in the task deployment configuration information; By storing the code information in the code pull path corresponding to the current test environment, querying the local code submission record of the server of the current test environment; Based on the code submission record, a target hash value of the latest submission record locally on the server is obtained.
2. The method for synchronously executing a SQL script test environment according to claim 1, characterized in that: After obtaining the corresponding first judgment result, the method further includes: When the first judgment result indicates that it does not exist, a new record information is added to the preset SQL script submission record table based on the target hash value; Or, query the target submission record information with the latest creation time in the preset SQL script submission record table, and obtain the SQL script file submitted to the Gitlab code repository of the current system according to the target submission record information, so as to save the SQL script file to the script file storage path corresponding to the server of the current test environment; Or, the SQL script file is traversed and run at the database address corresponding to the current test environment, and when the operation fails, the corresponding SQL rollback script is traversed and executed.
3. The method for synchronously executing a SQL script test environment according to claim 1, characterized in that: After obtaining the corresponding second judgment result, the method further includes: If the second judgment result indicates that the target hash value is consistent with the target submission record information, the deployment operation of the current Jenkins build task is terminated and completed based on the preset code package deployment mode configuration information; When a task deployment fails, check the corresponding deployment log to find the cause.
4. The method for synchronously executing a SQL script test environment according to claim 1, characterized in that: If the second judgment result indicates inconsistency, obtaining target difference information between the target hash value and the target submission record information includes: If the second judgment result indicates inconsistency, determining whether the SQL script information corresponding to the target hash value and the SQL script information corresponding to the target submission record information are the same by comparison, so as to obtain a corresponding third judgment result; When the third judgment result indicates that the SQL script corresponding to the target hash value is different from the SQL script corresponding to the target submission record information, the corresponding target difference information is obtained.
5. A device for synchronously executing a SQL script test environment, characterized in that: include: The hash value acquisition module is used to store the code information under the code repository address of the current system to the corresponding code pull path through the task deployment configuration information of the current Jenkins build task during the continuous integration process, and obtain the target hash value of the latest submission record on the server; The first judgment module is used to judge whether there is record information corresponding to the current code branch of the current system in the current test environment in the preset SQL script submission record table, and obtain a corresponding first judgment result; wherein the preset SQL script submission record table includes a corresponding submission record ID field, a system name field, a code branch field, a test environment field, a creation time field, and a creator field; A second judgment module is used to judge whether the target hash value is consistent with the target submission record information with the latest creation time in the preset SQL script submission record table if the first judgment result indicates existence, so as to obtain a corresponding second judgment result; A synchronous execution process completion module, used for obtaining target difference information between the target hash value and the target submission record information if the second judgment result indicates inconsistency, and using the target difference information and the task deployment configuration information to complete the corresponding SQL script synchronous execution process; Among them, the synchronous execution process completion module is used to: obtain the corresponding target execution script file and target rollback script file by parsing the target difference information; when the current rollback mode is determined to be full rollback based on the rollback parameters in the task deployment configuration information, traverse and run the SQL rollback script corresponding to the target submission record information stored in the script file storage path of the current test environment, and run the SQL execution script corresponding to the target hash value; when the current rollback mode is determined to be differential rollback based on the rollback parameters in the task deployment configuration information, traverse and run the target execution script file in the current test environment, and traverse and run the target rollback script file when the operation fails; The device for synchronously executing the SQL script test environment is further used to: if the SQL execution script corresponding to the target hash value is successfully executed, or the target execution script file is successfully traversed and run in the current test environment, then add a record information in the preset SQL script submission record table based on the target hash value; if the SQL execution script corresponding to the target hash value fails to be executed, then after traversing and running the SQL fallback script corresponding to the target hash value, run the SQL execution script corresponding to the target submission record information; The hash value acquisition module is used to: pull the code information under the code repository address of the current system based on the system name and code branch in the task deployment configuration information; query the local code submission record of the server of the current test environment by storing the code information in the code pulling path corresponding to the current test environment; and obtain the target hash value of the latest local submission record of the server based on the code submission record.
6. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor is used to execute the computer program to implement the method for synchronously executing a SQL script test environment as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed by a processor, implements the method for synchronously executing a SQL script test environment as described in any one of claims 1 to 4.
