Data migration method, device and storage medium
Through the automated database table structure migration method, the source database table structure information is obtained, the target table structure information and table building statements are generated, which solves the problems of low efficiency and poor accuracy caused by relying on manual migration in the existing technology, and realizes efficient and reliable database table structure migration.
Patent Information
- Application Number
- CN202411940491.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, the migration of database table structure mainly relies on manual labor, especially in large systems, which require a lot of manpower and time, and errors are prone to occur, affecting the project launch.
By obtaining the table structure information of the source database table, setting the target database table, determining the mapping table, generating target table structure information and table building statements based on data type, data length and other information, to realize automated database table structure migration.
It realizes accurate and reliable migration of database table structure, reduces manual intervention, improves migration efficiency and accuracy, and reduces project risks.
Smart Images

Figure CN119782283A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a data migration method, device and storage medium. Background Art
[0002] With the continuous advancement of information construction, the application of domestic databases is becoming more and more extensive. However, due to various reasons, many systems still use non-domestic databases, and the data migration and upgrade of these systems has become a problem. Therefore, how to convert the table structure of non-domestic databases into the table structure of domestic databases has become an urgent problem to be solved.
[0003] Currently, database table structure conversion still relies mainly on manual work, such as using SQL statements or database tools to export the source database table structure to text; manually rewriting the source database table structure into the target database table structure according to the mapping rules. In existing data migration, database table structure conversion still relies mainly on manual work, which is feasible when there are relatively few database tables. However, if you encounter large-scale system data migration (such as thousands of tables), the existing methods not only require a lot of manpower and time, but are also prone to errors, and may cause data migration failure, affecting the final project launch. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a data migration method, device and storage medium, which realizes accurate and reliable data migration.
[0005] In order to achieve the above-mentioned object, the first aspect of the present application provides a data migration method, which includes:
[0006] Acquire source table structure information of a source database table, wherein the source table structure information includes column information, and acquire the data type and data length of the column information;
[0007] Setting a first target database table, wherein the first target database table is provided with initial table structure information;
[0008] Determine a mapping table according to the correspondence between the fields of the source database table and the first target database table;
[0009] Determine the target table structure information of the first target database table according to the data type, data length, initial table structure information and mapping table;
[0010] Generate target table structure meta information according to the target table structure information, and generate a target table creation statement according to the target table structure meta information;
[0011] A second target database table is determined according to the target table creation statement and the target table structure information.
[0012] Optionally, determining a mapping table according to a correspondence between fields of the source database table and the first target database table includes:
[0013] Determine a mapping table according to the field correspondence between the data type and the data length in the source database table and the first target database table;
[0014] The column information in the source database table and the first target database table also includes at least one of column name, column non-empty information and column comment information.
[0015] Optionally, generating a target table creation statement according to the target table structure meta-information includes:
[0016] Acquire a database table statement format in the first target database table;
[0017] The target table structure meta-information is brought into the database table statement format to obtain a target table creation statement.
[0018] Optionally, the initial table structure information and the source table structure information both further include table name information, index information, constraint information and partition information;
[0019] The table name information, index information, constraint information and partition information in the initial table structure information are the same as those in the source table structure information.
[0020] Optionally, the method further includes: acquiring metadata in source table structure information of the source database table as first metadata, and acquiring metadata in table structure information of the second target database table as second metadata;
[0021] Acquire a first text and a second text of the first metadata and the second metadata respectively;
[0022] The hash codes and contents of the first text and the second text are compared to confirm whether the second target database table is correct.
[0023] Optionally, the method further includes:
[0024] Migrate the data of the source database table to the third target database table by using a data migration tool, and compare the data volume of each table in the third target database table and the second target database table;
[0025] Whether the second target database table is correct is determined based on the data amounts of the two.
[0026] On the other hand, the present invention also provides a data migration device, the device comprising:
[0027] An acquisition module is used to acquire source table structure information of a source database table, wherein the source table structure information includes column information, and acquire the data type and data length of the column information;
[0028] A first processing module is used to set a first target database table, wherein the first target database table is provided with initial table structure information;
[0029] A second processing module, configured to determine a mapping table according to a correspondence between fields of the source database table and the first target database table;
[0030] A third processing module, configured to determine target table structure information of the first target database table according to the data type, data length, initial table structure information and a mapping table;
[0031] A fourth processing module, configured to generate target table structure meta information according to the target table structure information, and generate a target table creation statement according to the target table structure meta information;
[0032] The fifth processing module is used to determine a second target database table according to the target table creation statement and the target table structure information.
[0033] Optionally, determining a mapping table according to a correspondence between fields of the source database table and the first target database table includes:
[0034] Determine a mapping table according to the field correspondence between the data type and the data length in the source database table and the first target database table;
[0035] The column information in the source database table and the first target database table also includes at least one of column name, column non-empty information and column comment information.
[0036] Optionally, the device further comprises:
[0037] A verification module is used to obtain the metadata in the table structure information of the source database table as the first metadata, and obtain the metadata in the table structure information of the second target database table as the second metadata; obtain the first text and the second text of the first metadata and the second metadata respectively; compare the hash code and content of the first text and the second text to confirm whether the second target database table is correct.
[0038] On the other hand, the present invention further provides a processor configured to execute the data migration method described above.
[0039] On the other hand, the present invention further proposes a machine-readable storage medium, on which instructions are stored. When the instructions are executed by a processor, the processor is configured to execute the data migration method described above.
[0040] On the other hand, the present invention further proposes a computer program product, comprising a computer program, wherein the computer program implements the data migration method described above when executed by a processor.
[0041] A data migration method of the present application includes: obtaining source table structure information of a source database table, the source table structure information includes column information, and obtaining the data type and data length of the column information; setting a first target database table, the first target database table is provided with initial table structure information; determining a mapping table according to the correspondence between the fields of the source database table and the first target database table; determining the target table structure information of the first target database table according to the data type, data length, initial table structure information and mapping table; generating target table structure meta information according to the target table structure information, generating a target table building statement according to the target table structure meta information; determining a second target database table according to the target table building statement and the target table structure information. The method obtains metadata information of the table structure by querying a system table, formulates conversion rules by importing into Excel, and realizes accurate and reliable data migration.
[0042] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings:
[0044] Figure 1 A schematic diagram of a data migration method according to an embodiment of the present application is shown schematically;
[0045] Figure 2 A schematic diagram of an embodiment according to the present application is schematically shown;
[0046] Figure 3 A structural block diagram of a data migration device according to an embodiment of the present application is schematically shown;
[0047] Figure 4 The internal structure diagram of a computer device according to an embodiment of the present application is schematically shown.
[0048] Description of Reference Numerals
[0049] 300-data migration device;
[0050] 301-Get module;
[0051] 302-first processing module;
[0052] 303-second processing module;
[0053] 304-third processing module;
[0054] 305-fourth processing module;
[0055] 306-Fifth processing module. DETAILED DESCRIPTION
[0056] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0057] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back...), the directional indications are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0058] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0059] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations. In addition, it should be noted that in the embodiments of this application, some existing solutions in the industry such as certain software, components, and models may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.
[0060] Figure 1 A schematic diagram of a data migration method according to an embodiment of the present application is shown schematically. Figure 1 As shown, the method includes:
[0061] Step S101 is to obtain the source table structure information of the source database table, the source table structure information includes column information, and the data type and data length of the column information are obtained. Specifically, the source table structure information also includes table name information, index information, constraint information and partition information, etc. The source database table refers to the data table contained in the database as the data source during data migration, data integration or data analysis. These tables usually include all table structures, table data, table relationships and other information stored in the source database. The source database table includes a main table, a subtable, a relationship table, a temporary table, a historical table, etc. Among them, the main table is the most common and core data table, which stores the main business data in the application system. For example, in a customer management system, the customer information table is a typical main table, which contains the basic information of the customer, such as name, address, contact information, etc. The main table usually has a unique primary key, which is used to uniquely identify each record, and the data in the main table has high consistency and integrity.
[0062] The main table, sub-table, relational table, temporary table and historical table all include table structure information, and the table structure information includes column information, table name information, index information, constraint information and partition information.
[0063] Specifically, the column information of the database table includes column name, column data type, column data length, column non-null information, column comment information, etc. What needs to be converted is the column data type and data length. For example, if the source end is an Oracle database, the column information of the Oracle database needs to be obtained.
[0064] Data migration refers to the process of migrating data from one data source to another. In software development and system integration, data migration is a common task that can migrate data between different systems so that it can be used in a new system or backed up in an old system.
[0065] According to a specific implementation method, the source end obtains the information required for the table structure (i.e., source table structure information) by querying the database system table (i.e., source database table), and the source table structure information includes table name, columns, indexes, constraints, and partition information. Taking Oracle as an example, the source table structure information includes:
[0066] Table information: dba_tables, dba_tab_comments;
[0067] Column information: dba_tab_colums, dba_col_comments;
[0068] Index information: dba_indexes, dba_ind_colums;
[0069] Constraint information: dba_constranints, dba_cons_colums;
[0070] Partition information: dba_tab_partitions, dba_part_key_colums.
[0071] Among them, table information includes table comments, column information includes column name, column data type, column data length, column non-empty information, column comment information and default value, etc., index information includes the number of indexes, fields of each index and field order, constraint information includes the number of constraints, fields of each constraint and field order, partition information includes partition fields and the value range of each partition. The column information in the source table structure information is the main information to be acquired, because usually different databases differ mainly in column information during the conversion process, mainly in the data type and length of the column. Other table names, comments and index fields are the same, and are used directly after acquisition without conversion.
[0072] Step S102 is to set a first target database table, wherein the first target database table is provided with initial table structure information.
[0073] Specifically, the initial table structure information and the source table structure information both further include table name information, index information, constraint information and partition information; the table name information, index information, constraint information and partition information in the initial table structure information and the source table structure information are the same.
[0074] The source database table and the target database table both belong to the database table structure, which refers to the definition of the columns and constraints of the database table, and describes the structure and data type of the table. In a relational database, a table is the basic unit of data storage, and each table consists of a series of columns, each of which has a unique column name and data type.
[0075] A database is a file locker that stores data. Users can store and add, query, modify, and delete data in a certain way. The design of a database table is the process of developers designing the database architecture and database based on the needs of users on a database management system. Each table contains one or more data types represented by columns.
[0076] Step S103 is to determine a mapping table according to the correspondence between the fields of the source database table and the first target database table.
[0077] According to a specific implementation manner, determining a mapping table according to a correspondence between fields in the source database table and the first target database table includes: determining a mapping table according to a correspondence between fields in data types and data lengths in the source database table and the first target database table; and the column information in the source database table and the first target database table also includes at least one of a column name, column non-empty information, and column comment information.
[0078] In the database, a mapping table is also called a connection table, link table or association table. It is used to resolve many-to-many relationships between entities. For example, a student can select multiple courses, and a course can be selected by multiple students. This relationship can be represented by a mapping table.
[0079] For example, a MySQL mapping table is a table used to establish a relationship between two entities. A mapping table usually contains foreign keys that relate two different data tables to each other. For example, consider a book database with the following two data tables, books and authors: There are many relationships between books and authors in this database. Each book can be written by one or more authors, and each author can also write multiple books. We need a mapping table to capture these relationships. It contains two foreign keys, book_id and author_id, to connect the books and authors tables. In this example, any book can belong to multiple authors, and any author can also write multiple books. Generally speaking, a mapping table does not include a primary key because it is just an intermediate table between two tables and does not represent an independent entity in the system.
[0080] For example, in the process of converting the table structure, the most important thing is the mapping relationship of the fields. The main difference between different databases is that the data types of the columns are inconsistent. The system can adapt to the conversion between different databases through dynamic adjustment. Moreover, the data length of the same data type may be different between different databases. For example, if Oracle's varchar2(90) only stores Chinese characters, because Oracle uses three bytes for each Chinese character, it can only store 30 Chinese characters. However, for the TiDB database (a distributed NewSQL database), the TiDB database stores characters, so the data type for storing 30 Chinese characters should be varchar(30). Therefore, this application designs the following excel table based on this situation:
[0081] Source data type Target data type Source data length Target data length varchar2 varchar 3n n char char n n
[0082] This application formulates conversion rules by importing Excel instead of changing the encoding code. In this way, if conversion problems occur, they can be solved by dynamically adjusting the Excel content, which is more flexible.
[0083] Step S104 is to determine the target table structure information of the first target database table according to the data type, data length, initial table structure information and mapping table.
[0084] Specifically, the mapping relationship is determined according to the above mapping table, and the table structure meta information (ie, target table structure information) of the target end is generated according to the source table structure information and the initial table structure information.
[0085] Designing the table structure is one of the core steps to build the target database table. First, determine the table columns. The table columns are the basic units in the database table, and each column stores a type of data. When designing the table structure, you need to determine the table columns and the data types of the columns.
[0086] For example, in a customer information table, you need to store information such as the customer's name, address, and phone number. Then define the primary key, which is one or more columns in the table whose values are used to identify each row in the table. The primary key is used to ensure the uniqueness and integrity of the data, such as using the customer ID as the primary key of the customer information table. In addition, you need to design foreign keys, which are one or more columns in a table whose values reference the primary key in another table. Foreign keys are used to define the relationship between tables. For example, the customer ID in the order table can be used as a foreign key to reference the customer ID in the customer information table.
[0087] Step S105 is to generate target table structure meta information according to the target table structure information, and generate a target table creation statement according to the target table structure meta information.
[0088] Meta information, also known as metadata, is a key component in database management and application development. It helps developers understand the structure of the database and how to interact with it efficiently. Metadata is "data about data" and contains descriptive information about the structure of the database. This information is usually not stored directly in the database, but in system tables or data dictionaries maintained by the database system. Metadata enables the database to be self-describing, that is, to provide information about its own structure. Metadata plays a vital role in the database design process.
[0089] According to a specific implementation, generating a target table creation statement according to the target table structure meta-information includes: obtaining a database table statement format in the first target database table; and bringing the target table structure meta-information into the database table statement format to obtain a target table creation statement.
[0090] For example, the module obtains the meta information and generates the table creation statement on the target side according to the DDL statement format of the target side table creation. DDL statements are statements used in the SQL language to define and manage database structures. They are mainly used to create, modify, and delete objects such as tables, views, and indexes in the database. Fill the target table structure meta information into the template in sequence (such as the table creation statement template of the target database Tidb).
[0091] Step S106 is to determine a second target database table according to the target table creation statement and the target table structure information.
[0092] According to a specific implementation, the method further includes: obtaining metadata in the source table structure information of the source database table as first metadata, and obtaining metadata in the table structure information of the second target database table as second metadata; respectively obtaining a first text and a second text of the first metadata and the second metadata; and comparing hash codes and contents of the first text and the second text to confirm whether the second target database table is correct.
[0093] For example, the target table structure information is mapped to the source table structure according to the mapping rules, and then both sides are output to txt in a certain format, such as:
[0094] table1-item1-varchar(5)-not null-'12345';
[0095] table1-item2-varchar(30)-not null;
[0096] table1-PARMARY KEY-item1-item2-item3;
[0097] table1-IND_TABLE_A1-item3;
[0098] table1-PARTITION-item3-table1_20230101-20230101;
[0099] table2-PARTITION-item3-table1_20240101-20240101.
[0100] Both the source database and the target database will generate such a text, and then compare the MD5 codes of the two texts. If the MD5 codes are equal, it means that the information in the database tables on both sides is consistent. If they are inconsistent, the program will be used to compare line by line to find the inconsistent information.
[0101] For example, by querying the system tables of the source and target databases, and then exporting the metadata of the table structure to text, and then comparing the MD5 codes of the two texts to compare the text content line by line to confirm whether the conversion is correct. When exporting the target data, the system will also reversely convert it into the data type of the source according to the relationship in the mapping table to ensure that the data type and length are consistent.
[0102] According to a specific implementation, the method further includes: migrating data from the source database table to a third target database table using a data migration tool, comparing the data volume of each table in the third target database table and the second target database table; and determining whether the second target database table is correct based on the data volume of the two.
[0103] For example, use a data migration tool to migrate data. After the migration is completed, compare the data on both databases to see if they are consistent. If they are consistent, it indirectly indicates that the table structures are consistent. If any field value is inconsistent, it may be caused by incorrect table structure conversion.
[0104] Specifically, the data at the source end is migrated to the target end through the data migration tool. After the migration is completed, the system compares the data volume of each table. If the data volume of each table is consistent, it means that the table structure conversion is correct. If there is inconsistency, it means that the conversion is incorrect and the conversion rules of the above mapping table need to be adjusted. This application ensures the data integrity and correctness of the target table by performing data migration and testing.
[0105] This application verifies whether the table structure conversion is correct through the double insurance of table structure conversion verification and data verification, which has the effect of verifying from both fundamental and purpose aspects.
[0106] Figure 2 A schematic diagram of an embodiment according to the present application is shown schematically. Figure 2 As shown, the present invention includes a source-end table structure information acquisition module, a source-end and target-end table structure mapping module, a target-end table structure conversion module, a table structure conversion verification module and a data verification module.
[0107] The source-side table structure information acquisition module is used by the source side to obtain the information required for the table structure by querying the database system table, including the table name, columns, indexes, constraints, and partitions.
[0108] In the process of table structure conversion, the most important thing is the mapping relationship of the fields. The biggest difference between different databases is the inconsistency of column data types. The source and target table structure mapping modules are used to adapt to the conversion between different databases through dynamic adjustment. The data length of the same data type may be different between different databases.
[0109] The target-side table structure conversion module is used to generate the target-side table structure meta information based on the source-side database table structure information. Then this module uses the obtained meta information to generate the target-side table creation statement according to the target-side table creation DDL statement format.
[0110] The table structure conversion verification module is used to query the system tables of the source and target databases, export the metadata of the table structure to text, and then confirm whether the conversion is correct by comparing the MD5 codes of the two texts and comparing the text contents line by line.
[0111] The data verification module is used to migrate the data from the source end to the destination end through the data migration tool. After the migration is completed, the system compares the data volume of each table. If the data volume of each table is consistent, it means that the table structure conversion is correct. If there is an inconsistency, it means that the conversion is incorrect and the conversion rules of the source table structure information acquisition module need to be adjusted.
[0112] This application obtains metadata information of the table structure by querying the system table, formulates conversion rules by importing them into Excel, and achieves accurate and reliable data migration.
[0113] Figure 3 A structural block diagram of a data migration device according to an embodiment of the present application is schematically shown. Figure 3 As shown, the data migration device 300 of the present application includes:
[0114] The acquisition module 301 is used to acquire source table structure information of a source database table, wherein the source table structure information includes column information, and acquire the data type and data length of the column information.
[0115] The first processing module 302 is used to set a first target database table, where the first target database table is provided with initial table structure information.
[0116] The second processing module 303 is used to determine a mapping table according to the correspondence between the fields of the source database table and the first target database table. The determining of the mapping table according to the correspondence between the fields of the source database table and the first target database table includes: determining the mapping table according to the correspondence between the fields of the data type and the data length in the source database table and the first target database table; the column information in the source database table and the first target database table also includes at least one of the column name, column non-empty information and column comment information.
[0117] The third processing module 304 is used to determine the target table structure information of the first target database table according to the data type, data length, initial table structure information and mapping table.
[0118] The fourth processing module 305 is used to generate target table structure meta information according to the target table structure information, and generate a target table creation statement according to the target table structure meta information.
[0119] The fifth processing module 306 is used to determine a second target database table according to the target table creation statement and the target table structure information.
[0120] The device also includes: a verification module, which is used to obtain the metadata in the table structure information of the source database table as the first metadata, and obtain the metadata in the table structure information of the second target database table as the second metadata; respectively obtain the first text and the second text of the first metadata and the second metadata; compare the hash code and content of the first text and the second text to confirm whether the second target database table is correct. The data migration refers to the process of migrating data from one data source to another data source. In software development and system integration, data migration is a common task that can migrate data between different systems so that it can be used in a new system or backed up in an old system.
[0121] The device obtains metadata information of the table structure by querying the system table, formulates conversion rules by importing them into Excel, and realizes accurate and reliable data migration.
[0122] A data migration method of the present application includes: obtaining source table structure information of a source database table, the source table structure information includes column information, and obtaining the data type and data length of the column information; setting a first target database table, the first target database table is provided with initial table structure information; determining a mapping table according to the correspondence between the fields of the source database table and the first target database table; determining the target table structure information of the first target database table according to the data type, data length, initial table structure information and mapping table; generating target table structure meta information according to the target table structure information, generating a target table building statement according to the target table structure meta information; determining a second target database table according to the target table building statement and the target table structure information. The method obtains metadata information of the table structure by querying a system table, formulates conversion rules by importing into Excel, and realizes accurate and reliable data migration.
[0123] An embodiment of the present application provides a storage medium on which a program is stored, and when the program is executed by a processor, the above-mentioned data migration method is implemented.
[0124] An embodiment of the present application provides a processor, which is used to run a program, wherein the above-mentioned data migration method is executed when the program is running.
[0125] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 4 As shown. The computer device includes a processor A01, a network interface A02, a display screen A04, an input device A05 and a memory (not shown in the figure) connected through a system bus. Among them, the processor A01 of the computer device is used to provide computing and control capabilities. The memory of the computer device includes an internal memory A03 and a non-volatile storage medium A06. The non-volatile storage medium A06 stores an operating system B01 and a computer program B02. The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 in the non-volatile storage medium A06. The network interface A02 of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor A01, a data migration method is implemented. The display screen A04 of the computer device can be a liquid crystal display or an electronic ink display, and the input device A05 of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0126] An embodiment of the present application provides a device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the data migration method described in any embodiment of the present application is performed.
[0127] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that initializes the data migration method according to any embodiment of the present invention.
[0128] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0129] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0130] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0131] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0132] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0133] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0134] Computer readable media include permanent and non-permanent, removable and non-removable media, and can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0135] The acquisition, transmission, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of national laws and regulations. It should be noted that in the embodiments of this application, some existing solutions in the industry such as certain software, components, and models may be mentioned, and they should be considered as exemplary. Their purpose is only to illustrate the feasibility of the implementation of the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution.
[0136] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0137] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A data migration method, characterized in that: The method includes: Acquire source table structure information of a source database table, wherein the source table structure information includes column information, and acquire the data type and data length of the column information; Setting a first target database table, wherein the first target database table is provided with initial table structure information; Determine a mapping table according to the correspondence between the fields of the source database table and the first target database table; Determine the target table structure information of the first target database table according to the data type, data length, initial table structure information and mapping table; Generate target table structure meta information according to the target table structure information, and generate a target table creation statement according to the target table structure meta information; A second target database table is determined according to the target table creation statement and the target table structure information.
2. The method according to claim 1, characterized in that The determining of the mapping table according to the correspondence between the fields of the source database table and the first target database table includes: Determine a mapping table according to the field correspondence between the data type and the data length in the source database table and the first target database table; The column information in the source database table and the first target database table also includes at least one of column name, column non-empty information and column comment information.
3. The method according to claim 1, characterized in that The step of generating a target table creation statement according to the target table structure meta-information includes: Acquire a database table statement format in the first target database table; The target table structure meta-information is brought into the database table statement format to obtain a target table creation statement.
4. The method according to claim 1, characterized in that The initial table structure information and the source table structure information both include table name information, index information, constraint information and partition information; The table name information, index information, constraint information and partition information in the initial table structure information are the same as those in the source table structure information.
5. The method according to claim 1, characterized in that The method further includes: The metadata in the source table structure information of the source database table is obtained as the first metadata, and the metadata in the table structure information of the second target database table is obtained as the second metadata; Acquire a first text and a second text of the first metadata and the second metadata respectively; The hash codes and contents of the first text and the second text are compared to confirm whether the second target database table is correct.
6. The method according to claim 1, characterized in that The method further includes: Migrate the data of the source database table to the third target database table by using a data migration tool, and compare the data volume of each table in the third target database table and the second target database table; Whether the second target database table is correct is determined based on the data amounts of the two.
7. A data migration device, characterized in that: The device includes: An acquisition module is used to acquire source table structure information of a source database table, wherein the source table structure information includes column information, and acquire the data type and data length of the column information; A first processing module is used to set a first target database table, wherein the first target database table is provided with initial table structure information; A second processing module, configured to determine a mapping table according to a correspondence between fields of the source database table and the first target database table; A third processing module, configured to determine target table structure information of the first target database table according to the data type, data length, initial table structure information and a mapping table; A fourth processing module, configured to generate target table structure meta information according to the target table structure information, and generate a target table creation statement according to the target table structure meta information; The fifth processing module is used to determine a second target database table according to the target table creation statement and the target table structure information.
8. The device according to claim 7, characterized in that The determining of the mapping table according to the correspondence between the fields of the source database table and the first target database table includes: Determine a mapping table according to the field correspondence between the data type and the data length in the source database table and the first target database table; The column information in the source database table and the first target database table also includes at least one of column name, column non-empty information and column comment information.
9. The device according to claim 7, characterized in that The device also includes: A verification module is used to obtain the metadata in the table structure information of the source database table as the first metadata, and obtain the metadata in the table structure information of the second target database table as the second metadata; obtain the first text and the second text of the first metadata and the second metadata respectively; compare the hash code and content of the first text and the second text to confirm whether the second target database table is correct.
10. A processor, characterized in that: The method is configured to execute the data migration method according to any one of claims 1 to 6.
11. A machine-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor is configured to perform the data migration method according to any one of claims 1 to 6.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the data migration method according to any one of claims 1 to 6.