Database script upgrading method and device
By detecting and setting baseline version scripts, combined with script verification tools, the automatic upgrade of database scripts is realized, which solves the problems of cumbersome traditional manual operations and poor compatibility of existing tools, and improves the efficiency and stability of database management.
Patent Information
- Application Number
- CN202410650654.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-23
- Publication Date
- 2024-08-30
AI Technical Summary
Traditional manual execution of SQL scripts to change the database structure is cumbersome and error-prone. Existing automation tools are not compatible with different types of databases in multiple environments, causing database script upgrades to fail.
Provides a database script upgrade method that obtains the upgrade script of the target database, detects and sets the baseline version script, and performs a full or incremental upgrade of the target database according to the upgrade script. It supports MySQL and ClickHouse databases, is compatible with multiple environments, and uses script verification The tool corrects incorrect statements and implements automated upgrades.
It achieves automated and intelligent upgrades of database scripts, reduces operational complexity and error rates, ensures compatibility and stability in multiple environments, and improves database management efficiency.
Smart Images

Figure CN118567676A
Abstract
Description
Technical Field
[0001] The present application relates to the field of big data technology, and in particular to a database script upgrade method and device. Background Art
[0002] When managing and upgrading a database, the traditional solution is to manually execute SQL (Structured Query Language) scripts to change the database structure. This process is subject to much manual intervention, and is cumbersome and error-prone. As the scale of database deployment continues to expand, manually executing database scripts can no longer meet the current database upgrade management needs.
[0003] Currently, there are some automated script upgrade tools on the market, but the functions of these tools are relatively simple, and they are not compatible with different types of databases in multiple environments at the same time. They are also prone to database script upgrade failures due to SQL execution conflicts.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present application provide a database script upgrade method and device to at least solve the technical problem of complex database script upgrade operations in different environments in the related art.
[0006] According to one aspect of an embodiment of the present application, a database script upgrade method is provided, comprising: obtaining an upgrade script for a target database uploaded by a target object to a database script upgrade management platform, wherein the type of the target database includes at least one of the following: a MySQL database, a ClickHouse database; detecting whether a baseline version script has been set for the target database; if a baseline version script has not been set for the target database, setting the upgrade script as the baseline version script of the target database, and fully upgrading the current script of the target database according to the upgrade script; if a baseline version script has been set for the target database, incrementally upgrading the baseline version script of the target database according to the upgrade script.
[0007] Optionally, before obtaining the upgrade script for the target database uploaded by the target object to the database script upgrade management platform, obtain the installation file of the database script upgrade management platform; based on the installation file, deploy the database script upgrade management platform to the target terminal through a target deployment method, wherein the target deployment method includes one of the following: a stand-alone deployment method, a Docker container deployment method, and a Kubernetes cluster deployment method.
[0008] Optionally, obtaining an upgrade script for a target database uploaded by the target object to the database script upgrade management platform includes: in response to the upgrade script uploaded by the target object to the database script upgrade management platform, detecting whether the target object has script upgrade authority for the target database; if the target object does not have script upgrade authority, refusing to receive the upgrade script, and sending an alarm prompt message to a system administrator, wherein the alarm prompt message is used to prompt the existence of an illegal operation to upgrade the script of the target database; if the target object has script upgrade authority, storing the upgrade script in a script database, wherein the script database is used to store historical upgrade scripts.
[0009] Optionally, after obtaining the upgrade script for the target database uploaded by the target object to the database script upgrade management platform, the upgrade script is verified using a script verification tool, and erroneous statements in the upgrade script are corrected, wherein the script verification tool stores a variety of erroneous statements determined based on historical experience and a correction method for each erroneous statement.
[0010] Optionally, the current script of the target database is fully upgraded according to the upgrade script, including: obtaining data source information of the target database, and establishing a connection with the target database based on the data source information, wherein the data source information includes configuration information for accessing and operating the target database; executing the upgrade script to complete the full upgrade of the current script of the target database.
[0011] Optionally, the baseline version script of the target database is incrementally upgraded according to the upgrade script, including: obtaining data source information of the target database, and establishing a connection with the target database according to the data source information, wherein the data source information includes configuration information for accessing and operating the target database; splitting the upgrade script, and marking the upgrade statements in the multiple upgrade statements obtained by the splitting that are repeated with the statements in the baseline version script; executing the multiple upgrade statements corresponding to the upgrade script in sequence, and automatically skipping the marked upgrade statements, to complete the incremental upgrade of the baseline version script of the target database.
[0012] Optionally, in response to a query instruction of the target object, a query result corresponding to the query instruction is queried and fed back, wherein the query instruction is used to query at least one of the following information: script upload records, script upgrade history, script upgrade log, script upgrade results, historical upgrade scripts, baseline version script setting information, and data source information.
[0013] According to another aspect of an embodiment of the present application, a database script upgrade device is also provided, including: an acquisition module, used to acquire an upgrade script for a target database uploaded by a target object to a database script upgrade management platform, wherein the type of the target database includes at least one of the following: a MySQL database, a ClickHouse database; a detection module, used to detect whether a baseline version script has been set for the target database; a first upgrade module, used to set the upgrade script to the baseline version script of the target database when the baseline version script has not been set for the target database, and to fully upgrade the current script of the target database according to the upgrade script; a second upgrade module, used to incrementally upgrade the baseline version script of the target database according to the upgrade script when the baseline version script has been set for the target database.
[0014] According to another aspect of an embodiment of the present application, a computer program product is further provided, the computer program product comprising: a computer program, wherein when the computer program is executed by a processor, the above-mentioned database script upgrade method is implemented.
[0015] According to another aspect of an embodiment of the present application, an electronic device is further provided, comprising: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned database script upgrade method through the computer program.
[0016] In an embodiment of the present application, firstly, the upgrade script for the target database uploaded by the target object to the database script upgrade management platform is obtained, and then it is detected whether the target database has been set with a baseline version script; if the target database has not been set with a baseline version script, the upgrade script is set as the baseline version script of the target database, and the current script of the target database is fully upgraded according to the upgrade script; if the target database has been set with a baseline version script, the baseline version script of the target database is incrementally upgraded according to the upgrade script. Among them, the user only needs to upload the upgrade script, and the database script upgrade management platform can automatically and intelligently perform incremental or full upgrades on the target database script. The upgrade solution is compatible with application environments such as MySQL database and ClickHouse database, and effectively solves the technical problem of complex database script upgrade operations in different environments in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0018] Figure 1is a schematic diagram of an optional database script upgrade management platform according to an embodiment of the present application;
[0019] Figure 2 is a schematic diagram of the structure of an optional computer terminal according to an embodiment of the present application;
[0020] Figure 3 It is a flowchart of an optional database script upgrade method according to an embodiment of the present application;
[0021] Figure 4 It is a structural diagram of an optional database script upgrading device according to an embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0023] It should be noted that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0024] In order to better understand the embodiments of the present application, some nouns or terms that appear in the description of the embodiments of the present application are first translated and explained as follows:
[0025] Database script upgrade: refers to updating and improving existing database scripts to improve database performance, security and functionality. Script upgrades usually include operations such as modifying the database table structure, adding or deleting indexes, optimizing stored procedures and triggers, and migrating data.
[0026] MySQL database: an open source relational database that uses SQL for database operations. MySQL database can be used to store and manage large amounts of data, supports multi-user access, and can run on multiple operating systems. It is a lightweight and efficient database system that is widely used in Web applications and large enterprise systems.
[0027] ClickHouse database: an open source distributed columnar database that supports high-performance data compression and parallel query processing, suitable for large-scale data analysis and data warehouse applications. ClickHouse is highly scalable and fault-tolerant, capable of handling PB-level data scales, and has fast query response times. It is written in C++ and uses Yandex's own columnar storage engine, supporting SQL query language and import and export of multiple data formats. ClickHouse is widely used in big data analysis and real-time report query scenarios in the Internet, e-commerce, advertising technology, finance and other industries.
[0028] Example 1
[0029] In order to solve the technical problem of complex database script upgrade operations in different environments in the related art, an embodiment of the present application provides an automated database script upgrade management platform.
[0030] Figure 1 is a schematic diagram of a functional interaction module of an optional database script upgrade management platform according to an embodiment of the present application, such as Figure 1 As shown, the database script upgrade management platform mainly includes: a system management module and a script management module.
[0031] Optionally, the system management module mainly includes: a user management module and a project management module. The system administrator can create a project for upgrading multiple database scripts in the project management module and specify project-related members in the user management module, such as script administrators and other project members.
[0032] Optionally, the script management module mainly includes: a script upload module, a script upgrade module, a script setting module, a file management module and a permission management module. Among them, the permission management module includes a user permission setting module and a basic parameter setting module. The script administrator can set the operation permissions of different project members in the user permission setting module and configure the script-related parameter information in the basic parameter setting module; the script setting module includes a baseline version setting module and a data source setting module. The script administrator can specify the baseline version script in the baseline version setting module and configure the data source information corresponding to each database in the data source setting module. The data source information is the connection configuration information for accessing and operating the database; the script administrator can upload the upgrade script in the script upload module; the script upgrade module includes: a script full upgrade module, a script incremental upgrade module, an upgrade database selection module, an upgrade history viewing module, an upgrade log viewing module and an upgrade script information viewing module. Usually, the database script upgrade management platform can determine the type of database to be upgraded based on the uploaded upgrade script, and determine the corresponding upgrade method based on the version information of the upgrade script and the baseline version information. Of course, the script administrator can also select the upgrade database by upgrading the database. The module specifies upgrading the MySQL database or ClickHouse database, and specifies the database script upgrade method through the script full upgrade module and the script incremental upgrade module. The script administrator can also view the specific upgrade script content through the upgrade script information viewing module, or monitor the log information of the execution of the upgrade script in real time through the upgrade log viewing module, or view all historical upgrade records of the database script through the upgrade history viewing module; the file management module includes: a script file online browsing module, an upload record viewing module and a mark skip SQL code snippet module. The script administrator can view and modify the current upgrade script file in real time through the script file online browsing module, or view all historical upgrade scripts uploaded to the database script upgrade management platform through the upload record viewing module. Usually, the database script upgrade management platform can automatically mark duplicate SQL statements by splitting the SQL statements in the upgrade script and comparing them with the baseline version script. The script administrator can also manually mark duplicate SQL statements that need to be skipped through the mark skip SQL code snippet module.
[0033] It should be noted that the database script upgrade management platform of the embodiment of the present application needs to be deployed to a target terminal for use, and the target terminal may be a mobile terminal, a computer terminal or a similar computing device.
[0034] Figure 2 The hardware structure block diagram of a computer terminal for deploying a database script upgrade management platform is shown. Figure 2As shown, the computer terminal 20 may include one or more (202a, 202b, ..., 202n are used to illustrate) processors 202 (the processor 202 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 204 for storing data, and a transmission device 206 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 2 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 2 More or fewer components as shown, or with Figure 2 Different configurations shown.
[0035] It should be noted that the one or more processors 202 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 20 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0036] The memory 204 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the database script upgrade method in the embodiment of the present application. The processor 202 executes various functional applications and data processing by running the software programs and modules stored in the memory 204, that is, to implement the vulnerability detection method of the above-mentioned application. The memory 204 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 204 may further include a memory remotely arranged relative to the processor 202, and these remote memories may be connected to the computer terminal 20 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0037] The transmission device 206 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 20. In one example, the transmission device 206 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 206 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0038] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 20 (or mobile device).
[0039] As an optional implementation, the database script upgrade management platform can be deployed to the target terminal in the following manner: obtain the installation file of the database script upgrade management platform; based on the installation file, deploy the database script upgrade management platform to the target terminal through a target deployment method, wherein the target deployment method includes one of the following: a stand-alone deployment method, a Docker container deployment method, and a Kubernetes cluster deployment method.
[0040] Specifically, in the stand-alone deployment mode, you can use a shell script to start the jar format installation file with one click through the command, and deploy the database script upgrade management platform to the target terminal; in the Docker container deployment mode, you can package the installation file and related environment configuration information into a Docker image, use the docker load method to load the Docker image to the local image repository of the target terminal, and then start the installation file through the image to deploy the database script upgrade management platform to the target terminal; in the Kubernetes cluster deployment mode, you can package the installation file and related environment configuration information into a Docker image and helm resource file, upload it to the local image repository of the target terminal, and then start the installation file with one click through helminstall to deploy the database script upgrade management platform to the target terminal.
[0041] In an embodiment of the present application, the user only needs to upload the upgrade script, and the database script upgrade management platform can automatically and intelligently perform incremental or full upgrades on the target database script. The upgrade solution is also compatible with application environments such as MySQL database and ClickHouse database, effectively solving the technical problems of complex database script upgrade operations in different environments in related technologies.
[0042] Example 2
[0043] Based on the database script upgrade management platform provided in Example 1, the embodiment of the present application provides a database script upgrade method. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0044] Specifically, the database script upgrade method provided in the embodiment of the present application is as follows: Figure 3 As shown, the method comprises the following steps:
[0045] Step S302, obtaining an upgrade script for a target database uploaded by the target object to the database script upgrade management platform, wherein the type of the target database includes at least one of the following: MySQL database, ClickHouse database;
[0046] Step S304, detecting whether the target database has been set with a baseline version script;
[0047] Step S306, if the target database has not been set with a baseline version script, the upgrade script is set as the baseline version script of the target database, and the current script of the target database is fully upgraded according to the upgrade script;
[0048] Step S308: In the case where the target database has been set with a baseline version script, the baseline version script of the target database is incrementally upgraded according to the upgrade script.
[0049] The following describes the various steps of the database script upgrade method in conjunction with the specific implementation process.
[0050] It can be understood that the above database script upgrade method is mainly implemented by the database script upgrade management platform. Therefore, before the steps of the method are executed, the database script upgrade management platform needs to be deployed first. Optionally, the installation file of the database script upgrade management platform can be obtained first; then, based on the installation file, the database script upgrade management platform is deployed to the target terminal through the target deployment method, wherein the target deployment method includes one of the following: stand-alone deployment method, Docker container deployment method, and Kubernetes cluster deployment method.
[0051] Specifically, in the stand-alone deployment mode, you can use a shell script to start the jar format installation file with one click through the command, and deploy the database script upgrade management platform to the target terminal; in the Docker container deployment mode, you can package the installation file and related environment configuration information into a Docker image, use the docker load method to load the Docker image to the local image repository of the target terminal, and then start the installation file through the image to deploy the database script upgrade management platform to the target terminal; in the Kubernetes cluster deployment mode, you can package the installation file and related environment configuration information into a Docker image and helm resource file, upload it to the local image repository of the target terminal, and then start the installation file with one click through helminstall to deploy the database script upgrade management platform to the target terminal.
[0052] Considering the security of the database script upgrade process, the embodiment of the present application proposes that the user identity needs to be verified when receiving the upgrade script uploaded by the user. Optionally, in response to the upgrade script uploaded by the target object to the database script upgrade management platform, it is detected whether the target object has the script upgrade permission for the target database, such as detecting whether the target object is the script administrator designated by the system administrator, and only the script administrator has the permission to upgrade the database script; if the target object does not have the script upgrade permission, it can refuse to receive the upgrade script and send an alarm prompt information to the system administrator, which is used to prompt that there is an illegal operation to upgrade the script of the target database; if the target object has the script upgrade permission, the upgrade script is stored in the script database, which is used to store all historical upgrade scripts.
[0053] Optionally, in order to ensure the reliability of the database script upgrade process, after obtaining the upgrade script uploaded by the target object, the upgrade script can be verified using a script verification tool, and the erroneous SQL statements in the upgrade script can be corrected. The script verification tool stores a variety of erroneous SQL statements determined based on historical experience and the correction method for each erroneous SQL statement.
[0054] As an optional implementation, when upgrading the target database script according to the upgrade script, you can first detect whether the target database has been set up with a baseline version script. Usually, after the database is deployed or the script is upgraded, the latest or most stable version of the script will be set as the baseline version script; when it is detected that the target database has not been set up with a baseline version script, it means that the database is a newly deployed database, and the upgrade script can be set as the baseline version script of the target database, and the current script of the target database can be fully upgraded according to the upgrade script; when it is detected that the target database has been set up with a baseline version script, the baseline version script of the target database can be incrementally upgraded according to the upgrade script. It should be noted that in some scenarios, the script administrator can directly specify whether to use a full upgrade method or an incremental upgrade method according to needs.
[0055] Optionally, in the full upgrade mode, the data source information of the target database can be obtained, and a connection with the target database can be established based on the data source information, wherein the data source information includes configuration information for accessing and operating the target database; then the upgrade script is directly executed to complete the full upgrade of the current script of the target database.
[0056] Optionally, in the incremental upgrade method, the data source information of the target database is also first obtained, and a connection is established with the target database based on the data source information; to avoid conflicts between the SQL statements in the current upgrade script and the SQL statements in the baseline version script during execution, the current upgrade script can be split, and the SQL upgrade statements in the multiple segments of SQL upgrade statements obtained by splitting that are repeated with the SQL statements in the baseline version script are marked, and then the multiple segments of SQL upgrade statements corresponding to the upgrade script are executed in sequence, and the marked SQL upgrade statements are automatically skipped to complete the incremental upgrade of the baseline version script of the target database.
[0057] In actual application scenarios, users only need to upload the upgrade script to the database script upgrade management platform, and then they can use the platform to implement one-click script upgrades for MySQL databases and ClickHouse databases in various environments.
[0058] In order to improve the visualization of the database script upgrade process, the embodiment of the present application also provides a related information query function, which can respond to the query instruction of the target object, query and feedback the query result corresponding to the query instruction, wherein the query instruction can query the following related information: script upload record, script upgrade history, script upgrade log, script upgrade result, historical upgrade script, baseline version script setting information, data source information. Through this information query function, users can easily understand the database script upgrade process and database specimen upgrade history related information.
[0059] In an embodiment of the present application, firstly, the upgrade script for the target database uploaded by the target object to the database script upgrade management platform is obtained, and then it is detected whether the target database has been set with a baseline version script; if the target database has not been set with a baseline version script, the upgrade script is set as the baseline version script of the target database, and the current script of the target database is fully upgraded according to the upgrade script; if the target database has been set with a baseline version script, the baseline version script of the target database is incrementally upgraded according to the upgrade script. Among them, the user only needs to upload the upgrade script, and the database script upgrade management platform can automatically and intelligently perform incremental or full upgrades on the target database script. The upgrade solution is compatible with application environments such as MySQL database and ClickHouse database, and effectively solves the technical problem of complex database script upgrade operations in different environments in the related technology.
[0060] Example 3
[0061] According to an embodiment of the present application, a database script upgrade device for implementing the database script upgrade method in embodiment 2 is also provided. Figure 4 As shown, the database script upgrade device at least includes: an acquisition module 41, a detection module 42, a first upgrade module 43 and a second upgrade module 44, wherein:
[0062] An acquisition module 41 is used to acquire an upgrade script for a target database uploaded by a target object to a database script upgrade management platform, wherein the type of the target database includes at least one of the following: a MySQL database and a ClickHouse database;
[0063] A detection module 42, used to detect whether a baseline version script has been set for the target database;
[0064] A first upgrade module 43 is used to set the upgrade script as the baseline version script of the target database when the target database has not been set with a baseline version script, and to fully upgrade the current script of the target database according to the upgrade script;
[0065] The second upgrade module 44 is used to perform incremental upgrade on the baseline version script of the target database according to the upgrade script when the baseline version script has been set for the target database.
[0066] The functions of each module of the database script upgrade device are described below in conjunction with a specific implementation process.
[0067] As an optional implementation, the database script upgrade device of the embodiment of the present application also includes a deployment module, which is used to obtain the installation file of the database script upgrade management platform; based on the installation file, the database script upgrade management platform is deployed to the database script upgrade device through a target deployment method, wherein the target deployment method includes one of the following: a stand-alone deployment method, a Docker container deployment method, and a Kubernetes cluster deployment method.
[0068] Considering the security of the database script upgrade process, the embodiment of the present application proposes that when receiving the upgrade script uploaded by the user, the user identity needs to be verified. Optionally, the database script upgrade device of the embodiment of the present application also includes a permission detection module, which is used to respond to the upgrade script uploaded by the target object to the database script upgrade management platform, and detect whether the target object has the script upgrade permission for the target database, such as detecting whether the target object is the script administrator designated by the system administrator, and only the script administrator has the permission to upgrade the database script; if the target object does not have the script upgrade permission, it can refuse to receive the upgrade script and send an alarm prompt information to the system administrator, which is used to prompt that there is an illegal operation to upgrade the script of the target database; if the target object has the script upgrade permission, the upgrade script is stored in the script database, and the script database is used to store all historical upgrade scripts.
[0069] Optionally, in order to ensure the reliability of the database script upgrade process, the database script upgrade device of the embodiment of the present application also includes a verification module, which is used to use a script verification tool to verify the upgrade script after obtaining the upgrade script uploaded by the target object, and correct the erroneous SQL statements in the upgrade script, wherein the script verification tool stores a variety of erroneous SQL statements determined based on historical experience and a correction method for each erroneous SQL statement.
[0070] As an optional implementation, when upgrading the target database script according to the upgrade script, the detection module can be used to first detect whether the target database has been set with a baseline version script. Usually, after the database is deployed or the script is upgraded, the latest or most stable version of the script will be set as the baseline version script; when it is detected that the target database has not been set with a baseline version script, it means that the database is a newly deployed database, and the first upgrade module can set the upgrade script as the baseline version script of the target database, and perform a full upgrade of the current script of the target database according to the upgrade script; when it is detected that the target database has been set with a baseline version script, the second upgrade module can perform an incremental upgrade of the baseline version script of the target database according to the upgrade script. It should be noted that in some scenarios, the script administrator can also directly specify whether to use a full upgrade method or an incremental upgrade method according to demand.
[0071] Optionally, in a full upgrade mode, the first upgrade module can obtain the data source information of the target database and establish a connection with the target database based on the data source information, wherein the data source information includes configuration information for accessing and operating the target database; and then directly execute the upgrade script to complete the full upgrade of the current script of the target database.
[0072] Optionally, in the incremental upgrade method, the second upgrade module also first obtains the data source information of the target database, and establishes a connection with the target database based on the data source information; to avoid conflicts between the SQL statements in the current upgrade script and the SQL statements in the baseline version script during execution, the current upgrade script can be split, and the SQL upgrade statements in the multiple segments of SQL upgrade statements obtained by the split that are repeated with the SQL statements in the baseline version script are marked, and then the multiple segments of SQL upgrade statements corresponding to the upgrade script are executed in sequence, and the marked SQL upgrade statements are automatically skipped to complete the incremental upgrade of the baseline version script of the target database.
[0073] In order to improve the visualization of the database script upgrade process, the database script upgrade device of the embodiment of the present application also includes an information query module, which is used to respond to the query instruction of the target object, query and feedback the query result corresponding to the query instruction, wherein the query instruction can query the following related information: script upload record, script upgrade history, script upgrade log, script upgrade result, historical upgrade script, baseline version script setting information, data source information. Through this information query module, users can easily understand the database script upgrade process and database specimen upgrade history related information.
[0074] It should be noted that each module in the database script upgrade device in the embodiment of the present application corresponds one-to-one to each implementation step of the database script upgrade method in Example 2. Since a detailed description has been given in Example 2, some details not reflected in this embodiment can be referred to Example 2, and will not be repeated here.
[0075] Example 4
[0076] According to an embodiment of the present application, a computer program product is also provided, which includes a computer program, wherein when the computer program is executed by a processor, the database script upgrade method in Example 2 is implemented.
[0077] According to an embodiment of the present application, a non-volatile storage medium is also provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the database script upgrade method in Example 2 by running the computer program.
[0078] According to an embodiment of the present application, a processor is also provided, which is used to run a computer program, wherein the database script upgrade method in Example 2 is executed when the computer program is running.
[0079] According to an embodiment of the present application, an electronic device is also provided, which includes: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the database script upgrade method in Example 2 through the computer program.
[0080] Specifically, the following steps are executed when the computer program is running: obtaining an upgrade script for a target database uploaded by the target object to a database script upgrade management platform, wherein the type of the target database includes at least one of the following: MySQL database, ClickHouse database; detecting whether a baseline version script has been set for the target database; if a baseline version script has not been set for the target database, setting the upgrade script as the baseline version script of the target database, and performing a full upgrade of the current script of the target database according to the upgrade script; if a baseline version script has been set for the target database, performing an incremental upgrade of the baseline version script of the target database according to the upgrade script.
[0081] The serial numbers of the above embodiments are only for description and do not represent the advantages or disadvantages of the embodiments.
[0082] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0083] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0084] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed over multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0085] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0086] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk, etc. Various media that can store program codes.
[0087] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A database script upgrade method, characterized in that: include: Obtain an upgrade script for a target database uploaded by the target object to a database script upgrade management platform, wherein the type of the target database includes at least one of the following: a MySQL database and a ClickHouse database; Detecting whether the target database has been set with a baseline version script; If the target database is not set with a baseline version script, the upgrade script is set as the baseline version script of the target database, and the current script of the target database is fully upgraded according to the upgrade script; In the case that the target database has been set with a baseline version script, the baseline version script of the target database is incrementally upgraded according to the upgrade script.
2. The method according to claim 1, characterized in that Before obtaining the upgrade script for the target database uploaded by the target object to the database script upgrade management platform, the method further includes: Obtaining the installation file of the database script upgrade management platform; Based on the installation file, the database script upgrade management platform is deployed to the target terminal through a target deployment method, wherein the target deployment method includes one of the following: a stand-alone deployment method, a Docker container deployment method, and a Kubernetes cluster deployment method.
3. The method according to claim 1, characterized in that Obtain the upgrade script for the target database uploaded by the target object to the database script upgrade management platform, including: In response to the upgrade script uploaded by the target object to the database script upgrade management platform, detecting whether the target object has script upgrade authority for the target database; If the target object does not have the script upgrade permission, the upgrade script is refused to be received, and an alarm prompt message is sent to the administrator, wherein the alarm prompt message is used to prompt that there is an illegal operation to upgrade the script of the target database; If the target object has the script upgrade permission, the upgrade script is stored in a script database, wherein the script database is used to store historical upgrade scripts.
4. The method according to claim 1, characterized in that: After obtaining the upgrade script for the target database uploaded by the target object to the database script upgrade management platform, the method further includes: The upgrade script is verified by using a script verification tool, and the erroneous statements in the upgrade script are corrected, wherein the script verification tool stores a plurality of erroneous statements determined based on historical experience and a correction method for each erroneous statement.
5. The method according to claim 1, characterized in that The current script of the target database is fully upgraded according to the upgrade script, including: Acquire data source information of the target database, and establish a connection with the target database according to the data source information, wherein the data source information includes configuration information for accessing and operating the target database; Execute the upgrade script to complete the full upgrade of the current script of the target database.
6. The method according to claim 1, characterized in that Incrementally upgrading the baseline version script of the target database according to the upgrade script includes: Acquire data source information of the target database, and establish a connection with the target database according to the data source information, wherein the data source information includes configuration information for accessing and operating the target database; Splitting the upgrade script into statements, and marking upgrade statements in the multiple upgrade statements obtained by splitting that are repeated with statements in the baseline version script; The multiple upgrade statements corresponding to the upgrade script are executed in sequence, and the marked upgrade statements are automatically skipped to complete the incremental upgrade of the baseline version script of the target database.
7. The method according to claim 3, characterized in that The method further comprises: In response to a query instruction of the target object, query and feed back a query result corresponding to the query instruction, wherein the query instruction is used to query at least one of the following information: script upload records, script upgrade history, script upgrade log, script upgrade results, historical upgrade scripts, baseline version script setting information, data source information.
8. A database script upgrade device, characterized in that: include: An acquisition module is used to acquire an upgrade script for a target database uploaded by a target object to a database script upgrade management platform, wherein the type of the target database includes at least one of the following: a MySQL database and a ClickHouse database; A detection module, used to detect whether the target database has been set with a baseline version script; A first upgrade module is used to set the upgrade script as the baseline version script of the target database when the target database has not been set with a baseline version script, and to fully upgrade the current script of the target database according to the upgrade script; The second upgrade module is used to perform incremental upgrade on the baseline version script of the target database according to the upgrade script when the baseline version script has been set for the target database.
9. A computer program product, characterized in that include: A computer program, wherein when the computer program is executed by a processor, the database script upgrading method according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the database script upgrading method according to any one of claims 1 to 7 through the computer program.
Citation Information
Cited By
Database upgrading method and device, equipment, storage medium and program product
CN119440590A
Method for realizing Clickhome data migration process automation
CN119759868A
A method for automating the Clickhouse data migration process
CN119759868B
