Heterogeneous database migration method and device, electronic equipment and storage medium

By establishing a communication connection between the source database and the target database, the migration of table structure, data, views and stored procedures is automatically performed, and the migration problem in the multi-source domestic heterogeneous database environment is solved, and the migration efficiency and accuracy are improved. Migration between multiple databases.

CN119166608APending Publication Date: 2024-12-20TONGFANG KNOWLEDGE NETWORK DIGITAL PUBLISHING TECHNOLOGY CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202411109514.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-13
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

Due to the diversity of business needs, uneven technological development and historical problems, enterprises have adopted a variety of different types of database systems, resulting in a multi-source domestic heterogeneous database environment, making it difficult to realize database migration.

Method used

After establishing a communication connection between the source database and the target database, table structure migration, data migration, view and stored procedure migration are automatically performed, supporting migration between multiple domestic and non-domestic databases, and obtaining table information and determining the table to be migrated , perform table structure analysis and mapping, select data transit method, perform data migration, and convert relationships through statements to convert views and stored procedures.

Benefits of technology

It realizes comprehensive database migration, improves migration efficiency, reduces errors, supports migration between multiple databases, and ensures data consistency and integrity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166608A_ABST
    Figure CN119166608A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a heterogeneous database migration method and device, electronic equipment and a storage medium, according to the method, after communication connection with a source database and a target database is established, the steps of table structure migration, data migration and view and storage process migration are automatically executed, comprehensive migration of the database is achieved, and the migration efficiency of the database is improved. And meanwhile, migration among various localized databases and non-localized databases is supported, the migration efficiency is improved, and errors are not prone to occurring. The method comprises the following steps: respectively establishing communication connection with a source database and a target database; migrating a table structure of the source database to the target database; migrating the data of the source database to the target database; and migrating the view and the storage process of the source database to a target database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of database migration, and in particular to a method, device, electronic device and storage medium for migrating heterogeneous databases. Background Art

[0002] In the context of the rapid development of information technology today, diversified databases provide a solid knowledge and information resource foundation for the efficient sharing and integration of knowledge resources in the whole society. In view of the in-depth implementation of the localization policy, the demand for comprehensive localization of equipment is becoming increasingly urgent, and the database system is also facing the inevitable trend of migrating to the localized database.

[0003] However, due to the diversity of business needs, the imbalance of technological development, and the complexity of historical problems, enterprises often have to use a variety of different types of database systems to store and manage data. This multi-source domestic heterogeneous database environment has brought great challenges to enterprises. Therefore, how to achieve the migration of heterogeneous databases has become a technical problem that technicians in this field need to solve urgently. Summary of the invention

[0004] The present application provides a heterogeneous database migration method, device, electronic device and storage medium. After establishing a communication connection with a source database and a target database, the method automatically executes the steps of table structure migration, data migration, view and stored procedure migration to achieve comprehensive database migration. At the same time, it supports migration between multiple domestic databases and non-domestic databases, improves migration efficiency and is less prone to errors.

[0005] In a first aspect, an embodiment of the present application provides a method for migrating a heterogeneous database, including:

[0006] Establish communication connections with the source database and the target database respectively;

[0007] Migrating the table structure of the source database to the target database;

[0008] Migrating the data of the source database to the target database;

[0009] Migrate the views and stored procedures of the source database to the target database.

[0010] In some embodiments, the step of migrating the table structure of the source database to the target database includes:

[0011] Get the table information of the source database;

[0012] Determine a list of tables to be migrated from the table information, wherein the list of tables to be migrated includes at least one table to be migrated;

[0013] Parsing the table structure of the table to be migrated to obtain entity classes and mapping files;

[0014] Mapping the entity class and mapping file to the target database, and constructing a table structure mapping relationship between the source database and the target database;

[0015] According to the table structure mapping relationship, the tables to be migrated in the to-be-migrated list are migrated to the target database.

[0016] In some embodiments, the step of migrating the data of the source database to the target database includes:

[0017] Determine a data transfer method according to the table to be migrated;

[0018] Determine the range of data to be migrated in the table to be migrated;

[0019] By using the data transfer method, data corresponding to the data range to be migrated is read from the source database, the read data is stored in a transfer container, and the data in the transfer container is written into the target database.

[0020] In some embodiments, the method further comprises:

[0021] Check whether the data is successfully written into the target database;

[0022] If the writing is successful, a consistency check is performed on the data in the source database and the data written into the target database;

[0023] If the verification is successful, the data in the transfer container is deleted.

[0024] In some embodiments, the step of migrating the views and stored procedures of the source database to the target database includes:

[0025] Get views and stored procedures in the source database;

[0026] Constructing statement conversion relationships corresponding to the views and stored procedures respectively;

[0027] The view and stored procedure of the source database are converted into a format compatible with the target database by using the statement conversion relationship; the converted view and stored procedure are executed in the target database to generate the corresponding view and stored procedure in the target database.

[0028] In some embodiments, the step of constructing a statement conversion relationship between the view and the stored procedure includes:

[0029] Obtain the corresponding syntax file according to the type of source database and target database;

[0030] The visitor pattern generated by the syntax analyzer generator corresponding to the syntax file is used to traverse the abstract syntax tree of the stored procedure in the source database, and to construct equivalent views and equivalent stored procedures of the target database to obtain view and stored procedure statement conversion relationships.

[0031] In some embodiments, the step of establishing a communication connection with the source data includes:

[0032] A communication connection with the source database is established using a standard database connection protocol according to preset configuration information of the source database.

[0033] In a second aspect, an embodiment of the present application further provides a heterogeneous database migration device, including:

[0034] A connection unit, used to establish communication connections with a source database and a target database respectively;

[0035] A first migration unit, configured to migrate the table structure of the source database to the target database;

[0036] A second migration unit, configured to migrate the data of the source database to the target database;

[0037] The third migration unit is used to migrate the views and stored procedures of the source database to the target database.

[0038] In a third aspect, an embodiment of the present application further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the heterogeneous database migration method when executing the computer program.

[0039] In a fourth aspect, the present application also provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the heterogeneous database migration method are implemented.

[0040] In the above embodiment, a heterogeneous database migration method, device, electronic device and storage medium are provided. After establishing a communication connection with the source database and the target database, the method automatically performs the steps of table structure migration, data migration, view and stored procedure migration to achieve comprehensive database migration, and supports migration between multiple domestic databases and non-domestic databases, thereby improving migration efficiency and preventing errors. The method includes: establishing a communication connection with the source database and the target database respectively; migrating the table structure of the source database to the target database; migrating the data of the source database to the target database; migrating the views and stored procedures of the source database to the target database. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 A flowchart of a method for migration based on heterogeneous databases provided according to some embodiments is exemplified;

[0042] Figure 2 A flowchart of another method for migration based on heterogeneous databases provided according to some embodiments is exemplified;

[0043] Figure 3 A flowchart of another method for migration based on heterogeneous databases provided according to some embodiments is exemplarily shown;

[0044] Figure 4 A flowchart of another method for migration based on heterogeneous databases provided according to some embodiments is exemplarily shown;

[0045] Figure 5 A schematic structural diagram of a migration device based on a heterogeneous database provided according to some embodiments is exemplarily shown. DETAILED DESCRIPTION

[0046] In order to make the purpose and implementation method of the present application clearer, the exemplary implementation method of the present application will be clearly and completely described below in conjunction with the drawings in the exemplary embodiments of the present application. Obviously, the described exemplary embodiments are only part of the embodiments of the present application, rather than all the embodiments.

[0047] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.

[0048] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.

[0049] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.

[0050] Due to the diversity of business needs, the imbalance of technological development, and the complexity of historical problems, enterprises often have to use a variety of different types of database systems to store and manage data. This multi-source domestic heterogeneous database environment has brought great challenges to enterprises. Therefore, how to achieve the migration of heterogeneous databases has become a technical problem that technicians in this field need to solve urgently.

[0051] In order to solve the above technical problems, an embodiment of the present application provides a heterogeneous database migration method. After establishing a communication connection with the source database and the target database, the method automatically executes the steps of table structure migration, data migration, view and stored procedure migration, thereby realizing comprehensive migration of the database. At the same time, it supports migration between multiple domestic databases and non-domestic databases, thereby improving migration efficiency and making it less error-prone.

[0052] Figure 1 A heterogeneous database migration method provided according to some embodiments is exemplarily shown, and the method includes S100-S400.

[0053] S100: Establish communication connections with a source database and a target database respectively.

[0054] It should be noted that the method of the present application is executed by a control system, which first establishes a communication connection with a source database. The connection with the target database can be completed before step S200 or during the execution of step S200.

[0055] In some embodiments, the step of establishing a communication connection with the source database includes: using a standard database connection protocol and establishing a communication connection with the source database according to preset configuration information of the source database.

[0056] Standard database connection protocols can include JDBC, ODBC or ADO.NET. JDBC is a standard Java API for database connection in the Java programming language. ODBC is an open standard API that defines how an application accesses a database. ADO.NET is a set of class libraries in the .NET Framework for data access.

[0057] The configuration information of the preset source database includes the type, address, port, user name and password of the source database. This allows the system to establish an encrypted and stable communication connection with the source database. The system in this embodiment supports dynamic configuration, provides a management interface, and supports users to dynamically add, modify or delete data source information, including database connection parameters (such as IP address, port number, user name, password), database type, version, etc.

[0058] The system in the embodiment of the present application supports migration between mainstream domestic databases, including migration between DAMO database and DAMO database, between Renmin University Jincang database and Renmin University Jincang database, and between DAMO database and Renmin University Jincang database. It supports migration between mainstream non-domestic databases, including migration between MySQL database and MySQL database, SQL Server database and SQL Server database, SQLite database and SQLite database, MySQL database and SQLite database, MySQL database and SQL Server database, and SQLite database and SQL Serve r database. It also supports migration between domestic and non-domestic databases, including migration between DAMO database and MySQL database, DAMO database and SQL Server database, DAMO database and SQLite database, Renmin University Jincang database and MySQL database, Renmin University Jincang database and SQL Server database, and Renmin University Jincang database and SQLite database.

[0059] S200: Migrate the table structure of the source database to the target database.

[0060] The system in the embodiment of the present application provides the ability to automatically convert and synchronize the table structure in the source database, so as to automatically convert the structural information such as table definition, field definition, index, primary key, foreign key constraint, etc. in the source database into a format compatible with the target database, and synchronize it to the target database.

[0061] In some embodiments, Figure 2 A flowchart of another heterogeneous database migration method provided according to some embodiments is exemplarily shown, wherein the step of migrating the table structure of the source database to the target database includes S201-S205.

[0062] S201, obtaining table information of the source database;

[0063] In this embodiment, after the system is connected to the source database, the system executes specific SQL query statements (for example, SHOW TABLES, INFORMATION_SCHEMA.TABLES, etc., and the selection of SQL query statements depends on the type of the source database) to traverse and collect table information of all tables in the source database, including but not limited to table name, creation time, schema, etc. This table information provides basic data support for subsequent migration steps.

[0064] S202: Determine a list of tables to be migrated from the table information, where the list of tables to be migrated includes at least one table to be migrated.

[0065] In this embodiment, the system provides an interface or an API interface, allowing the user to manually select the table to be migrated according to needs.

[0066] S203: parse the table structure of the table to be migrated to obtain entity classes and mapping files.

[0067] In this embodiment, for the migration table, the database table is reverse parsed by Hibernate to generate Hibernate entity classes and mapping files, thereby parsing and collecting detailed information of the table structure, including table fields, table field constraints, indexes, and table data volume estimation.

[0068] Among them, Hibernate is an open source object-relational mapping (ORM) framework that establishes a mapping relationship between POJO (Plain Old Java Object) and a database table, thereby achieving seamless interaction between the object and the database.

[0069] S204, mapping the entity class and the mapping file to the target database, and constructing a table structure mapping relationship between the source database and the target database;

[0070] In this embodiment, the obtained entity class and mapping file are mapped to the target database, and a table structure mapping relationship between the source database and the target database is constructed. The table structure mapping relationship includes field-level mapping (such as type conversion, name adjustment), constraints, and index reconstruction strategies.

[0071] S205 . Migrate the tables to be migrated in the to-be-migrated list to the target database according to the table structure mapping relationship.

[0072] In this embodiment, according to the table structure mapping relationship, the step of migrating the table to be migrated in the to-be-migrated list to the target database includes generating and executing a corresponding SQL script according to the table structure mapping relationship. The SQL script can be understood as a section of language. The table structure of each database can be described in language. The SQL script is a description language of the table structure in the target database. Then, the system calls the database management API to create relevant tables in the target database.

[0073] The system in the embodiment of the present application supports table mapping, mapping the table structure in the source database to the corresponding table structure in the target database. Automatic mapping is achieved, based on the preset mapping rules, the table structure differences between the source database and the target database are automatically analyzed to generate a preliminary mapping relationship; at the same time, a flexible custom mapping function is provided to support users to adjust the mapping relationship according to actual needs, including field mapping, data type conversion, index and constraint creation, etc.; mapping verification is supported, and the mapping relationship is verified before data migration to ensure the correctness and completeness of the mapping and avoid data loss or errors.

[0074] In addition, the system and the target database establish a communication connection, which can be completed before step S200 or in step S205. Specifically, the system first establishes a communication connection with the target database, and then migrates the table to be migrated in the list to be migrated to the target database according to the table structure mapping relationship.

[0075] S300: Migrate data from the source database to the target database.

[0076] In an embodiment of the present application, a data migration function may be provided to achieve migration of data in a source database to a target database.

[0077] In some embodiments, Figure 3 The flowchart of another heterogeneous database migration method provided according to some embodiments is exemplarily shown. The step of migrating the data of the source database to the target database includes S301-S303.

[0078] S301: Determine a data transfer method according to the table to be migrated.

[0079] In some embodiments, a transfer mode can be automatically selected according to the data volume of the table to be migrated. The data transfer modes include memory transfer and file transfer. Specifically, according to the table to be migrated, the step of determining the data transfer mode includes determining the data volume of the table to be migrated, and if the data volume is not greater than a preset data volume, determining the data transfer mode is memory transfer. If the data volume is greater than a preset data volume, determining the data transfer mode is file transfer.

[0080] In this embodiment, the memory transfer is a transfer method for data in the migration process for small or medium-sized data. In this way, data is directly read from the source database into the memory and then quickly written to the target database. The advantage of memory transfer is fast speed and low latency, which is suitable for processing time-sensitive data migration tasks.

[0081] The file transfer mentioned above refers to the transfer method of data during the migration process when the amount of data is large and exceeds the memory processing capacity. At this time, the data will be read into temporary files in batches. After all data is exported, it will be imported into the target database in batches from the files. The advantage of file transfer is that it can handle large-scale data sets and supports breakpoint resumption, which enhances the robustness and reliability of the migration process.

[0082] S302: Determine the range of data to be migrated in the table to be migrated.

[0083] In this embodiment, the range of data to be migrated can be selected according to actual conditions. The range of data to be migrated includes all data and filtered data. The filtered data can be obtained by querying and filtering by the user through an interface provided by the system.

[0084] When the range of data to be migrated is all data, all data in the table to be migrated will be migrated. When the range of data to be migrated is filtered data, only the filtered data in the table to be migrated will be migrated.

[0085] The system in the embodiment of the present application supports automatic construction of table structure mapping conversion and index conversion between multiple databases, and supports full table copying of the table to be migrated and multiple data ranges to be migrated of query result copying.

[0086] S303: Using the data transfer method, read data corresponding to the data range to be migrated from the source database, store the read data in a transfer container, and write the data in the transfer container into the target database.

[0087] Specifically, firstly, data corresponding to the scope to be migrated is read from the source database, the read data is stored in the transfer container (content or temporary file) specified in step S301, and then the data in the transfer container is written into the target database.

[0088] In some embodiments, in order to ensure the integrity, consistency and security of data migration, the method further includes:

[0089] Check whether the data is successfully written into the target database;

[0090] If the writing is successful, a consistency check is performed on the data in the source database and the data written into the target database;

[0091] If the verification is successful, the data in the transfer container is deleted.

[0092] In the embodiment of the present application, the consistency check method can be to determine whether the data written into the target database has the same amount of data when it is in the target database and the source database, and whether the number of fields is consistent. If they are consistent, the check is successful, and the space in the transfer container can be released at this time, and the data in the transfer container can be deleted.

[0093] The system in the embodiment of the present application supports data migration. The migration process is executed according to the predetermined migration strategy and mapping relationship to migrate the data in the source database to the target database. It supports concurrent migration and uses multi-threading technology to achieve concurrent execution of data migration. It supports error handling and retry mechanisms. When an error is encountered during the migration process, error handling is automatically performed and retries are performed according to the preset retry strategy to ensure the smooth completion of the migration task. During the data migration process, the migrated data is verified to ensure the integrity and consistency of the data.

[0094] S400: Migrate the views and stored procedures of the source database to the target database.

[0095] In the embodiment of the present application, the system provides the function of view and stored procedure migration to realize the migration of views and stored procedures in the source database to the target database system.

[0096] The system in the embodiment of the present application supports data source management, centrally manages and configures all database resources involved in the migration, and realizes multi-source access.

[0097] In some embodiments, Figure 4 The flowchart of another heterogeneous database migration method provided according to some embodiments is exemplarily shown. The step of migrating the views and stored procedures of the source database to the target database includes S401-S403.

[0098] S401. Obtain views and stored procedures in the source database.

[0099] In this embodiment, by executing predefined SQL query statements, all views and stored procedures defined in the source database are fully scanned and captured. This process is not limited to obtaining object names, but goes deeper into the creation statement (DDL, Data Definition Language) of each view and stored procedure.

[0100] S402: Construct statement conversion relationships corresponding to the views and stored procedures respectively.

[0101] In this embodiment, after obtaining the creation statements of views and stored procedures, a view and stored procedure statement conversion relationship from the source database to the target database is constructed based on factors such as syntax differences, data type compatibility, and mapping rules of functions and operators between the source database and the target database.

[0102] In some embodiments, the step of constructing a statement conversion relationship between the view and the stored procedure includes:

[0103] According to the type of the source database and the type of the target database, a corresponding grammar file (exemplarily, an ANTLR 4 grammar file) is obtained.

[0104] In this embodiment, the type of the source database and the type of the target database can be DAMO or RD Financial Holdings, and the cross-platform databases include MySQL, SQLite, and SQL Server in Windows environment.

[0105] The visitor pattern generated by the syntax analyzer generator (exemplarily, ANTLR) corresponding to the syntax file is used to traverse the abstract syntax tree (AST) of the stored procedure in the source database to obtain the view and stored procedure statement conversion relationship.

[0106] In this embodiment, first, according to the selected source database type and target database type, the corresponding ANTLR 4 grammar file is obtained, and then the visitor pattern generated by ANTLR is used to traverse the AST (abstract syntax tree) of the source database view and stored procedure, and build the equivalent view and equivalent stored procedure of the target database. In this embodiment, it supports the processing of complex problems including but not limited to SQL dialect differences and specific database function support differences. At the same time, the system also supports user-defined conversion rules to meet specific business needs or solve compatibility issues between specific databases.

[0107] It should be noted that ANTLR 4 is a parser generator for reading, processing, executing and translating structured text or binary files. It generates a lexical analyzer (Lexer) and a grammatical analyzer (Parser) by defining the grammatical rules of the language, and then parses the input text and builds a parse tree (Parse Tree). The ANTLR 4 grammar file is a text file that defines the language structure. The system has built-in ANTLR 4 (.g4 files) for multiple databases. ANTLR generates parsers and lexical analyzers based on built-in rules. AST is a tree representation of the abstract grammatical structure of the source code. It does not depend on the grammar of the source language and can clearly represent the structure of the program. The visitor pattern defines a visitor for the database's AST, which can traverse nodes and perform conversion logic based on node types.

[0108] S403. Using statement conversion relationships, convert the views and stored procedures of the source database into a format compatible with the target database; execute the converted views and stored procedures in the target database to generate corresponding views and stored procedures in the target database.

[0109] In this embodiment, on the basis of establishing a connection between the system and the target database, the view and stored procedure statements of the source database are converted into a format compatible with the target database by using the established statement conversion relationship. Then, these converted statements are executed one by one in the target database, thereby generating corresponding views and stored procedures in the target database. In addition, during this process, the system monitors the execution status in real time and provides error reports and solution suggestions when errors are encountered.

[0110] In some embodiments, the method further comprises:

[0111] Comparing the behavior output of views and stored procedures in the source database and the target database;

[0112] If the behavior outputs are consistent, the migration is determined to be successful.

[0113] In this embodiment, after the migration of views and stored procedures is completed, the migration is verified. By comparing the behavior outputs of views and stored procedures in the source database and the target database, it is ensured that the migrated objects are functionally consistent with the source database. It can be understood that the essence of views and stored procedures is a series of instructions. By verifying whether the results presented by the instructions in the source database are consistent with the results presented by the views and stored procedures after migration in the target database, if they are consistent, it is determined that the behavior output is consistent, and then the output is successful, so that the consistency and integrity of the logical functions of the views and stored procedures after migration can be guaranteed.

[0114] The system in the embodiment of the present application supports the conversion of view syntax and stored procedure syntax between multiple databases, and supports the parsing of SQL syntax and data definition language (DDL) of different database systems. It supports converting the SQL statements of the source database system into SQL statements executable by the target database system according to the syntax rules of the target database system; it supports syntax verification: after syntax conversion, the generated SQL statements are verified to ensure their correctness and executableness in the target database system.

[0115] In the above embodiment, a heterogeneous database migration method is provided. After establishing a communication connection with the source database and the target database, the method automatically performs the steps of table structure migration, data migration, view and stored procedure migration, realizes the comprehensive migration of the database, and supports the migration between multiple domestic databases and non-domestic databases, improves the migration efficiency and is less prone to errors. The method includes: establishing a communication connection with the source database and the target database respectively; migrating the table structure of the source database to the target database; migrating the data of the source database to the target database; migrating the view and stored procedure of the source database to the target database.

[0116] Further, as Figure 1-4 The specific implementation of the method, the embodiment of the present application provides a migration device for heterogeneous databases, including:

[0117] A connection unit 501 is used to establish communication connections with a source database and a target database respectively;

[0118] A first migration unit 502 is used to migrate the table structure of the source database to the target database;

[0119] A second migration unit 503, configured to migrate the data of the source database to the target database;

[0120] The third migration unit 504 is used to migrate the views and stored procedures of the source database to the target database.

[0121] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0122] In a specific application scenario, the first migration unit includes:

[0123] A first acquisition unit, used to acquire table information of a source database;

[0124] A first determining unit, configured to determine a list of tables to be migrated from the table information, wherein the list of tables to be migrated includes at least one table to be migrated;

[0125] A parsing unit, used for parsing the table structure of the table to be migrated to obtain an entity class and a mapping file;

[0126] A first construction unit is used to map the entity class and the mapping file to a target database, and to construct a table structure mapping relationship between the source database and the target database;

[0127] The migration subunit is used to migrate the to-be-migrated tables in the to-be-migrated list to the target database according to the table structure mapping relationship.

[0128] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0129] In a specific application scenario, the second migration unit includes:

[0130] A second determining unit, configured to determine a data transfer method according to the table to be migrated;

[0131] A third determining unit, configured to determine a range of data to be migrated in the table to be migrated;

[0132] The writing unit is used to read data corresponding to the data range to be migrated from the source database by using the data transfer method, store the read data in a transfer container, and write the data in the transfer container into the target database.

[0133] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0134] In a specific application scenario, the second migration unit further includes:

[0135] A checking unit, used to check whether the data is successfully written into the target database;

[0136] A consistency checking unit, configured to perform a consistency check on the data in the source database and the data written into the target database if the writing is successful;

[0137] The deleting unit is used to delete the data in the transfer container if the verification is successful.

[0138] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0139] In a specific application scenario, the third migration unit includes:

[0140] The second acquisition unit is used to acquire views and stored procedures in the source database;

[0141] A second construction unit is used to construct statement conversion relationships corresponding to the view and the stored procedure respectively;

[0142] The execution unit is used to convert the views and stored procedures of the source database into a format compatible with the target database by using the statement conversion relationship; and execute the converted views and stored procedures in the target database to generate corresponding views and stored procedures in the target database.

[0143] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0144] In a specific application scenario, the second building unit includes:

[0145] A third acquisition unit is used to acquire a corresponding grammar file according to the type of the source database and the type of the target database;

[0146] A traversal unit is used to traverse the abstract syntax tree of the stored procedure in the source database using the visitor pattern generated by the syntax analyzer generator corresponding to the syntax file, and to construct an equivalent view and an equivalent stored procedure of the target database to obtain a view and stored procedure statement conversion relationship.

[0147] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0148] In specific application scenarios, the connection unit is specifically used for:

[0149] A communication connection with the source database is established using a standard database connection protocol according to preset configuration information of the source database.

[0150] It should be noted that for other corresponding descriptions of the functional units involved in the heterogeneous database migration device provided in this embodiment, reference can be made to Figure 1-4 The corresponding description in will not be repeated here.

[0151] Based on the above Figure 1-4 The method shown in the embodiment of the present application accordingly provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned Figure 1-4 The migration method of heterogeneous databases shown in FIG.

[0152] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.

[0153] Based on the above Figure 1-4 The method shown, and Figure 5 In order to achieve the above-mentioned purpose, the embodiment of the present application also provides a physical device based on the migration of heterogeneous databases, which can be a computer, a smart phone, a tablet computer, a smart watch, a server, or a network device, etc. The physical device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figure 1-4 The migration method based on heterogeneous database is shown.

[0154] Optionally, the physical device may also include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.

[0155] Those skilled in the art will appreciate that the electronic device structure provided in this embodiment does not limit the electronic device, and may include more or fewer components, or a combination of certain components, or different component arrangements.

[0156] The storage medium may also include an operating device and a network communication module. The operating device is a program that manages and saves the hardware and software resources of the electronic device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the various controls inside the storage medium, and the communication with other hardware and software in the physical device.

[0157] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform, or by hardware.

[0158] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the units or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the units in the devices in the implementation scenario can be distributed in the devices of the implementation scenario according to the description of the implementation scenario, or can be changed accordingly and located in one or more devices different from the present implementation scenario. The units of the above-mentioned implementation scenarios can be combined into one unit, or can be further split into multiple sub-units.

[0159] The above serial numbers of this application are only for description and do not represent the advantages and disadvantages of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of this application, but this application is not limited to them, and any changes that can be thought of by technicians in this field should fall within the scope of protection of this application.

Claims

1. A method for migrating a heterogeneous database, characterized in that: include: Establish communication connections with the source database and the target database respectively; Migrating the table structure of the source database to the target database; Migrating the data of the source database to the target database; Migrate the views and stored procedures of the source database to the target database.

2. The method according to claim 1, characterized in that The step of migrating the table structure of the source database to the target database includes: Get the table information of the source database; Determine a list of tables to be migrated from the table information, wherein the list of tables to be migrated includes at least one table to be migrated; Parsing the table structure of the table to be migrated to obtain entity classes and mapping files; Mapping the entity class and mapping file to the target database, and constructing a table structure mapping relationship between the source database and the target database; According to the table structure mapping relationship, the tables to be migrated in the to-be-migrated list are migrated to the target database.

3. The method according to claim 2, characterized in that The step of migrating the data of the source database to the target database includes: Determine a data transfer method according to the table to be migrated; Determine the range of data to be migrated in the table to be migrated; By using the data transfer method, data corresponding to the data range to be migrated is read from the source database, the read data is stored in a transfer container, and the data in the transfer container is written into the target database.

4. The method according to claim 3, characterized in that Also includes: Check whether the data is successfully written into the target database; If the writing is successful, a consistency check is performed on the data in the source database and the data written into the target database; If the verification is successful, the data in the transfer container is deleted.

5. The method according to claim 1, characterized in that The step of migrating the views and stored procedures of the source database to the target database includes: Get views and stored procedures in the source database; Constructing statement conversion relationships corresponding to the views and stored procedures respectively; The view and stored procedure of the source database are converted into a format compatible with the target database by using the statement conversion relationship; the converted view and stored procedure are executed in the target database to generate the corresponding view and stored procedure in the target database.

6. The method according to claim 5, characterized in that The step of constructing the statement conversion relationship corresponding to the view and the stored procedure includes: Obtain the corresponding syntax file according to the type of source database and target database; The visitor pattern generated by the syntax analyzer generator corresponding to the syntax file is used to traverse the abstract syntax tree of the stored procedure in the source database, and to construct equivalent views and equivalent stored procedures of the target database to obtain view and stored procedure statement conversion relationships.

7. The method according to claim 1, characterized in that The step of establishing a communication connection with the source data includes: A communication connection with the source database is established using a standard database connection protocol according to preset configuration information of the source database.

8. A heterogeneous database migration device, characterized in that: include: A connection unit, used to establish communication connections with a source database and a target database respectively; A first migration unit, configured to migrate the table structure of the source database to the target database; A second migration unit, configured to migrate the data of the source database to the target database; The third migration unit is used to migrate the views and stored procedures of the source database to the target database.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the heterogeneous database migration method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the heterogeneous database migration method described in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Heterogeneous database incremental data real-time migration method and related equipment

    CN113590588A

  • Data migration method and device for heterogeneous database and computer readable medium

    CN114281798A

  • Data migration method and device, electronic equipment and readable storage medium

    CN115858493A

  • Database migration method and device, equipment and storage medium

    CN116627928A

  • Migrating data between databases

    US10803031B1