Multi-tenant architecture-oriented government affair system database upgrading method
By integrating multi-data source scenario initiator and MyBatis SQL executor, the problem that the existing technology cannot flexibly upgrade multiple databases is solved, and the adaptation and upgrading of domestic databases is realized.
Patent Information
- Application Number
- CN202510423806.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-07
- Publication Date
- 2025-07-22
AI Technical Summary
The existing database version management framework Flyway and other databases cannot be flexibly upgraded to multiple databases and are not suitable for domestic databases.
By integrating a multi-data source scenario initiator, loading and storing multiple data sources, using MyBatis' SQL executor to obtain data source connections, and executing different types of domestic database scripts for upgrading.
It has achieved flexible upgrades to multiple different types of domestic databases, and is adapted to the database upgrade requirements of multi-tenant architecture government affairs systems.
Smart Images

Figure CN120353482A_ABST
Abstract
Description
Technical Field
[0001] The present invention discloses a method for upgrading a database of a multi-tenant architecture government affairs system, which relates to the technical field of database upgrading. Background Art
[0002] The functions of a multi-tenant government affairs system are mainly reflected in improving the efficiency of government affairs services and promoting data sharing and security. The multi-tenant government affairs system adopts cloud computing technology and realizes the opening of the data middle platform capabilities to various departments through the technical concept of multi-tenancy to provide services for enterprises. However, existing database version management frameworks such as Flyway cannot flexibly upgrade multiple databases and are not compatible with domestic databases. Summary of the Invention
[0003] Aiming at the problems of the existing technology, the present invention provides a method for upgrading a database of a multi-tenant architecture government affairs system. By integrating a multi-data source scenario starter, the loading and storage of multiple data sources are realized. When needed, the data sources are traversed to establish connections, and the SQL executor obtains the data source connections and executes scripts for different types of domestic databases to realize the upgrade of multiple different types of domestic databases.
[0004] The specific solution proposed by the present invention is as follows:
[0005] The present invention provides a method for upgrading a database of a multi-tenant architecture government affairs system, including:
[0006] Step 1: Loading and storing multiple data sources based on the multi-data source scenario starter of Spring Boot: In the configuration file, configure information of multiple data sources, configure the default data source, and data source grouping. The data source information includes the URL, username, password, and driver class name information of the data source. When starting the Spring Boot application, read the data source information in the configuration file, use the multi-data source scenario starter to initialize multiple data sources according to the configuration information, and store the data sources in the data source router;
[0007] Step 2: Establish a connection with the data source according to the database upgrade requirement, obtain the data source connection through the SQL executor of MyBatis, and execute scripts for different types of domestic databases to upgrade multiple different types of government affairs system databases:
[0008] Step 21: Dynamically select a data source according to the runtime context through the multi-data source scenario starter and establish a connection,
[0009] Step 22: Parse the database upgrade script through the SQL executor, identify the SQL statements, compile the parsed SQL statements into an execution plan, obtain a data source connection through the SQL executor, send the compiled execution plan to the government affairs system database server of the corresponding data source, and perform the upgrade according to the execution plan through the government affairs system database server.
[0010] Further, in step 1 of the method for upgrading a government affairs system database oriented to a multi-tenant architecture, in the configuration file, the default data source is also configured according to the configuration order, and the priority of the data source is set.
[0011] Further, in step 1 of the method for upgrading a government affairs system database oriented to a multi-tenant architecture, the addDataSource method of the data source router is used to store the data sources in the form of key-value pairs, where the key is the identifier of the data source and the value is the data source object.
[0012] Further, in step 21 of the method for upgrading a government affairs system database oriented to a multi-tenant architecture, when performing a database operation, the multi-data source scenario starter switches to the corresponding data source according to the data source information bound to the current thread. After switching the data source, subsequent database operations are executed on the switched data source until the data source is switched again.
[0013] The present invention also provides a device for upgrading a government affairs system database oriented to a multi-tenant architecture, including a multi-data source scenario starter module, a data source router module, and an SQL executor module
[0014] The multi-data source scenario starter module based on Spring Boot loads and stores multiple data sources: in the configuration file, configure multiple data source information, configure the default data source, and data source grouping. The data source information includes the URL, username, password, and driver class name information of the data source; when starting the Spring Boot application, read the data source information in the configuration file, initialize multiple data sources according to the configuration information using the multi-data source scenario starter, and store the data sources in the data source router module;
[0015] The multi-data source scenario starter module establishes a connection with the data source according to the database upgrade requirements, and the SQL executor module of MyBatis obtains the data source connection and executes different types of domestic database scripts to upgrade multiple different types of government affairs system databases:
[0016] The multi-data source scenario starter module dynamically selects a data source and establishes a connection according to the runtime context,
[0017] The SQL executor module parses the database upgrade script, identifies the SQL statements, compiles the parsed SQL statements into an execution plan, obtains the data source connection, sends the compiled execution plan to the government affairs system database server of the corresponding data source, and performs the upgrade according to the execution plan through the government affairs system database server.
[0018] Furthermore, in the configuration file, the multi-data source scenario starter module of the database upgrade device for the government affairs system with a multi-tenant architecture also configures the default data source according to the configuration order and sets the priority of the data source.
[0019] Furthermore, the data source router module of the database upgrade device for the government affairs system with a multi-tenant architecture uses the addDataSource method to store the data sources in the form of key-value pairs, where the key is the identifier of the data source and the value is the data source object.
[0020] Furthermore, when performing database operations, the multi-data source scenario starter module of the database upgrade device for the government affairs system with a multi-tenant architecture switches to the corresponding data source according to the data source information bound to the current thread. After switching the data source, subsequent database operations are executed on the switched data source until the data source is switched again.
[0021] The beneficial effects of the present invention are:
[0022] The present invention realizes the loading and storage of multiple data sources through the multi-data source scenario starter, traverses the data sources to establish connections when needed, the SQL executor obtains the data source connection, and executes different types of domestic database scripts to realize the upgrade of multiple different types of domestic databases. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a schematic flowchart of the method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] The following further describes the present invention in conjunction with the drawings and specific embodiments, so that those skilled in the art can better understand the present invention and be able to implement it, but the embodiments cited are not intended to limit the present invention.
[0025] Embodiment 1
[0026] The present invention provides a method for upgrading a database of a government affairs system with a multi-tenant architecture, including:
[0027] Step 1: Based on the multi-data source scenario starter dynamic-datasource-spring-boot-starter of Spring Boot, load and store multiple data sources: In the configuration file, configure the information of multiple data sources, configure the default data source, and data source grouping. Configure the default data source according to the configuration order and set the priority of the data sources. The data source information includes the URL, username, password, and driver class name information of the data source. When starting the Spring Boot application, read the data source information in the configuration file, use the multi-data source scenario starter to initialize multiple data sources according to the configuration information, and store the data sources in the data source router DynamicRoutingDataSource. Use the addDataSource method of the data source router to store the data sources in the form of key-value pairs, where the key is the identifier of the data source and the value is the data source object.
[0028] Step 2: Establish a connection with the data source according to the database upgrade requirements, obtain the data source connection through the SQL executor of MyBatis, execute the domesticated database scripts of different types, and upgrade multiple government affairs system databases of different types:
[0029] Step 21: Dynamically select the data source according to the runtime context through the multi-data source scenario starter and establish a connection. Among them, when performing database operations, switch to the corresponding data source through the multi-data source scenario starter according to the data source information bound to the current thread. After switching the data source, subsequent database operations are executed on the switched data source until the data source is switched again.
[0030] Step 22: Parse the database upgrade script through the SQL executor, parse and identify the SQL statements, compile the parsed SQL statements into an execution plan, obtain the data source connection through the SQL executor, send the compiled execution plan to the government affairs system database server of the corresponding data source, and perform the upgrade according to the execution plan through the government affairs system database server.
[0031] Among them, MyBatis is an excellent persistence layer framework that supports custom SQL, stored procedures, and advanced mapping. MyBatis eliminates almost all JDBC code, manual setting of parameters, and retrieval of result sets. SQL executor: org.apache.ibatis.jdbc.ScriptRunner is a utility class provided by MyBatis for running SQL scripts on a connected database.
[0032] Example 2
[0033] The present invention also provides a database upgrade device for a multi-tenant architecture government affairs system, including a multi-data source scenario starter module, a data source router module, and an SQL executor module.
[0034] The multi-data source scenario starter module based on Spring Boot loads and stores multiple data sources: In the configuration file, configure information of multiple data sources, configure the default data source, and data source grouping. The data source information includes the URL, username, password, and driver class name information of the data source; when starting the Spring Boot application, read the data source information in the configuration file, use the multi-data source scenario starter to initialize multiple data sources according to the configuration information, and store the data sources in the data source router module.
[0035] The multi-data source scenario starter module establishes a connection with the data source according to the database upgrade requirement. The SQL executor module of MyBatis obtains the data source connection and executes scripts of different types of domestic databases to upgrade multiple different types of government affairs system databases:
[0036] The multi-data source scenario starter module dynamically selects a data source and establishes a connection according to the runtime context.
[0037] The SQL executor module parses the database upgrade script, parses and identifies the SQL statements, compiles the parsed SQL statements into an execution plan, obtains the data source connection, and sends the compiled execution plan to the government affairs system database server of the corresponding data source. The government affairs system database server performs the upgrade according to the execution plan.
[0038] Regarding the information interaction and execution process among the above-mentioned modules in the device, since they are based on the same concept as the method embodiment of the present invention, the specific content can be referred to the description in the method embodiment of the present invention and will not be elaborated here.
[0039] Similarly, the device of the present invention realizes the loading and storage of multiple data sources through the multi-data source scenario starter, traverses the data sources to establish connections when needed, the SQL executor obtains the data source connection, and executes scripts of different types of domestic databases to realize the upgrade of multiple different types of domestic databases.
[0040] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted according to needs. The system structures described in the above-mentioned embodiments can be physical structures or logical structures, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities respectively, or some components in multiple independent devices can be jointly implemented.
[0041] The above-described embodiments are merely preferred embodiments given to fully illustrate the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or transformations made by those skilled in the art on the basis of the present invention are all within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.
Claims
1. A database upgrade method for a multi-tenant architecture government affairs system, characterized in that Including: Step 1: Loading and storing multiple data sources by the multi-data source scenario starter based on Spring Boot: In the configuration file, configure information of multiple data sources, configure the default data source, and data source grouping. The data source information includes the URL, username, password, and driver class name information of the data source; When starting the Spring Boot application, read the data source information in the configuration file, use the multi-data source scenario starter to initialize multiple data sources according to the configuration information, and store the data sources in the data source router; Step 2: Establish a connection with the data source according to the database upgrade requirements, obtain the data source connection through the SQL executor of MyBatis, execute different types of domestic database scripts, and upgrade multiple different types of government affairs system databases: Step 21: Dynamically select a data source and establish a connection according to the runtime context through the multi-data source scenario starter, Step 22: Parse the database upgrade script through the SQL executor, parse and identify the SQL statements, compile the parsed SQL statements into an execution plan, obtain the data source connection through the SQL executor, send the compiled execution plan to the government affairs system database server of the corresponding data source, and perform the upgrade according to the execution plan through the government affairs system database server.
2. A method for upgrading a database of a government affairs system oriented to a multi-tenant architecture according to claim 1, characterized in that In Step 1, in the configuration file, the default data source is also configured according to the configuration order, and the priority of the data source is set.
3. A method for upgrading a database of a government affairs system oriented to a multi-tenant architecture according to claim 1 or 2, characterized in that In Step 1, use the addDataSource method of the data source router to store the data sources in the form of key-value pairs. The key is the identifier of the data source, and the value is the data source object.
4. A method for upgrading a database of a multi-tenant architecture government affairs system according to claim 1, characterized in that In Step 21, when performing database operations, switch to the corresponding data source according to the data source information bound to the current thread through the multi-data source scenario starter. After switching the data source, subsequent database operations are executed on the switched data source until the data source is switched again.
5. A database upgrade device for a multi-tenant architecture government affairs system, characterized in that Including a multi-data source scenario starter module, a data source router module, and an SQL executor module The multi-data source scenario starter module based on Spring Boot loads and stores multiple data sources: In the configuration file, configure information of multiple data sources, configure the default data source, and data source grouping. The data source information includes the URL, username, password, and driver class name information of the data source; When starting the Spring Boot application, read the data source information in the configuration file, use the multi-data source scenario starter to initialize multiple data sources according to the configuration information, and store the data sources in the data source router module; The multi-data source scenario starter module establishes a connection with the data source according to the database upgrade requirements, and the SQL executor module of MyBatis obtains the data source connection and executes different types of domestic database scripts to upgrade multiple different types of government affairs system databases: The multi-data source scenario starter module dynamically selects a data source and establishes a connection according to the runtime context, The SQL executor module parses the database upgrade script, identifies the SQL statements, compiles the parsed SQL statements into an execution plan, obtains the data source connection, sends the compiled execution plan to the government affairs system database server of the corresponding data source, and performs the upgrade according to the execution plan through the government affairs system database server.
6. The database upgrade device for a multi-tenant architecture government affairs system according to claim 5, characterized in that In the configuration file, the multi-data source scenario starter module also configures the default data source according to the configuration order and sets the priority of the data source.
7. A database upgrade device for a government affairs system oriented to a multi-tenant architecture according to claim 5 or 6, characterized in that the data source router module uses the addDataSource method to store the data source in the form of key-value pairs, where the key is the identifier of the data source and the value is the data source object.
8. The database upgrade device for a multi-tenant architecture e-government system according to claim 5, characterized in that When performing database operations, the multi-data source scenario starter module switches to the corresponding data source according to the data source information bound to the current thread. After switching the data source, subsequent database operations are executed on the switched data source until the data source is switched again.