CN-122019500-A - Heterogeneous database migration method and device
Abstract
The invention relates to the technical field of databases and provides a heterogeneous database migration method and a heterogeneous database migration device, wherein the method comprises the steps of obtaining object definition metadata of a source database and service logic codes of an associated application system; the method comprises the steps of carrying out grammar structure analysis on a business logic code, combining object definition metadata, identifying grammar incompatibility items and structure difference items between a source database and a target database, matching a rewrite strategy corresponding to the grammar incompatibility items and the structure difference items based on a preset difference adaptation rule base, converting the object definition metadata into target structure definition of an adaptation target database according to the rewrite strategy, reconstructing the business logic code into target execution statements of the adaptation target database, constructing a target database environment based on the target structure definition, and configuring the target execution statements in the target database environment or related business interfaces thereof, thereby avoiding uncertainty of manually correcting codes and improving operation stability of the system in heterogeneous database environments.
Inventors
- LIU ZHIYUAN
- Ding Zhaozheng
- Lian Jiangyang
- WANG MENGYAN
- LV MINGWEI
Assignees
- 中车青岛四方机车车辆股份有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260113
Claims (10)
- 1. A heterogeneous database migration method, comprising: Acquiring object definition metadata of a source database and service logic codes of associated application systems; carrying out grammar structure analysis on the service logic codes, and identifying grammar incompatibility items and structure difference items between the source database and the target database by combining the object definition metadata; matching the rewrite strategy corresponding to the grammar incompatibility item and the structure difference item based on a preset difference adaptation rule base; According to the rewrite strategy, converting the object definition metadata into target structure definition of an adaptation target database, and reconstructing the business logic code into a target execution statement of the adaptation target database; and constructing a target database environment based on the target structure definition, and configuring the target execution statement in the target database environment or a service interface related to the target database environment so as to complete migration and adaptation of a database.
- 2. The heterogeneous database migration method of claim 1, wherein the parsing the service logic code comprises: decomposing the static structured query statement in the service logic code to generate grammar tree nodes containing function calls, keywords and grammar clauses; Sampling before executing the dynamic query statement in the service logic code to obtain an actual query statement generated in the running process, and analyzing the actual query statement into a dynamic grammar structure.
- 3. The heterogeneous database migration method of claim 2, wherein the identifying syntax incompatibility terms and structure difference terms between the source database and the target database in combination with the object definition metadata comprises: extracting field types, index types and constraint attributes in the object definition metadata, and respectively comparing the field types, the index types and the constraint attributes with preset mapping rules and support lists of a target database to identify field type mismatch items, index type unsupported items and constraint attribute incompatible items existing in the source database as the structure difference items; Traversing the grammar tree node and the dynamic grammar structure, extracting the function identifier, the reserved keyword and the query logic clause contained in the grammar tree node and matching the grammar tree node with a grammar rule base of a target database, and screening out the function identifier, the reserved keyword and the query logic clause which are not supported by the target database as the grammar incompatibility item.
- 4. The heterogeneous database migration method of claim 1, wherein when the identified structure difference item is a self-increasing attribute in a source database table structure, the matched rewrite strategy is a combined strategy of mapping self-increasing attribute to a sequence object and a trigger object; The converting the object definition metadata into a target structure definition of an adaptation target database according to the rewrite strategy includes: Executing the combination strategy, and generating a definition statement for creating a sequence object in a target database; acquiring the current maximum value of the self-increment list in a source database, and generating a sequence synchronization statement for setting the starting value of the sequence object based on the current maximum value; generating a definition statement for creating a pre-insertion trigger in a target database, wherein the pre-insertion trigger is configured to acquire a numerical value from the sequence object and assign the numerical value to a target column during a data insertion operation; And combining the definition statement of the created sequence object, the sequence synchronous statement and the definition statement of the trigger before creation and insertion into the target structure definition.
- 5. The heterogeneous database migration method according to claim 1, wherein the constructing a target database environment based on the target structure definition specifically comprises: connecting a target database instance, executing the target structure definition to establish a data table structure, and temporarily disabling non-primary key indexes and foreign key constraints in the table structure; After a data table structure is established, data migration is executed, a data table of a source database is divided into a plurality of data fragments according to a main key range, and the total data fragments are imported into the target database environment in a multithreading parallel mode; After the full import is completed, capturing data change events generated during the full import based on transaction change logs of a source database, and playing back the data change events to the target database environment to realize incremental synchronization; And after the data migration is completed, reconstructing the non-primary key index and the foreign key constraint to complete the construction of the target database environment.
- 6. The heterogeneous database migration method of claim 5, wherein the replaying the data change event to the target database environment to achieve incremental synchronization comprises: analyzing a global transaction identifier and an operation site in the transaction change log; Inquiring a synchronous log table in a target database before playback, and judging whether a global transaction identifier of a current data change event exists or not; And if the data change event does not exist, executing the data change event and writing the corresponding global transaction identifier into the synchronous log table so as to realize incremental synchronization.
- 7. The heterogeneous database migration method of claim 1, wherein the business logic code comprises an object relationship mapping configuration file of an application system, and a database connection configuration containing transaction isolation level parameters; the configuring the target execution statement in the target database environment or the associated service interface thereof comprises the following steps: Updating the target execution statement into the object relation mapping configuration file; And adapting the database connection configuration serving as the service interface, replacing a database driver of the application system with a driver version of an adaptation target database, and adjusting the transaction isolation level parameter to be consistent with the default level of the target database.
- 8. The heterogeneous database migration method according to any one of claims 1 to 7, further comprising, after completing migration and adaptation of the database: Sorting and dividing corresponding data tables in a source database and a target database into a plurality of logic segments according to a primary key; Respectively calculating a splicing hash value of the data in each logic segment in the source database and the target database; and comparing the spliced hash values corresponding to the two ends, if the spliced hash values are inconsistent, marking the logic segment as a difference segment, and comparing the data in the difference segment line by line to locate specific difference data.
- 9. A heterogeneous database migration apparatus, comprising: The acquisition module is used for acquiring the object definition metadata of the source database and the service logic codes of the associated application system; the analysis module is used for carrying out grammar structure analysis on the business logic codes and combining the object definition metadata to identify grammar incompatible items and structure difference items between the source database and the target database; the matching module is used for matching the rewrite strategy corresponding to the grammar incompatibility item and the structure difference item based on a preset difference adaptation rule base; the reconstruction module is used for converting the object definition metadata into target structure definition of the adaptation target database according to the rewrite strategy, and reconstructing the business logic code into a target execution statement of the adaptation target database; and the migration module is used for constructing a target database environment based on the target structure definition, and configuring the target execution statement in the target database environment or a service interface related to the target database environment so as to complete migration and adaptation of the database.
- 10. An electronic device comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein the processor implements the heterogeneous database migration method of any of claims 1 to 8 when the computer program is executed by the processor.
Description
Heterogeneous database migration method and device Technical Field The present invention relates to the field of database technologies, and in particular, to a heterogeneous database migration method and apparatus. Background With the deep advancement of national credit engineering, the localization substitution of databases for enterprise-level application systems has become a necessary trend. In this process, many key business systems originally built based on MySQL, such as vendor relation management systems, face urgent demands for migration to domestic databases due to their large data volume, complex SQL logic and high dependency on specific syntactic properties of MySQL. Such migration not only requires the replacement of data storage, but also requires the maintenance of system service continuity, data consistency and performance stability in a trusted environment. Existing database migration schemes typically employ a generic data extraction conversion loading tool, a database self-contained logic export import command, or a manual code modification approach. In the implementation, technicians often rely on standard SQL sentences to carry out data handling, and attempt to convert the table structure of the source database and query sentences in service codes into formats supported by the target database by using text processing means such as regular expression replacement, so as to complete switching among heterogeneous databases. However, the above prior art migration has a major technical problem, namely, lack of an automatic compatible adaptation mechanism for deep grammar logic and structural characteristics among heterogeneous databases. Because incompatible points generated by different database dialects, data type mapping and different bottom object definitions cannot be accurately identified and automatically repaired through a regularization means, the conventional scheme is difficult to ensure the execution correctness and data consistency of the migrated business logic under low manual intervention, so that the migration risk of a core business system is high and the stability is difficult to ensure. Disclosure of Invention The invention provides a heterogeneous database migration method and device, which are used for solving the defects that in the prior art, the execution correctness and data consistency of service logic after migration are difficult to guarantee, migration risk is high and stability is poor due to the lack of an automatic compatible adaptation mechanism aiming at deep grammar logic and structural characteristics among heterogeneous databases. The invention provides a heterogeneous database migration method, which comprises the following steps: Acquiring object definition metadata of a source database and service logic codes of associated application systems; carrying out grammar structure analysis on the service logic codes, and identifying grammar incompatibility items and structure difference items between the source database and the target database by combining the object definition metadata; matching the rewrite strategy corresponding to the grammar incompatibility item and the structure difference item based on a preset difference adaptation rule base; According to the rewrite strategy, converting the object definition metadata into target structure definition of an adaptation target database, and reconstructing the business logic code into a target execution statement of the adaptation target database; and constructing a target database environment based on the target structure definition, and configuring the target execution statement in the target database environment or a service interface related to the target database environment so as to complete migration and adaptation of a database. The method for migrating the heterogeneous database comprises the steps of decomposing static structured query sentences in the service logic codes to generate grammar tree nodes containing function calls, keywords and grammar clauses, sampling before execution of dynamic query sentences in the service logic codes to obtain actual query sentences generated in running, and analyzing the actual query sentences into dynamic grammar structures. According to the heterogeneous database migration method provided by the invention, the grammar incompatible item and the structure difference item between the source database and the target database are identified by combining the object definition metadata, which comprises the steps of extracting field types, index types and constraint attributes in the object definition metadata, and respectively comparing the field types, the index types and the constraint attributes with preset mapping rules and support lists of the target database to identify the field type incompatible item, the index type incompatible item and the constraint attribute incompatible item existing in the source database as the structure difference item; Traversing th