Data migration methods, devices, equipment, media and products for heterogeneous databases
By acquiring and converting table structure description files, constructing the target database, and migrating test data, the high cost and low flexibility issues between heterogeneous databases are resolved. This achieves low-cost, highly versatile, and flexible test data migration, making it suitable for testing environments.
Patent Information
- Application Number
- CN202310736857.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-20
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2043-06-20
AI Technical Summary
In the fintech field, migrating test data between heterogeneous databases is costly, inflexible, and heavily reliant on commercial tools, failing to meet migration needs in testing environments.
By obtaining the table structure description file of the source database, converting it into the corresponding table structure description file of the target database, constructing the target database, and migrating the test data to the corresponding data tables, automated data migration between heterogeneous databases is achieved, avoiding reliance on commercial tools.
It achieves low-cost, highly versatile and flexible test data migration, allowing technicians to handle anomalies without vendor support and ensuring the accuracy of the migrated data.
Smart Images

Figure CN116719795B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular to a method, apparatus, device, medium and product for data migration of heterogeneous databases. Background Technology
[0002] In the fintech field, the development of financial software necessitates testing. Testing environments require substantial amounts of test data, and an increasing number of these environments involve data migration. While data migration between homogeneous databases can be achieved by exporting test data from the source database to a file and then importing that file into the target database, this method is not suitable for heterogeneous databases.
[0003] Related technologies generally use commercial or open-source tools to migrate data between heterogeneous databases. However, commercial tools are mostly expensive, and the data migration logic for both types of tools is encapsulated within the tools themselves. If abnormal problems occur during the migration process, technicians need to rely on the vendor's technical support to handle the problems, which is less flexible and not suitable for migration processes in test environments. Summary of the Invention
[0004] This application provides a method, apparatus, device, medium, and product for migrating heterogeneous databases. It does not rely on commercial tools but is implemented through simple migration logic, which is low-cost and highly versatile. If abnormal problems occur during the migration process, technicians can handle them in a timely manner without relying on the manufacturer, effectively reducing the impact of abnormal problems on migration time and efficiency. It is more flexible, suitable for test data migration in test environments, and also ensures the accuracy of the migrated test data.
[0005] Firstly, this application provides a data migration method for heterogeneous databases, including:
[0006] Obtain the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data.
[0007] The first table structure description file is converted into a second table structure description file corresponding to the target database, wherein the table structure of the source database is different from the table structure of the target database.
[0008] Based on the second table structure description file, the target database is constructed. The multiple first data tables in the source database correspond one-to-one with the multiple second data tables in the target database, and each second data table is an empty data table.
[0009] The test data included in each of the first data tables in the source database are migrated to the second data table corresponding to the first data table in the target database.
[0010] Optionally, migrating the test data included in each of the first data tables in the source database to the second data table corresponding to the first data table in the target database includes:
[0011] Connect the source database and the target database respectively;
[0012] The plurality of first data tables in the source database are traversed in a preset order;
[0013] For the first data table currently being traversed:
[0014] Construct a query statement corresponding to the first data table, and construct an insert statement corresponding to the second data table, wherein the second data table corresponds to the first data table;
[0015] By executing the query statement, the test data included in the first data table is read, and by executing the insert statement, the read test data is inserted into the second data table;
[0016] After inserting the test data included in the currently traversed first data table into the second data table, the next first data table is traversed in the preset order until the traversal of the plurality of first data tables is completed.
[0017] Optionally, constructing the query statement corresponding to the first data table includes:
[0018] Obtain a first correspondence configuration file, which includes the correspondence between the table name of each of the multiple data tables and the column names of multiple columns in each of the multiple data tables, wherein the data table is the first data table or the second data table;
[0019] From the first correspondence configuration file, determine the correspondence between the table name corresponding to the first data table currently being traversed and the column names of multiple columns in the first data table;
[0020] Based on the determined correspondence between the table name corresponding to the first data table and the column names of multiple columns in the first data table, construct the query statement corresponding to the first data table.
[0021] Optionally, constructing the insert statement corresponding to the second data table includes:
[0022] Obtain a second correspondence configuration file, which includes the correspondence between the plurality of first data tables and the plurality of second data tables;
[0023] From the second correspondence configuration file, determine the second data table corresponding to the first data table currently being traversed;
[0024] From the first correspondence configuration file, determine the correspondence between the table name corresponding to the second data table and the column names of multiple columns in the second data table;
[0025] Based on the correspondence between the determined table name of the second data table and the column names of multiple columns in the second data table, construct the insert statement corresponding to the second data table.
[0026] Optionally, after migrating the test data included in each of the first data tables in the source database to the second data table corresponding to the first data table in the target database, the method further includes:
[0027] If the source database has been updated, determine the first data table that has been updated;
[0028] If it is determined that the first data table with updated data is a newly added table, then in the second correspondence configuration file, the correspondence between the first data table with updated data and the second data table to be added is added;
[0029] In the first correspondence configuration file, add the correspondence between the table name of the first data table with updated data and the column names of multiple columns in the first data table with updated data, as well as the correspondence between the table name of the second data table to be added and the column names of multiple columns in the second data table to be added;
[0030] Create the second data table to be added in the target database;
[0031] The test data included in the first data table with existing data updates is migrated to the second data table to be added.
[0032] Optionally, the method further includes:
[0033] If it is determined that the first data table with updated data is not a newly added table, then the test data included in the first data table with updated data is migrated to the second data table corresponding to the first data table with updated data.
[0034] Optionally, the method further includes:
[0035] Every preset time interval, the latest data update log of the source database is obtained, and the data update log includes the data update time of the source database;
[0036] If the time interval between the data update time and the current time is determined to be less than the preset duration, then it is determined that the source database has been updated.
[0037] Optionally, the data update log further includes the table identifier corresponding to the first data table that has been updated, and the second correspondence configuration file includes the correspondence between the table identifier corresponding to the first data table and the table identifier corresponding to the second data table;
[0038] The method further includes:
[0039] If it is determined that the table identifier is not included in the second correspondence configuration file, then it is determined that the first data table with data updates is a newly added table;
[0040] If it is determined that the table identifier is included in the second correspondence configuration file, then it is determined that the first data table with updated data is not a newly added table.
[0041] Optionally, obtaining the first table structure description file corresponding to the source database includes:
[0042] Execute the server connection command using the command-line tool to connect to the source server corresponding to the source database;
[0043] The command-line tool is used to execute a table structure retrieval command to obtain the first table structure description file corresponding to the source database from the source server.
[0044] Optionally, converting the first table structure description file into a second table structure description file corresponding to the target database includes:
[0045] Using data modeling tools, the first table structure description file is converted into a second table structure description file corresponding to the target database.
[0046] Optionally, constructing the target database based on the second table structure description file includes:
[0047] Execute server connection commands using command-line tools to connect to the target server;
[0048] The database construction command is executed through the command-line tool to construct the target database based on the second table structure description file on the target server.
[0049] Secondly, this application provides a data migration apparatus for heterogeneous databases, comprising:
[0050] The acquisition module is used to acquire the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data.
[0051] The conversion module is used to convert the first table structure description file into a second table structure description file corresponding to the target database, wherein the table structure of the source database is different from the table structure of the target database.
[0052] The construction module is used to construct the target database based on the second table structure description file, wherein the plurality of first data tables in the source database correspond one-to-one with the plurality of second data tables in the target database, and each second data table is an empty data table;
[0053] The migration module is used to migrate the test data included in each of the first data tables in the source database to the second data table corresponding to the first data table in the target database.
[0054] Thirdly, this application provides an electronic device, including: a processor and a memory communicatively connected to the processor;
[0055] The memory stores computer-executed instructions;
[0056] The processor executes computer execution instructions stored in the memory to implement the data migration method for heterogeneous databases as described in any of the first aspects.
[0057] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the data migration method for heterogeneous databases as described in any one of the first aspects.
[0058] Fifthly, this application provides a computer program product, including computer execution instructions, which, when executed by a processor, implement the data migration method for heterogeneous databases as described in any of the first aspects.
[0059] The heterogeneous database data migration method, apparatus, device, medium, and product provided in this application offer an automated data migration solution between heterogeneous databases for testing environments. When there is a need to migrate test data between heterogeneous databases, since the table structures of the source and target databases are different, the solution first obtains the first table structure description file corresponding to the source database, then converts the first table structure description file into the second table structure description file corresponding to the target database, thus obtaining the necessary conditions for constructing the target database. The target database is then constructed based on the second table structure description file. At this point, the constructed target database is empty. By migrating the test data included in each of the first data tables in the source database to the corresponding second data tables in the target database, the data migration process between heterogeneous databases is completed. This data migration solution does not rely on commercial tools but is implemented through simple migration logic, resulting in low cost and high versatility. If abnormal problems occur during the migration process, technicians can handle them promptly without relying on the vendor, effectively reducing the impact of abnormal problems on migration time and efficiency. It offers greater flexibility, is suitable for test data migration in testing environments, and also ensures the accuracy of the migrated test data. Attached Figure Description
[0060] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0061] Figure 1 This is a schematic diagram illustrating an application scenario according to an exemplary embodiment;
[0062] Figure 2 This is a flowchart illustrating a data migration method for heterogeneous databases according to an exemplary embodiment;
[0063] Figure 3 This is a flowchart illustrating a data migration method for heterogeneous databases according to another exemplary embodiment;
[0064] Figure 4 This is a schematic diagram illustrating a data migration process according to an exemplary embodiment;
[0065] Figure 5 This is a flowchart illustrating a data migration method for heterogeneous databases according to another exemplary embodiment;
[0066] Figure 6 This is a schematic diagram illustrating the structure of a data migration device for a heterogeneous database according to an exemplary embodiment;
[0067] Figure 7 This is a schematic diagram of the structure of an electronic device according to an exemplary embodiment.
[0068] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0069] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0070] The terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. In the following descriptions of embodiments, "a plurality of" means two or more, unless otherwise explicitly defined.
[0071] The collection, storage, use, processing, transmission, provision, and disclosure of financial data or user data involved in the technical solution of this application all comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0072] To clearly understand the technical solution of this application, the solutions of the prior art will be described in detail first.
[0073] In the fintech field, the development of financial software necessitates testing, and the testing environment requires a large amount of test data. Test data refers to data generated by users in various ways to conduct functional or non-functional testing of financial software, or data obtained by anonymizing and declassifying production data. Production data refers to real business data stored in the production environment where services are officially provided. As the reliability, stability, product functionality, ease of use, and scalability of domestically developed distributed database products become increasingly sophisticated, more and more application systems in major domestic financial and banking sectors are choosing to replace their existing Oracle databases with domestically developed distributed databases during information system business restructuring, creating a need for database replacement. However, the test data in the source database is offline data, mostly generated by users in various ways to conduct testing, or data obtained by anonymizing and declassifying production data. For example, test data constructed by users based on the business and software design logic of the software under test. Data creation is time-consuming and logically complex. When a database needs to be changed, manually creating data in the target database is time-consuming and susceptible to various subjective and objective factors, leading to inconsistencies between the test data in the target database and the test data in the source database. Therefore, test data migration is necessary. Unlike data migration within homogeneous database products, increasingly more testing environments involve migrating test data between heterogeneous databases. In testing environments, migrating test data between homogeneous database products can be done by directly exporting the source database data to a file using tools and then importing the file into the target database. However, this method is not universally applicable between heterogeneous databases.
[0074] Once financial software is deployed to a production environment and officially launched as a service, a large amount of production data is generated. This production environment also presents a data migration requirement. The migration of production data has the following characteristics: First, it requires minimizing the impact on business service continuity during data migration, and the data migration tools or technologies must minimize interference with the production system. Second, it demands high accuracy and integrity of the migrated data, requiring a full verification of the correctness of the entire dataset after migration. Third, the data migration between massive heterogeneous database products in the production environment requires extremely high efficiency. Furthermore, some high-concurrency business systems will generate new business data during the migration process, necessitating high real-time requirements for migrating incremental data.
[0075] Based on the above characteristics, for production data migration between heterogeneous databases, mature and stable commercial data migration tools are generally used, such as DSG (a tool for data migration in production environments). Alternatively, some specific database product vendors can provide open-source data migration tools for specific source and target databases, such as Navicat (a database development and management tool) which can be used to migrate data from Oracle databases to MySQL databases.
[0076] Currently, for migrating test data between heterogeneous databases in a testing environment, traditional methods of rebuilding data are too cumbersome and inefficient. Commercial data migration tools are mostly expensive and complex to configure, while open-source data migration tools lack versatility and have a high error rate during the migration process, leading to a higher probability of migration failure. Furthermore, the migration logic of both of these tools is encapsulated within the tool itself; if anomalies occur during the migration process, technical personnel need to rely on vendor technical support to handle the issues, resulting in poor flexibility and making them unsuitable for migrating test data in a testing environment.
[0077] To address the lack of a suitable test data migration solution for testing scenarios in related technologies, the inventors discovered in their research that, in order to solve this problem, the logic for migrating test data between heterogeneous databases can be determined first, and then program code can be written according to this logic to obtain a relatively simple migration logic. By executing this migration logic, the automatic migration of test data can be achieved. Specifically, this application provides an automated data migration solution between heterogeneous databases for testing environments. When there is a need to migrate test data between heterogeneous databases, since the table structures of the source and target databases are different, the solution first obtains the first table structure description file corresponding to the source database, then converts the first table structure description file into the second table structure description file corresponding to the target database, thus obtaining the necessary conditions for building the target database. The target database is then built based on the second table structure description file. At this point, the built target database is empty. By migrating the test data included in each of the first data tables in the source database to the corresponding second data tables in the target database, the data migration process between heterogeneous databases is completed. It is evident that this data migration solution does not rely on commercial tools but is implemented through simple migration logic, resulting in low cost and high versatility. If abnormal problems occur during the migration process, technicians can handle them promptly without relying on vendors, effectively reducing the impact of abnormal problems on migration time and efficiency. It offers greater flexibility, is suitable for test data migration in testing environments, and also ensures the accuracy of the migrated test data.
[0078] The following describes the application scenarios of the data migration method for heterogeneous databases provided in the embodiments of this application.
[0079] Figure 1 This is a schematic diagram illustrating an application scenario according to an exemplary embodiment. For example... Figure 1 As shown, this application scenario includes: electronic device 1. Electronic device 1 is a device used by the user. In this embodiment, the source database and the target database can be deployed on the local end, i.e., on the electronic device side, or they can be deployed on the server side.
[0080] In some embodiments, when the source database and the target database are deployed on the local end, when there is a need to migrate test data between heterogeneous databases, the electronic device 1 obtains the first table structure description file corresponding to the source database, then converts the first table structure description file into the second table structure description file corresponding to the target database, constructs the target database based on the second table structure description file, and migrates the test data included in each first data table in the source database to the second data table corresponding to the first data table in the target database, thereby realizing an automated test data migration process.
[0081] In other embodiments, where the source and target databases are deployed on the server side, the application scenario also includes a source server and a target server, where the source server is the server corresponding to the source database and the target server is the server corresponding to the target database. When there is a need to migrate test data between heterogeneous databases, electronic device 1 sends a request to the source server. In response to the request, the source server returns a first table structure description file corresponding to the source database. Electronic device 1 then converts the first table structure description file into a second table structure description file corresponding to the target database and sends a build request to the target server. This allows the target server to build the target database based on the second table structure description file. The test data included in each first data table in the source database is then obtained from the source server. Finally, the obtained test data is migrated to the second data table corresponding to the first data table in the target database through the target server, thereby realizing an automated test data migration process.
[0082] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0083] Figure 2 This is a flowchart illustrating a data migration method for heterogeneous databases according to an exemplary embodiment. The execution entity of the data migration method for heterogeneous databases provided in this embodiment is a data migration device for heterogeneous databases, which is integrated into an electronic device. For example... Figure 2As shown, the data migration method for heterogeneous databases provided in this embodiment includes the following steps:
[0084] Step S101: Obtain the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data.
[0085] In this context, the source database refers to the database from which data is migrated during the data migration process. This embodiment does not limit the type of the source database; for example, it can be a MySQL database, an Oracle database, or other types of databases. The first table structure description file describes the table structure corresponding to the first data table in the source database. The first data table consists of three parts: the table name, the columns in the table, and the records in the table. Designing the table structure involves defining the table name, determining which columns the table contains, the column names, column types, and widths, etc. Optionally, the first table structure description file includes the table name, column names, column data types, whether they are nullable, whether they are primary keys or unique keys, default values, and additional information. It should be noted that if the source database stores multiple first data tables, and each first data table has its own corresponding first table structure description file, then the number of first table structure description files corresponding to the source database obtained in this step is multiple.
[0086] In this embodiment, when there is a need to migrate test data, a target database is first built, and then the test data in the source database is migrated to the target database. Building the target database requires a corresponding table structure description file. Accordingly, the electronic device executes step S102.
[0087] Step S102: Convert the first table structure description file into the second table structure description file corresponding to the target database. The table structure of the source database is different from the table structure of the target database.
[0088] In this embodiment, the target database refers to the database into which data is migrated during the data migration process. Since the table structures of the source database and the target database are different, and the test data to be stored in the target database is the same test data currently stored in the source database, the first table structure description file can be converted into a second table structure description file corresponding to the target database. The second table structure description file describes the table structure of the second data table in the target database. The second data table is the data table in the target database corresponding to the first data table. Optionally, the second table structure description file includes the table name, column names, column data types, nullability, primary key or unique key, default value, and additional information of the second data table. Optionally, both the first and second table structure description files are SQL script files.
[0089] Step S103: Based on the second table structure description file, construct the target database. The multiple first data tables in the source database correspond one-to-one with the multiple second data tables in the target database, and each second data table is an empty data table.
[0090] In this embodiment, the constructed target database includes multiple second data tables. The first data table corresponds one-to-one with the second data table, and the second data table is an empty data table, that is, the second data table does not contain test data.
[0091] Step S104: Migrate the test data included in each first data table in the source database to the second data table corresponding to the first data table in the target database.
[0092] In this embodiment, when there is a need to migrate test data between heterogeneous databases, since the table structures of the source database and the target database are different, the necessary conditions for building the target database are obtained by first obtaining the first table structure description file corresponding to the source database and then converting the first table structure description file into the second table structure description file corresponding to the target database. Then, the target database is built based on the second table structure description file. At this time, the built target database is empty. By migrating the test data included in each first data table in the source database to the corresponding second data table in the target database, the data migration process between heterogeneous databases is completed. It can be seen that this application provides an automated data migration solution between heterogeneous databases for the test environment. This data migration solution does not rely on commercial tools, but is implemented through simple migration logic, which is lower in cost and more universal. If abnormal problems occur during the migration process, technicians can handle them in a timely manner without relying on the vendor, effectively reducing the impact of abnormal problems on migration time and migration efficiency. It is more flexible, suitable for test data migration in the test environment, and also ensures the accuracy of the migrated test data.
[0093] Based on the data migration method for heterogeneous databases provided in the previous embodiment of this application, the following detailed description of each step is provided. Figure 3 This is a flowchart illustrating a data migration method for heterogeneous databases according to another exemplary embodiment. The execution entity of the data migration method for heterogeneous databases provided in this embodiment is a data migration device for heterogeneous databases, which is integrated into an electronic device. For example... Figure 3 As shown, the method includes the following steps:
[0094] Step S201: Obtain the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data.
[0095] In one optional embodiment, step S201 is implemented by: executing a server connection command through a command-line tool to connect to the source server corresponding to the source database; and executing a table structure retrieval command through a command-line tool to retrieve the first table structure description file corresponding to the source database from the source server.
[0096] In this context, the command-line tool refers to a tool that performs a corresponding function by executing the input command line. The server connection command is used to connect to the device to which the corresponding source database belongs. This device can be the source server corresponding to the source database or an electronic device; in other words, the source database can be deployed on the source server or on the electronic device itself. If the source database is deployed on the source server, the server connection command is used to connect to that source server, which means logging into the source server. The server connection command includes information such as login account, password, server name, and database name. If the source database is deployed locally, the server name in the server connection command can be "local". The table structure retrieval command is used to retrieve the corresponding table structure description file. Specifically, in the above implementation, the table structure retrieval command is used to retrieve the first table structure description file. In this embodiment, the user triggers the electronic device to display the operation interface corresponding to the command-line tool. Then, the user inputs the server connection command in this operation interface, and the electronic device retrieves and executes the input server connection command. Then, the user continues to input the table structure retrieval command in this operation interface, and the electronic device retrieves and executes the input table structure retrieval command to obtain the first table structure description file corresponding to the source database. For example, assuming the source database is an Oracle database and the target database is a MySQL database, the command to retrieve the table structure can be:
[0097] exp user / password@dbServerName file=filepath\Oracle_to_MySQL.sql, owner=user;
[0098] In this command, exp is the export command, user is the username, password is the password, dbServerName is the database service name, filepath is the file storage path, and Oracle_to_MySQL.sql is the filename. This command retrieves the table structure description file corresponding to the username and exports it to the file storage path.
[0099] In this embodiment, the server connection command and table structure retrieval command are executed sequentially using the command-line tool built into the electronic device's operating system, thereby obtaining the first table structure description file corresponding to the source database. No additional tools need to be installed, saving the electronic device's computing resources and storage space, and the operation is relatively simple.
[0100] In some embodiments, the implementation of step S201 is the same as that of step S101 described above, and will not be repeated here.
[0101] Step S202: Convert the first table structure description file into the second table structure description file corresponding to the target database. The table structure of the source database is different from the table structure of the target database.
[0102] Optionally, step S202 can be implemented by converting the first table structure description file into a second table structure description file corresponding to the target database using a data modeling tool. The data modeling tool can be selected as needed, and this embodiment does not limit its use. For example, the data modeling tool could be PowerDesigner.
[0103] Taking an Oracle database as the source database and a MySQL database as the target database as an example, the user triggers the PowerDesigner tool's interface on the electronic device. This interface includes a "File" option. Triggering the "File" option displays a list of options, including a "Reverse Engineering" option and other options such as "Open" and "Save." Triggering the "Reverse Engineering" option displays a list of options, including a "Database" option. Triggering the "Database" option displays a pop-up window, which is a "New Physical Data Model" window. The user enters the source database version "ORACLE Version" in the "Current Database Management System" input box. Then, click the "Add Files" button in the pop-up window, select the first table structure description file corresponding to the Oracle database, and click the "OK" button to trigger the electronic device to display the operation interface. In addition to the "File" option mentioned above, the operation interface also includes a "Database" option. When the user triggers the "Database" option, the electronic device will display the corresponding option list. This option list includes the "Change Current DBMS" option. When the user triggers the "Change Current DBMS" option, the electronic device will display the corresponding pop-up window, which is the "Change DBMS" window. In the New database field, select the target database version "MySQL 5.0" and in the Current database field, select the source database version "ORACLE Version 11g". Then click the "OK" button to trigger the electronic device to display the PowerDesigner information pop-up window. This pop-up window displays the message "The DBMS has been changed" and an "OK" button. When the user clicks the "OK" button, the electronic device will cancel the pop-up window. The above process converts the first table structure description file into the second table structure description file corresponding to the target database.
[0104] In this embodiment, the conversion of table structure description files is achieved by using existing data modeling tools in related technologies, which makes it easy for users to get started and the operation is relatively simple. Only the corresponding parameters need to be input, and the conversion efficiency is high.
[0105] Optionally, the user triggers the electronic device to export the converted second table structure description file to the local machine for local storage. For example, the exported second table structure description file is named "mySQLDB.sql". Optionally, after exporting, the second table structure description file is manually checked. Specifically, the user determines whether there are any errors in the second table structure description file, and if errors are found, appropriate adjustments can be made.
[0106] For example, the first data table is the student table. The first table structure description file corresponding to the first data table includes the table name "create table STUDENT", the column name "student ID (SNO)" and the corresponding data type "NUMBER(16)" and primary key, the column name "student name (SNAME)" and the corresponding data type "varchar(32)" and not null, the column name "gender (SSEX)" and the corresponding data type "char(2)" and check constraint hint "check(SSEX='male' or SSEX='female')", the column name "age (SAGE)" and the corresponding data type "NUMBER(3)" and default null flag "default NULL", and the column name "college (SDEPT)" and the corresponding data type "varchar(40)" and default null flag "default NULL".
[0107] For example, the converted second table structure description file includes the table name "create tableSTUDENT", the column name "student ID (SNO)" and its corresponding data type "bigint(16)" and primary key marker (primarykey), the column name "student name (SNAME)" and its corresponding data type "varchar(32)" and not null marker (not null), the column name "gender (SSEX)" and its corresponding data type "char(2)" and check constraint hint "check(SSEX='male' or SSEX='female')", the column name "age (SAGE)" and its corresponding data type "int(3)" and default null marker "defaultNULL", and the column name "college (SDEPT)" and its corresponding data type "varchar(40)" and default null marker "defaultNULL".
[0108] In some embodiments, step S202 is implemented as described in step S102 above, and will not be repeated here.
[0109] Step S203: Based on the second table structure description file, construct the target database. The multiple first data tables in the source database correspond one-to-one with the multiple second data tables in the target database, and each second data table is an empty data table.
[0110] Optionally, step S203 can be implemented by: executing a server connection command via a command-line tool to connect to the target server; and executing a database construction command via a command-line tool to construct the target database based on the second table structure description file on the target server.
[0111] In this implementation, the server connection command is used to connect to the device to which the target database belongs. Optionally, this device can be the target server corresponding to the target database, or it can be an electronic device. In other words, the target database can be deployed on the target server or on the local device. If the target database is deployed on the target server, the server connection command is used to connect to that target server; connecting to the target server means logging into it. After connecting to the target server, the target database is built through the target server. The server connection command includes information such as the login account, password, server name, and database name. If the target database is deployed locally, the server name in the server connection command can be "local". For example, the database build command is "source / filepath / mySQLDB.sql", where source is the file source, filepath is the file storage path of the second table structure description file, and mySQLDB.sql is the second table structure description file.
[0112] In this embodiment, the target database is constructed by sequentially executing the server connection command and the database construction command through the command line tool built into the operating system of the electronic device. Since the target database is constructed on the server, the computing resources and storage space of the electronic device are saved, and the operation is relatively simple.
[0113] In this embodiment, the constructed target database includes multiple second data tables. Each first data table corresponds one-to-one with a second data table, and the second data tables are empty, meaning they do not contain test data. Accordingly, the electronic device migrates the test data contained in each of the first data tables in the source database to the corresponding second data tables in the target database.
[0114] Optionally, the electronic device performs steps S204-S208 to migrate the test data included in each first data table in the source database to the second data table corresponding to the first data table in the target database. This can be implemented using Python (a computer programming language).
[0115] Step S204: Connect the source database and the target database respectively.
[0116] Optionally, the electronic device obtains a connection information configuration file and connects to the source database and target database respectively according to the configuration file. This connection information configuration file includes first connection information for the source database and second connection information for the target database. For example, taking an Oracle database as the source database and a MySQL database as the target database, the first connection information includes the source server's IP address (ip), port (port), username (user), password (pwd), and database service name (sid), while the second connection information includes the target server's IP address (host), port (port), username (user), password (password), database service name (db), and character set identifier (charset). Optionally, the user pre-configures the connection information configuration file using the electronic device, which then stores this configuration file and retrieves it when a connection is needed.
[0117] Step S205: Traverse multiple first data tables in the source database in a preset order.
[0118] The preset order can be set as needed, and this embodiment does not limit it. For example, the preset order could be the creation time of the first data table from oldest to newest, the update time of the first data table from oldest to newest, or the first letter of the table name of the first data table in ascending order. In this embodiment, for the first data table currently being traversed, steps S206-S207 are executed sequentially to migrate the test data.
[0119] Step S206: For the first data table currently being traversed, construct the query statement corresponding to the first data table and construct the insert statement corresponding to the second data table, with the second data table corresponding to the first data table.
[0120] In this step, the first data table refers to the first data table currently being traversed. Optionally, the implementation of constructing the query statement corresponding to the first data table includes: obtaining a first correspondence configuration file, which includes the correspondence between the table names of multiple data tables and the column names of multiple columns in each data table; determining the correspondence between the table name of the currently traversed first data table and the column names of multiple columns in the first data table from the first correspondence configuration file; and constructing the query statement corresponding to the first data table according to the determined correspondence between the table name of the first data table and the column names of multiple columns in the first data table. The user pre-configures the first correspondence configuration file through an electronic device, which then stores the configuration file. When there is a need to construct a query statement, the first correspondence configuration file is retrieved.
[0121] In this embodiment, by constructing a query statement corresponding to the first data table that is currently being traversed, the dynamic construction of the query statement is realized, which makes the query statement more adaptable and more real-time.
[0122] Based on the above optional implementation methods, optionally, the implementation method for constructing the insert statement corresponding to the second data table includes: obtaining a second correspondence configuration file, which includes correspondences between multiple first data tables and multiple second data tables; determining the second data table corresponding to the currently traversed first data table from the second correspondence configuration file; determining the correspondence between the table name corresponding to the second data table and the column names of multiple columns in the second data table from the first correspondence configuration file; and constructing the insert statement corresponding to the second data table according to the determined correspondences between the table name corresponding to the second data table and the column names of multiple columns in the second data table. The user pre-configures the second correspondence configuration file via an electronic device, which then stores the configuration file. When there is a need to construct an insert statement, the second correspondence configuration file is retrieved. Optionally, the second correspondence configuration file includes the correspondence between the table identifier corresponding to the first data table and the table identifier corresponding to the second data table. The table identifier can be the table name.
[0123] In this embodiment, by constructing an insertion statement for the first data table that is currently being traversed, which corresponds to a second data table, and the second data table is the data table for which test data is to be inserted, the dynamic construction of the insertion statement is realized, which makes the insertion statement more adaptable and more real-time.
[0124] Step S207: For the first data table currently being traversed, the test data included in the first data table is read by executing a query statement, and the read test data is inserted into the second data table by executing an insert statement.
[0125] After constructing the query and insert statements, the query and insert statements are executed sequentially to migrate the data from the first data table to the second data table.
[0126] It should be noted that steps S206-S207 are illustrated by first dynamically constructing the query statement corresponding to the first data table and the insert statement corresponding to the second data table for the currently traversed first data table, and then migrating the test data. In other embodiments, the electronic device may first construct corresponding query statements for multiple first data tables in the source database, and then construct corresponding insert statements for multiple second data tables in the target database. When traversing to a first data table, the electronic device obtains the query statement corresponding to the first data table, executes the query statement, and then obtains and executes the insert statement corresponding to the second data table.
[0127] Step S208: After inserting the test data included in the currently traversed first data table into the second data table, the next first data table is traversed in a preset order until the traversal of multiple first data tables is completed.
[0128] In this embodiment, the test data is migrated in each of the first data tables that are traversed in accordance with the implementation method of steps S206-S207 above. This will not be repeated here.
[0129] This embodiment uses a traversal approach to automatically migrate the test data from each first data table to the corresponding second data table in sequence, which is more versatile. Furthermore, during the migration process, query and insert statements are dynamically constructed, which provides greater flexibility.
[0130] For example, Figure 4 This is a schematic diagram illustrating a data migration process according to an exemplary embodiment, such as... Figure 4 As shown, the data migration process includes the following steps:
[0131] Step S301: Connect the source database and the target database respectively.
[0132] Step S302: Traverse multiple first data tables in the source database.
[0133] Step S303: Determine if the traversal has ended.
[0134] If the traversal is complete, the data migration process ends; otherwise, step S304 is executed.
[0135] Step S304: Read the test data from the first data table.
[0136] Step S305: Determine whether the test data in the first data table has been read completely.
[0137] If the reading is complete, proceed to step S302; if the reading is not complete, proceed to step S306.
[0138] Step S306: Insert the read test data into the target database.
[0139] After step S306, continue with step S304.
[0140] In some embodiments, the implementation of steps S301-S306 is the same as in the above embodiments, and will not be repeated here.
[0141] The above embodiment uses the migration of all test data from the source database to the target database as an example. After the migration, incremental data may be generated in the source database. Accordingly, the migration process of incremental data is described below.
[0142] Figure 5 This is a flowchart illustrating a data migration method for heterogeneous databases according to another exemplary embodiment. The data migration method provided in this embodiment is executed after migrating the test data included in each first data table in the source database to the second data table corresponding to the first data table in the target database. Furthermore, the executing entity of the data migration method provided in this embodiment is a heterogeneous database data migration device, which is integrated into an electronic device. Figure 5 As shown, the method includes the following steps:
[0143] Step S401: If there is data update in the source database, determine the first data table that has been updated.
[0144] If the source database has data updates, it indicates that one or more first data tables in the source database have been updated. In this embodiment, it is first determined whether the source database has data updates. If the source database has data updates, step S401 is executed. Optionally, determining whether the source database has data updates includes: obtaining the latest data update log of the source database every preset time interval, the data update log including the data update time of the source database; if the time interval between the data update time and the current time is less than the preset time interval, it is determined that the source database has data updates. The preset time interval can be set as needed, and this embodiment does not limit it, for example, the preset time interval is 1 hour, 1 day, or 7 days, etc.
[0145] In this embodiment, since the source database generates a corresponding data update log after each update, and this data update log records the data update time, it can be determined whether the time interval between the data update time and the current time is less than a preset duration. If it is determined that the time interval between the data update time and the current time is less than the preset duration, it means that the source database has undergone a data update within the time interval between the current acquisition and the previous acquisition. If it is determined that the time interval between the data update time and the current time is greater than or equal to the preset duration, it means that the source database has not undergone a data update within the time interval between the current acquisition and the previous acquisition, and the data update log obtained this time is the same as the data update log obtained last time. This method of determining whether the source database has undergone a data update is relatively accurate.
[0146] Step S402: Determine whether the first data table with updated data is a newly added table.
[0147] In this embodiment, when there is a data update in the source database, the first data table with the updated data is first determined from the multiple first data tables stored in the source database, and then it is determined whether the first data table is a newly added table. If it is determined that the first data table with the updated data is a newly added table, then steps S403-S406 are executed; if it is determined that the first data table with the updated data is not a newly added table, then step S407 is executed.
[0148] Optionally, the data update log also includes the table identifier corresponding to the first data table that has been updated, and the second correspondence configuration file includes the correspondence between the table identifiers corresponding to the first data table and the table identifiers corresponding to the second data table; accordingly, the implementation method for determining the first data table that has been updated from the multiple first data tables stored in the source database includes: if it is determined that the second correspondence configuration file does not include a table identifier, then it is determined that the first data table that has been updated is a newly added table; if it is determined that the second correspondence configuration file includes a table identifier, then it is determined that the first data table that has been updated is not a newly added table.
[0149] In this embodiment, since the second correspondence configuration file includes the correspondence between the first data table and the second data table in the source database before the data update, it is possible to determine whether the first data table with data update is a newly added table by judging whether the second correspondence configuration file includes the table identifier corresponding to the first data table with data update. This method is simple, easy to implement, and highly efficient.
[0150] Step S403: In the second correspondence configuration file, add the correspondence between the first data table with existing data updates and the second data table to be added.
[0151] Step S404: In the first correspondence configuration file, add the correspondence between the table name of the first data table that has been updated and the column names of multiple columns in the first data table that has been updated, as well as the correspondence between the table name of the second data table to be added and the column names of multiple columns in the second data table to be added.
[0152] Step S405: Create the second data table to be added in the target database.
[0153] In some embodiments, the implementation of this step can refer to the implementation of creating a new data table in the database in related technologies, and will not be repeated here.
[0154] Step S406: Migrate the test data included in the first data table that has been updated to the second data table to be added.
[0155] This embodiment provides a migration scheme for incremental test data in cases where the source database has been updated. By updating the first and second correspondence configuration files, data support is provided for data migration. By migrating incremental test data, the accuracy of the test data stored in the target database is ensured.
[0156] Step S407: Migrate the test data included in the first data table that has been updated to the second data table corresponding to the first data table that has been updated.
[0157] In this embodiment, if it is determined that the first data table with updated data is not a newly added table, the test data in the first data table is directly migrated to the second data table, thus achieving timely data updates and higher real-time performance.
[0158] In some embodiments, the implementation of steps S406 and S407 is the same as that of steps S206-S207 described above, and will not be repeated here.
[0159] Figure 6 This is a schematic diagram illustrating the structure of a data migration device for heterogeneous databases according to an exemplary embodiment, such as... Figure 6 As shown, in this embodiment, the heterogeneous database data migration device 500 can be installed in an electronic device, and the heterogeneous database data migration device 500 includes:
[0160] The acquisition module 501 is used to acquire the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data.
[0161] The conversion module 502 is used to convert the first table structure description file into the second table structure description file corresponding to the target database. The table structure of the source database is different from the table structure of the target database.
[0162] The construction module 503 is used to construct the target database based on the second table structure description file. Multiple first data tables in the source database correspond one-to-one with multiple second data tables in the target database, and each second data table is an empty data table.
[0163] The migration module 504 is used to migrate the test data included in each first data table in the source database to the second data table corresponding to the first data table in the target database.
[0164] Optionally, migration module 504 is specifically used for:
[0165] Connect to the source database and the target database respectively;
[0166] According to the preset order, traverse multiple first data tables in the source database;
[0167] For the first data table currently being traversed:
[0168] Construct the query statement corresponding to the first data table, and construct the insert statement corresponding to the second data table, which corresponds to the first data table;
[0169] By executing a query statement, the test data included in the first data table is read, and by executing an insert statement, the read test data is inserted into the second data table;
[0170] After inserting the test data included in the first data table into the second data table, the next first data table is traversed in a preset order until the traversal of multiple first data tables is completed.
[0171] Optionally, migration module 504 is specifically used for:
[0172] Obtain the first correspondence configuration file, which includes the correspondence between the table name and the column names of multiple columns in each of the multiple data tables. The data tables are either the first data table or the second data table.
[0173] From the first correspondence configuration file, determine the correspondence between the table name corresponding to the first data table currently being traversed and the column names of multiple columns in the first data table;
[0174] Based on the correspondence between the table name of the first data table and the column names of multiple columns in the first data table, construct the query statement corresponding to the first data table.
[0175] Optionally, migration module 504 is specifically used for:
[0176] Obtain the second mapping configuration file, which includes the mapping relationships between multiple first data tables and multiple second data tables;
[0177] From the second correspondence configuration file, determine the second data table corresponding to the first data table currently being traversed;
[0178] From the first correspondence configuration file, determine the correspondence between the table name corresponding to the second data table and the column names of multiple columns in the second data table;
[0179] Based on the correspondence between the determined table name of the second data table and the column names of multiple columns in the second data table, construct the corresponding insert statement for the second data table.
[0180] Optionally, the device 500 further includes an update module, which is used for:
[0181] If data has been updated in the source database, determine the first data table that has been updated;
[0182] If it is determined that the first data table with updated data is a newly added table, then in the second correspondence configuration file, add the correspondence between the first data table with updated data and the second data table to be added;
[0183] In the first correspondence configuration file, add the correspondence between the table name of the first data table that has been updated and the column names of multiple columns in the first data table that has been updated, as well as the correspondence between the table name of the second data table to be added and the column names of multiple columns in the second data table to be added.
[0184] Create the second data table to be added in the target database;
[0185] Migrate the test data included in the first data table that has been updated to the second data table that is to be added.
[0186] Optionally, the update module is also used for:
[0187] If it is determined that the first data table with updated data is not a newly added table, then the test data included in the first data table with updated data will be migrated to the second data table corresponding to the first data table with updated data.
[0188] Optionally, the update module is also used for:
[0189] At preset intervals, retrieve the latest data update log from the source database. The data update log includes the data update time from the source database.
[0190] If the time interval between the data update time and the current time is less than the preset duration, then it is determined that there is a data update in the source database.
[0191] Optionally, the data update log also includes the table identifier corresponding to the first data table where data updates have occurred, and the second correspondence configuration file includes the correspondence between the table identifier corresponding to the first data table and the table identifier corresponding to the second data table.
[0192] The update module is also used for:
[0193] If it is determined that the second correspondence configuration file does not include a table identifier, then the first data table with data updates is determined to be a newly added table.
[0194] If the second correspondence configuration file is found to include a table identifier, then the first data table with updated data is determined not to be a newly added table.
[0195] Optionally, module 501 is used specifically for:
[0196] Execute the server connection command using the command-line tool to connect to the source server corresponding to the source database;
[0197] The command-line tool is used to execute the table structure retrieval command to obtain the first table structure description file corresponding to the source database from the source server.
[0198] Optionally, the conversion module 502 is specifically used for:
[0199] Using data modeling tools, the first table structure description file is converted into the second table structure description file corresponding to the target database.
[0200] Optionally, module 503 is constructed specifically for:
[0201] Execute server connection commands using command-line tools to connect to the target server;
[0202] Execute the database build command using the command-line tool to build the target database based on the second table structure description file on the target server.
[0203] The data migration device for heterogeneous databases provided in this embodiment can execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar to those of the above method embodiments, and will not be described in detail here.
[0204] This application also provides an electronic device. The electronic device can be a computer, a laptop, a tablet, or a personal digital assistant, wherein the computer can be a laptop computer, a desktop computer, a workbench, a mainframe computer, or other suitable computer.
[0205] Figure 7 This is a schematic diagram illustrating the structure of an electronic device according to an exemplary embodiment. For example... Figure 7 As shown, the electronic device 600 includes a processor 601 and a memory 602 communicatively connected to the processor 601.
[0206] The memory 602 stores computer-executable instructions; the processor 601 executes the computer-executable instructions stored in the memory 602 to implement the data migration method for heterogeneous databases provided in this application.
[0207] In this embodiment, the memory 602 and the processor 601 are connected via a bus. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one thick line is used in the figure, but this does not indicate that there is only one bus or one type of bus.
[0208] The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein. The various components are interconnected via different buses and can be mounted on a common motherboard or otherwise as required.
[0209] In an exemplary embodiment, a computer-readable storage medium is also provided, which stores computer-executable instructions that, when executed by a processor, are used to implement the data migration method for heterogeneous databases provided in this application.
[0210] In an exemplary embodiment, a computer program product is also provided, including computer execution instructions, which, when executed by a processor, are used to implement the data migration method for heterogeneous databases provided in this application.
[0211] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.
[0212] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0213] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.
[0214] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.
[0215] When an integrated unit / module is implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a Central Processing Unit (CPU), Graphics Processing Unit (GPU), Application Specific Integrated Circuit (ASIC), Digital Signal Processor (DSP), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), controller, microcontroller, microprocessor, or other electronic component. Unless otherwise specified, memory can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as USB flash drives, random-access memory (RAM), static random-access memory (SRAM), dynamic random-access memory (DRAM), enhanced dynamic random-access memory (EDRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), resistive random access memory (RRAM), high-bandwidth memory (HBM), and hybrid memory cube (HMC). Cube, magnetic storage, flash storage, disk, optical disk, portable hard drive or magnetic disk, and other media that can store program code.
[0216] If the integrated unit / module is implemented as a software program module and sold or used as an independent product, it can be stored in a computer-readable storage device. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application.
[0217] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.
[0218] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0219] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A data migration method for heterogeneous databases, characterized in that, include: Obtain the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data. The first table structure description file is converted into a second table structure description file corresponding to the target database, wherein the table structure of the source database is different from the table structure of the target database. Based on the second table structure description file, the target database is constructed. The multiple first data tables in the source database correspond one-to-one with the multiple second data tables in the target database, and each second data table is an empty data table. Connect to the source database and the target database respectively according to the connection information configuration file; The connection information configuration file includes first connection information corresponding to the source database and second connection information corresponding to the target database; The plurality of first data tables in the source database are traversed in a preset order. For the first data table currently being traversed: Construct a query statement corresponding to the first data table, and construct an insert statement corresponding to the second data table, wherein the second data table corresponds to the first data table; By executing the query statement, the test data included in the first data table is read, and by executing the insert statement, the read test data is inserted into the second data table; After inserting the test data included in the first data table that is currently being traversed into the second data table, the next first data table is traversed in the preset order until the traversal of the plurality of first data tables is completed. The construction of the query statement corresponding to the first data table includes: Obtain a first correspondence configuration file, which includes the correspondence between the table name of each of the multiple data tables and the column names of multiple columns in each of the multiple data tables, wherein the data table is the first data table or the second data table; From the first correspondence configuration file, determine the correspondence between the table name corresponding to the first data table currently being traversed and the column names of multiple columns in the first data table; Based on the determined correspondence between the table name corresponding to the first data table and the column names of multiple columns in the first data table, construct the query statement corresponding to the first data table. The construction of the insertion statement corresponding to the second data table includes: Obtain a second correspondence configuration file, which includes the correspondence between the plurality of first data tables and the plurality of second data tables; From the second correspondence configuration file, determine the second data table corresponding to the first data table currently being traversed; From the first correspondence configuration file, determine the correspondence between the table name corresponding to the second data table and the column names of multiple columns in the second data table; Based on the correspondence between the determined table name of the second data table and the column names of multiple columns in the second data table, construct the insert statement corresponding to the second data table.
2. The method according to claim 1, characterized in that, After migrating the test data included in each of the first data tables in the source database to the second data table corresponding to the first data table in the target database, the method further includes: If the source database has been updated, determine the first data table that has been updated; If it is determined that the first data table with updated data is a newly added table, then in the second correspondence configuration file, the correspondence between the first data table with updated data and the second data table to be added is added; In the first correspondence configuration file, add the correspondence between the table name of the first data table with updated data and the column names of multiple columns in the first data table with updated data, as well as the correspondence between the table name of the second data table to be added and the column names of multiple columns in the second data table to be added; Create the second data table to be added in the target database; The test data included in the first data table with existing data updates is migrated to the second data table to be added.
3. The method according to claim 2, characterized in that, The method further includes: If it is determined that the first data table with updated data is not a newly added table, then the test data included in the first data table with updated data is migrated to the second data table corresponding to the first data table with updated data.
4. The method according to claim 2, characterized in that, The method further includes: Every preset time interval, the latest data update log of the source database is obtained, and the data update log includes the data update time of the source database; If the time interval between the data update time and the current time is determined to be less than the preset duration, then it is determined that the source database has been updated.
5. The method according to claim 4, characterized in that, The data update log also includes the table identifier corresponding to the first data table that has been updated, and the second correspondence configuration file includes the correspondence between the table identifier corresponding to the first data table and the table identifier corresponding to the second data table; The method further includes: If it is determined that the table identifier is not included in the second correspondence configuration file, then it is determined that the first data table with data updates is a newly added table; If it is determined that the table identifier is included in the second correspondence configuration file, then it is determined that the first data table with updated data is not a newly added table.
6. The method according to any one of claims 1-5, characterized in that, The step of obtaining the first table structure description file corresponding to the source database includes: Execute the server connection command using the command-line tool to connect to the source server corresponding to the source database; The command-line tool is used to execute a table structure retrieval command to obtain the first table structure description file corresponding to the source database from the source server.
7. The method according to any one of claims 1-5, characterized in that, The step of converting the first table structure description file into a second table structure description file corresponding to the target database includes: Using data modeling tools, the first table structure description file is converted into a second table structure description file corresponding to the target database.
8. The method according to any one of claims 1-5, characterized in that, The construction of the target database based on the second table structure description file includes: Execute server connection commands using command-line tools to connect to the target server; The database construction command is executed through the command-line tool to construct the target database based on the second table structure description file on the target server.
9. A data migration device for heterogeneous databases, characterized in that, include: The acquisition module is used to acquire the first table structure description file corresponding to the source database. The source database stores multiple first data tables, and each first data table includes multiple test data. The conversion module is used to convert the first table structure description file into a second table structure description file corresponding to the target database, wherein the table structure of the source database is different from the table structure of the target database. The construction module is used to construct the target database based on the second table structure description file, wherein the plurality of first data tables in the source database correspond one-to-one with the plurality of second data tables in the target database, and each second data table is an empty data table; The migration module is used to connect to the source database and the target database respectively according to the connection information configuration file; The connection information configuration file includes first connection information corresponding to the source database and second connection information corresponding to the target database; The plurality of first data tables in the source database are traversed in a preset order. For the first data table currently being traversed: construct the query statement corresponding to the first data table, and construct the insert statement corresponding to the second data table, where the second data table corresponds to the first data table; By executing the query statement, the test data included in the first data table is read, and by executing the insert statement, the read test data is inserted into the second data table; After inserting the test data included in the first data table that is currently being traversed into the second data table, the next first data table is traversed in the preset order until the traversal of the plurality of first data tables is completed. The migration module is specifically used to obtain a first correspondence configuration file, which includes the correspondence between the table name of each of the multiple data tables and the column names of multiple columns in each of the multiple data tables, wherein the data tables are the first data table or the second data table; and to determine the correspondence between the table name of the currently traversed first data table and the column names of multiple columns in the first data table from the first correspondence configuration file. Based on the determined correspondence between the table name corresponding to the first data table and the column names of multiple columns in the first data table, construct the query statement corresponding to the first data table; obtain the second correspondence configuration file, which includes the correspondence between the multiple first data tables and the multiple second tables; From the second correspondence configuration file, determine the second data table corresponding to the first data table currently being traversed; From the first correspondence configuration file, determine the correspondence between the table name corresponding to the second data table and the column names of multiple columns in the second data table; Based on the correspondence between the determined table name of the second data table and the column names of multiple columns in the second data table, construct the insert statement corresponding to the second data table.
10. An electronic device, characterized in that, include: A processor and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the data migration method for heterogeneous databases as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the data migration method for heterogeneous databases as described in any one of claims 1 to 8.
12. A computer program product comprising computer-executable instructions, characterized in that, When the computer execution instructions are executed by the processor, they implement the data migration method for heterogeneous databases as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Database migration method and device from MySQL to Oracle and computer equipment
CN110704398A
Database migration method and device, equipment and readable medium
CN113407514A