Universal database version management method, system and equipment and storage medium
By providing a universal database version management method, including database connection, initialization, change and control script modules, it solves the problems of incomplete database change management process and low readability of change record documents in the existing technology, and realizes database change and Synchronous recording of code changes and efficient database management.
Patent Information
- Application Number
- CN202411833050.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-12-13
AI Technical Summary
The prior art is difficult to fully cover the database change management process, and the change record documents are low in readability and ease of understanding.
Provides a general database version management method, including database connection module, initialization script execution module, database change script execution module and database control script execution module. Through these modules, database initialization, changes and version updates are realized, and the change process is recorded.
It realizes the synchronous recording of database changes and code changes, reduces the cost of upgrades and document maintenance, provides a comprehensive and flexible database management solution, supports multiple database types and enhances the compatibility and scalability of the system.
Smart Images

Figure CN119336735A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the technical field of database management, and in particular to a universal database version management method, system, device and storage medium. Background Art
[0002] In the continuous iteration process of software development, due to the continuous evolution of business needs, DDL (data definition language) and DML (data manipulation language) operations need to be frequently performed on the database. In a team-based development environment, multiple developers may need to modify the database structure at the same time. With the popularity of agile development, ensuring the consistency of database structure in different environments (such as development, testing, and production) has become more challenging, and it has also increased the complexity of the software upgrade process. Although traditional centralized document management methods help record change history, they may increase collaboration and management overhead, require additional training for team members, and make it difficult to ensure the readability and understandability of documents.
[0003] Generally, the GORP framework is used to handle database changes. It supports a variety of popular database systems, such as MySQL, PostgreSQL, and Oracle. However, some domestic databases, such as DAMO and GOSS, are not yet supported. In addition, the working principle of the GORP framework is to execute predefined DDL (data definition language) and DML (data manipulation language) statements. It is incapable of handling scenarios such as data initialization and field value calculation of complex business logic, and has a small coverage, failing to fully cover the entire database change management process. Summary of the invention
[0004] To this end, the embodiments of the present invention provide a universal database version management method, system, device and storage medium to solve the technical problems that the prior art is difficult to fully cover the database change management process and the readability and comprehensibility of change record documents are low.
[0005] In order to achieve the above objectives, the embodiments of the present invention provide the following technical solutions:
[0006] According to a first aspect of an embodiment of the present invention, a general database version management method is provided, the method being applied to a database type and comprising:
[0007] Get the configuration information and extract the database configuration from it, and create the corresponding database connection according to the specified database type;
[0008] Use the database type and detect whether initialization is required. If necessary, introduce the corresponding initialization script and add the structure containing ID information to the global slice. After the initialization script is executed, insert a record and generate the database, data table and data required for operation.
[0009] After initialization, check whether database changes are required. If changes are required, introduce the corresponding database change script according to the database type and change the corresponding data tables, data fields and indexes;
[0010] If no database change is required or after the database change is completed, the database control script is executed according to the database type to complete the database version update and record it.
[0011] Furthermore, the corresponding initialization script is introduced and the structure containing the ID information is added to the global slice. After the initialization script is executed, a record is inserted and the database, data table and data required for operation are generated, including:
[0012] Get the database type and initialize it, and add the structure containing ID information to the global slice;
[0013] Sort the global slices according to the ID information and traverse the global slices in order;
[0014] Check whether the current global slice has been initialized;
[0015] If yes, continue traversing;
[0016] If not, initialize the current global slice, insert a record and generate the database, data table and data required for operation.
[0017] Furthermore, according to the database type, the corresponding database change script is introduced and the corresponding data tables, data fields and indexes are changed, including:
[0018] Get the database type and initialize it, and add the structure containing ID information to the global slice;
[0019] Sort the global slices according to the ID information and traverse the global slices in order;
[0020] Check whether the current global slice has been changed;
[0021] If yes, continue traversing;
[0022] Otherwise, make database changes to the current global slice, change the corresponding data table, data field and index, and insert a change record.
[0023] Further, executing a database control script according to the database type includes:
[0024] Get the database type and initialize it, and add the structure containing ID information to the global slice;
[0025] Sort by a specific property and iterate over all global observer slices in order;
[0026] Determine whether there is a preset dependency script identifier;
[0027] If a dependency script identifier exists, the index of the dependency script identifier item is compared with the index position of the current item;
[0028] If the index of the dependency script identifier item is greater than the index position of the current item, swap the positions of the two and continue traversal.
[0029] Further, executing the database control script according to the database type also includes:
[0030] Check whether the current item has executed the database script task;
[0031] If it has been executed, continue traversing;
[0032] If it has not been executed, get the IsBlock property of the current item.
[0033] Furthermore, the IsBlock property of the current item is obtained, including:
[0034] Determine whether the IsBlock property of the current item is true;
[0035] If the IsBlock property of the current item is true, there is a strong dependency between the scripts, and the next script task can be executed only after the current script task is completed;
[0036] After the current script task is executed, a change record is inserted and the traversal continues until all script tasks are executed, completing the database version update and recording.
[0037] Furthermore, obtaining the IsBlock property of the current item also includes:
[0038] If the IsBlock property of the current item is false, there is no strong dependency between the scripts, and multiple script tasks can be executed at the same time;
[0039] Create a new coroutine and execute the next script task, insert a change record and continue to traverse until all script tasks are executed, completing the database version update and recording.
[0040] According to a second aspect of an embodiment of the present invention, a general database version management system is provided, the system comprising:
[0041] Database connection module, used to obtain configuration information and extract database configuration from it, and create corresponding database connection according to the specified database type;
[0042] The initialization script execution module is used to use the database type and detect whether initialization is required. If necessary, the corresponding initialization script is introduced and the structure containing the ID information is added to the global slice. After the initialization script is executed, a record is inserted and the database, data table and data required for operation are generated;
[0043] The database change script execution module is used to detect whether a database change is required if no initialization is required or after initialization is completed. If a change is required, the corresponding database change script is introduced according to the database type and the corresponding data table, data field and index are changed;
[0044] The database control script execution module is used to execute the database control script according to the database type if no database change is required or after the database change is completed, so as to complete the version update and recording of the database.
[0045] According to a third aspect of an embodiment of the present invention, a general database version management device is provided, the device comprising: a processor and a memory;
[0046] The memory is used to store one or more program instructions;
[0047] The processor is used to run one or more program instructions to execute the steps of a universal database version management method as described in any one of the above items.
[0048] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of a general database version management method as described in any one of the above items are implemented.
[0049] The embodiments of the present invention have the following advantages:
[0050] The present invention defines database operations as key steps during operation to ensure successful forced execution when the service is started. In this way, each database change can be recorded synchronously with the code change, making the change process clearer and easier to track, effectively reducing the cost of upgrades and document maintenance. The present invention subdivides database change support into three categories: initialization requirements, iterative changes, and complex business scripts. This subdivision comprehensively covers all operational requirements for the database during the software development process, thereby providing developers with a comprehensive and flexible database management solution. At the same time, a general execution solution is also defined, allowing users to provide specific scripts based on the type of database used. This modular design feature enables the system to easily adapt to new databases, avoids the problem of not supporting specific databases, and enhances the compatibility and scalability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the implementation methods of the present invention and the technical solutions in the prior art, the drawings required for the implementation methods and the prior art description are briefly introduced below. Obviously, the drawings in the following description are only exemplary, and for ordinary technicians in this field, other implementation drawings can be derived from the provided drawings without creative work.
[0052] The structures, proportions, sizes, etc. illustrated in this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with the technology. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no substantive technical significance. Any structural modification, change in proportion or adjustment of size shall fall within the scope of the technical contents disclosed in the present invention without affecting the effects and purposes that can be achieved by the present invention.
[0053] Figure 1 A schematic diagram of the logical structure of a universal database version management system provided by an embodiment of the present invention;
[0054] Figure 2 A schematic diagram of a flow chart of a general database version management method provided in an embodiment of the present invention;
[0055] Figure 3 A schematic diagram of a program startup flow in a general database version management method provided by an embodiment of the present invention;
[0056] Figure 4 A schematic diagram of a process of executing database migration in a general database version management method provided by an embodiment of the present invention;
[0057] Figure 5A schematic diagram of a database script execution flow in a general database version management method provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0058] The following is a description of the implementation of the present invention by specific embodiments. People familiar with the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification; obviously, the described embodiments are part of the embodiments of the present invention, but not all of them. 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.
[0059] Generally, the GORP framework is used to handle database changes. It supports a variety of popular database systems, such as MySQL, PostgreSQL, and Oracle. However, some domestic databases, such as DAMO and GOSS, are not yet supported. In addition, the working principle of the GORP framework is to execute predefined DDL (data definition language) and DML (data manipulation language) statements. It is incapable of handling scenarios such as data initialization and field value calculation of complex business logic, and has a small coverage, failing to fully cover the entire database change management process.
[0060] Therefore, there is an urgent need to propose a database script management solution that is universal to various database systems and can support complex business logic. Such a solution should be able to make database change records traceable together with code changes, thereby simplifying the upgrade process and improving the efficiency and security of database management.
[0061] In order to solve the above-mentioned technical problems that it is difficult to fully cover the database change management process and the readability and comprehensibility of change record documents are low.
[0062] refer to Figure 1 The embodiment of the present invention discloses a universal database version management system, which includes: a database connection module 1; an initialization script execution module 2; a database change script execution module 3; and a database control script execution module 4.
[0063] Corresponding to the above-disclosed universal database version management system, the embodiment of the present invention further discloses a universal database version management method. The following describes in detail a universal database version management method disclosed in the embodiment of the present invention in combination with the above-described universal database version management system.
[0064] refer to Figure 2 and Figure 3The present invention discloses a general database version management method, which is applied to database types and includes: obtaining configuration information and extracting database configuration therefrom, creating a corresponding database connection according to a specified database type; using the database type and detecting whether initialization is required, if necessary, introducing a corresponding initialization script, and adding a structure containing ID information to a global slice; inserting a record after the initialization script is executed and generating a database, data table, and data required for operation; if initialization is not required or after initialization is completed, detecting whether a database change is required, if a change is required, introducing a corresponding database change script according to the database type and changing the corresponding data table, data field, and index; if a database change is not required or after the database change is completed, executing a database control script according to the database type to complete the version update and recording of the database.
[0065] Its execution process is embedded in the program startup time, and is forced to execute successfully when the service starts.
[0066] Database connection initialization: First, the database configuration is extracted from the configuration information, and the corresponding database connection is created according to the specified database type.
[0067] Further, refer to Figure 4 , introduce the corresponding initialization script and add the structure containing ID information to the global slice, insert a record after the initialization script is executed, and generate the database, data table and data required for operation. Including: obtaining the database type and performing initialization, adding the structure containing ID information to the global slice; sorting the global slice according to the ID information and traversing the global slice in order; detecting whether the current global slice has been initialized; if so, continue to traverse; if not, initialize the current global slice, insert a record, and generate the database, data table and data required for operation.
[0068] Initialization script execution: Then the corresponding initialization script file will be imported according to the database type. Figure 4 , while introducing the file path, the initialization method will be executed to add specific structures to the global slice. These structures contain an ID that records the time of the addition operation and is used to control the execution order. After execution, records will be inserted to avoid repeated execution, which is mainly used to generate the initialization of libraries, tables, and data required for system operation.
[0069] Further, refer to Figure 4, introduce the corresponding database change script according to the database type, and change the corresponding data table, field and index, including: obtaining the database type and initializing it, adding the structure containing ID information to the global slice; sorting the global slice according to the ID information and traversing the global slice in order; detecting whether the current global slice has been changed; if so, continuing to traverse; if not, making database changes to the current global slice, changing the corresponding data table, field and index, and inserting a change record.
[0070] Database change script execution: Import the corresponding database change script file according to the database type. The process of this step is similar to initialization, but the main difference is that this step is to deal with the modification of the database due to business changes during the software development process. In this way, each iteration of database changes can be traced together with the code changes, making the change process clear and straightforward, thereby reducing the upgrade cost and document maintenance cost.
[0071] Database script execution: Finally, the corresponding database script will be introduced according to the database type. Figure 5 As shown, when the file path is introduced, the initialization method is automatically executed, a structure with specific properties is created, and it is registered in the global observer slice.
[0072] For further information, see Figure 5 , executing the database control script according to the database type, including: obtaining the database type and performing initialization, adding the structure containing ID information to the global slice; sorting according to specific attributes and traversing all global observer slices in order; determining whether there is a preset dependency script identifier; if there is a dependency script identifier, comparing the index of the dependency script identifier item with the index position of the current item; if the index of the dependency script identifier item is greater than the index position of the current item, automatically adjusting the positions of the two and continuing the traversal.
[0073] To ensure the execution order between certain scripts, you can enforce the execution order by setting the value of DependencyScritId (dependency script identifier) and combining it with the IsBlock property (default value is true). During operation, traverse the slice and compare the slice position of the DependencyScritId item with the current item.
[0074] If the index of the DependencyScritId item is greater than the current item, the system will automatically adjust the positions of the two to ensure the correct execution order. In addition, the IsBlock property is used to control the synchronous execution between scripts.
[0075] Furthermore, executing the database control script according to the database type also includes: detecting whether the current item has executed the database script task; if it has been executed, continuing to traverse; if it has not been executed, obtaining the IsBlock property of the current item.
[0076] Furthermore, obtaining the IsBlock property of the current item includes: determining whether the IsBlock property of the current item is true; when IsBlock is set to true, it indicates that there is a strong dependency between the scripts, that is, the previous script must be successfully executed before the next script can start executing. This synchronous blocking mechanism ensures that the entire upgrade process is completed and the service can be started smoothly only after all dependent scripts are successfully executed. This design allows the system to flexibly handle complex database script execution logic while ensuring the stability and reliability of the service.
[0077] Furthermore, obtaining the IsBlock property of the current item also includes: if the IsBlock property of the current item is false, there is no strong dependency between the scripts, and multiple script tasks can be executed at the same time; creating a new coroutine and executing the next script task, inserting a change record and continuing to traverse until all script tasks are executed, completing the version update and recording of the database.
[0078] The embodiments of the present invention have the following advantages:
[0079] 1) Integrated database operations:
[0080] The present invention defines database operations as key steps during operation to ensure successful forced execution when the service is started. In this way, each database change can be recorded synchronously with the code change, making the change process clearer and easier to track, effectively reducing the cost of upgrades and document maintenance;
[0081] 2) Refined database change support: The present invention divides database change support into three categories: initialization requirements, iterative changes, and complex business scripts. This subdivision comprehensively covers all database operation requirements during software development, thus providing developers with a comprehensive and flexible database management solution;
[0082] 3) Universal Implementation Scheme: This invention defines a universal implementation scheme that allows users to provide specific scripts based on the type of database used. This modular design feature enables the system to easily adapt to new databases, avoids the problem of not supporting specific databases, and enhances the compatibility and scalability of the system.
[0083] Through its innovative technical solution, the present invention not only improves the automation and accuracy of database operations, but also reduces upgrade and maintenance costs, enhances the compatibility and stability of the system, promotes the synchronization of code and database, supports rapid iteration, and provides an efficient, flexible and reliable solution for software development and database management.
[0084] In addition, an embodiment of the present invention also provides a universal database version management device, which includes: a processor and a memory; the memory is used to store one or more program instructions; the processor is used to run one or more program instructions to execute the steps of a universal database version management method as described in any one of the above items.
[0085] In addition, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of a general database version management method as described in any one of the above items are implemented.
[0086] In the embodiment of the present invention, the processor may be an integrated circuit chip having the signal processing capability. The processor may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0087] The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The processor reads the information in the storage medium and completes the steps of the above method in combination with its hardware.
[0088] The storage medium may be a memory, which may be, for example, a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memory.
[0089] Among them, the non-volatile memory can be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory.
[0090] The volatile memory may be a random access memory (RAM) which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM).
[0091] The storage media described in the embodiments of the present invention are intended to include, but are not limited to, these and any other suitable types of memory.
[0092] Those skilled in the art will appreciate that in one or more of the above examples, the functions described in the present invention can be implemented using a combination of hardware and software. When software is used, the corresponding functions can be stored in a computer-readable medium or transmitted as one or more instructions or codes on a computer-readable medium. Computer-readable media include computer storage media and communication media, wherein communication media include any media that facilitates the transmission of computer programs from one place to another. Storage media can be any available media that can be accessed by general or special-purpose computers.
[0093] Although the present invention has been described in detail above with general explanations and specific embodiments, it is obvious to those skilled in the art that some modifications or improvements can be made to the present invention. Therefore, these modifications or improvements made without departing from the spirit of the present invention all fall within the scope of protection claimed by the present invention.
Claims
1. A general database version management method, characterized in that: The method is applied to a database type, which includes: Get the configuration information and extract the database configuration from it, and create the corresponding database connection according to the specified database type; Use the database type and detect whether initialization is required. If necessary, introduce the corresponding initialization script and add the structure containing ID information to the global slice. After the initialization script is executed, insert a record and generate the database, data table and data required for operation; If initialization is not required or has been completed, detect whether database changes are required. If changes are required, introduce the corresponding database change script according to the database type and change the corresponding data tables, data fields and indexes; If no database change is required or after the database change is completed, the database control script is executed according to the database type to complete the database version update and recording.
2. A general database version management method as claimed in claim 1, characterized in that: Import the corresponding initialization script and add the structure containing ID information to the global slice. After the initialization script is executed, insert a record and generate the database, data table, and data required for operation, including: Get the database type and perform initialization, and add the structure containing ID information to the global slice; Sort the global slices according to the ID information and traverse the global slices in order; Check whether the current global slice has been initialized; If yes, continue traversing; If not, initialize the current global slice, insert a record and generate the database, data table and data required for operation.
3. A general database version management method as claimed in claim 2, characterized in that: Introduce the corresponding database change script according to the database type and change the corresponding data tables, data fields and indexes, including: Get the database type and perform initialization, and add the structure containing ID information to the global slice; Sort the global slices according to the ID information and traverse the global slices in order; Check whether the current global slice has been changed; If yes, continue traversing; Otherwise, make database changes to the current global slice, change the corresponding data table, data field and index, and insert a change record.
4. A general database version management method as claimed in claim 3, characterized in that: Execute the database control script according to the database type, including: Get the database type and perform initialization, and add the structure containing ID information to the global slice; Sort by a specific property and iterate over all global observer slices in order; Determine whether there is a preset dependency script identifier; If a dependency script identifier exists, the index of the dependency script identifier item is compared with the index position of the current item; If the index of the dependency script identifier item is greater than the index position of the current item, swap the positions of the two and continue traversal.
5. A general database version management method as claimed in claim 4, characterized in that: Executing a database control script according to the database type also includes: Check whether the current item has executed the database script task; If it has been executed, continue traversing; If it has not been executed, get the IsBlock property of the current item.
6. A general database version management method as claimed in claim 5, characterized in that: Get the IsBlock property of the current item, including: Determine whether the IsBlock property of the current item is true; If the IsBlock property of the current item is true, there is a strong dependency between the scripts, and the next script task can be executed only after the current script task is executed; After the current script task is executed, a change record is inserted and the traversal continues until all script tasks are executed, completing the database version update and recording.
7. A general database version management method as claimed in claim 6, characterized in that: Gets the IsBlock property of the current item, including: If the IsBlock property of the current item is false, there is no strong dependency between the scripts, and multiple script tasks can be executed at the same time; Create a new coroutine and execute the next script task, insert a change record and continue to traverse until all script tasks are executed, completing the database version update and recording.
8. A general database version management system, characterized in that: The system comprises: Database connection module, used to obtain configuration information and extract database configuration from it, and create corresponding database connection according to the specified database type; The initialization script execution module is used to utilize the database type and detect whether initialization is required. If necessary, the corresponding initialization script is introduced and the structure containing the ID information is added to the global slice. After the initialization script is executed, a record is inserted and the database, data table, and data required for operation are generated; The database change script execution module is used to detect whether a database change is required if no initialization is required or after initialization is completed. If a change is required, the corresponding database change script is introduced according to the database type and the corresponding data table, data field and index are changed; The database control script execution module is used to execute the database control script according to the database type if no database change is required or after the database change is completed, so as to complete the version update and recording of the database.
9. A universal database version management device, characterized in that: The device comprises: a processor and a memory; The memory is used to store one or more program instructions; The processor is used to run one or more program instructions to execute the steps of a universal database version management method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a general database version management method as claimed in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data base script generalization implementing system and method
CN101221561A
Distributed data synchronization method and device, equipment and medium
CN111459954A
Database version control system and method
CN111857796A
Initialization system and method for localized database
CN114416120A
Method for realizing multi-tenant cross-database type on-demand automatic initialization and upgrading by using entity Nuget packet
CN116360818A
Cited By
Information storage method and system based on character device, storage medium and device
CN120104067A