Data migration method and device, computer device and storage medium
By using an auto-incrementing identifier to modify and repair parent-child relationship identifiers during data migration, the problem of disordered hierarchical relationships in tree-shaped data migration is solved, enabling fast data migration without structural changes and reducing code redundancy and workload.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- VISIONNAV ROBOTICS SHENZHEN LTD
- Filing Date
- 2022-12-14
- Publication Date
- 2026-08-04
AI Technical Summary
During data migration, changes in the auto-incrementing identifier of tree-structured data can disrupt hierarchical relationships. Traditional solutions require altering the target data table structure, increasing workload and impacting migration speed.
By writing data from the first variable table into the second variable table, modifying the parent-child relationship identifier based on the auto-increment identifier in the second variable table, and then inserting it into the target data table, auto-increment processing and repair are performed to ensure that the parent-child relationship is correct without changing the target data table structure.
It enables rapid data migration without changing the target data table structure, reducing code redundancy and workload, and improving data migration speed.
Smart Images

Figure CN116069757B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a data migration method, apparatus, computer equipment, storage medium, and computer program product. Background Technology
[0002] In some scenarios, data might be inserted from a source table into a target table, and then the target table is saved, thus completing the data migration. If the data to be migrated is in a tree structure, the auto-incrementing identifier may change during the migration process, potentially causing confusion in the hierarchical relationships of the data.
[0003] To address the aforementioned technical issues, the traditional approach involves adding a new field to the target table during data migration to store an auto-incrementing identifier from the source table. This identifier is used to restore the hierarchical relationships after data insertion. However, this traditional approach requires altering the structure of the target table, increasing the workload and slowing down the migration process. Summary of the Invention
[0004] Therefore, it is necessary to provide a data migration method, apparatus, computer equipment, computer-readable storage medium, and computer program product to address the aforementioned technical problems, which can achieve rapid data migration without changing the structure of the target data table.
[0005] Firstly, this application provides a data migration method. The method includes:
[0006] Data from the first variable table is written into the second variable table; both the data in the first and second variable tables are tree-structured data; the parent-child relationship identifiers in the second variable table are modified according to the auto-increment identifiers, resulting in a modified second variable table; the modified second variable table is inserted into the target data table, and the auto-increment identifiers in the inserted second variable table are incremented according to a preset auto-increment strategy, resulting in a processed variable table; the parent-child relationship identifiers in the processed variable table are repaired according to the processed auto-increment identifiers, resulting in a repaired target data table; the repaired target data table is stored.
[0007] In one embodiment, writing data from the first variable table into the second variable table includes:
[0008] Load the data from the data table to be migrated into the first variable table; the first variable table contains an auto-incrementing identifier, the data to be migrated, and a parent-child relationship identifier representing the parent-child relationship between each of the data to be migrated; write the auto-incrementing identifier, the data to be migrated, and the parent-child relationship identifier from the first variable table into the second variable table.
[0009] In one embodiment, modifying the parent-child relationship identifier in the second variable table based on the auto-incrementing identifier in the second variable table includes:
[0010] Read the auto-incrementing identifier from the second variable table; modify the parent-child relationship identifier in the second variable table to the read auto-incrementing identifier.
[0011] In one embodiment, the step of repairing the parent-child relationship identifier in the processed variable table based on the processed auto-incrementing identifier includes:
[0012] The first data entry is obtained by searching for the data corresponding to the target node in the first variable table; the second data entry is obtained by searching for the data in the processed variable table that corresponds to the parent-child relationship identifier that is equal to the auto-incrementing identifier in the first data entry; the third data entry is obtained by searching for the data in the processed variable table that corresponds to the parent-child relationship identifier that is the same as the parent-child relationship identifier in the first data entry; and the parent-child relationship identifier in the second data entry is repaired according to the auto-incrementing identifier in the third data entry.
[0013] In one embodiment, the method further includes:
[0014] When the target node is not the root node, the step of repairing the parent-child relationship identifier in the processed variable table is executed repeatedly until the repair of the parent-child relationship identifier corresponding to the non-root node in the processed variable table is completed.
[0015] Secondly, this application also provides a data migration apparatus. The apparatus includes:
[0016] The write module is used to write data from the first variable table to the second variable table; the data in the first variable table and the data in the second variable table are both tree-structured data.
[0017] The modification module is used to modify the parent-child relationship identifier in the second variable table according to the auto-incrementing identifier in the second variable table, so as to obtain the modified second variable table;
[0018] The processing module is used to insert the modified second variable table into the target data table, and to increment the auto-increment identifier in the inserted second variable table according to the preset auto-increment strategy to obtain the processed variable table.
[0019] The repair module is used to repair the parent-child relationship identifier in the processed variable table based on the processed auto-incrementing identifier, so as to obtain the repaired target data table.
[0020] The storage module is used to store the repaired target data table.
[0021] In one embodiment, the writing module is further configured to load data from the data table to be migrated into a first variable table; the first variable table contains an auto-incrementing identifier, the data to be migrated, and a parent-child relationship identifier representing the parent-child relationship between each of the data to be migrated; and write the auto-incrementing identifier, the data to be migrated, and the parent-child relationship identifier from the first variable table into a second variable table.
[0022] In one embodiment, the modification module is further configured to read the auto-incrementing identifier in the second variable table and modify the parent-child relationship identifier in the second variable table to the read auto-incrementing identifier.
[0023] In one embodiment, the repair module is further configured to: search for data corresponding to the target node in the first variable table to obtain a first data entry; search for data in the processed variable table that corresponds to the parent-child relationship identifier being equal to the auto-incrementing identifier in the first data entry to obtain a second data entry; search for data in the processed variable table that corresponds to the parent-child relationship identifier being the same as the parent-child relationship identifier in the first data entry to obtain a third data entry; and repair the parent-child relationship identifier in the second data entry based on the auto-incrementing identifier in the third data entry.
[0024] In one embodiment, the repair module, when the target node is not the root node, repeatedly executes the step of repairing the parent-child relationship identifiers in the processed variable table until the repair of the parent-child relationship identifiers that are not corresponding to the root node in the processed variable table is completed.
[0025] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0026] Data from the first variable table is written into the second variable table; both the data in the first and second variable tables are tree-structured data; the parent-child relationship identifiers in the second variable table are modified according to the auto-increment identifiers, resulting in a modified second variable table; the modified second variable table is inserted into the target data table, and the auto-increment identifiers in the inserted second variable table are incremented according to a preset auto-increment strategy, resulting in a processed variable table; the parent-child relationship identifiers in the processed variable table are repaired according to the processed auto-increment identifiers, resulting in a repaired target data table; the repaired target data table is stored.
[0027] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0028] Data from the first variable table is written into the second variable table; both the data in the first and second variable tables are tree-structured data; the parent-child relationship identifiers in the second variable table are modified according to the auto-increment identifiers, resulting in a modified second variable table; the modified second variable table is inserted into the target data table, and the auto-increment identifiers in the inserted second variable table are incremented according to a preset auto-increment strategy, resulting in a processed variable table; the parent-child relationship identifiers in the processed variable table are repaired according to the processed auto-increment identifiers, resulting in a repaired target data table; the repaired target data table is stored.
[0029] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0030] Data from the first variable table is written into the second variable table; both the data in the first and second variable tables are tree-structured data; the parent-child relationship identifiers in the second variable table are modified according to the auto-increment identifiers, resulting in a modified second variable table; the modified second variable table is inserted into the target data table, and the auto-increment identifiers in the inserted second variable table are incremented according to a preset auto-increment strategy, resulting in a processed variable table; the parent-child relationship identifiers in the processed variable table are repaired according to the processed auto-increment identifiers, resulting in a repaired target data table; the repaired target data table is stored.
[0031] The aforementioned data migration method, apparatus, computer equipment, storage medium, and computer program product first write the data from the first variable table to be migrated into a second variable table. Based on the auto-incrementing identifier in the second variable table, the parent-child relationship identifier in the second variable table is modified. The modified second variable table is then inserted into the target data table, and the auto-incrementing identifier in the inserted second variable table is incremented according to a preset auto-incrementing strategy to obtain a processed variable table. Based on the processed auto-incrementing identifier, the parent-child relationship identifier in the processed variable table is repaired. Therefore, it is not necessary to add a new field in the target data table to store the auto-incrementing identifier from the first variable table. The repaired target data table can be obtained without changing its structure, smoothly completing the data migration. This helps reduce code redundancy and workload, and effectively avoids structural changes affecting the data in the target data table, thereby improving the speed of data migration. Attached Figure Description
[0032] Figure 1 This is a diagram illustrating the application environment of a data migration method in one embodiment.
[0033] Figure 2 This is a flowchart illustrating a data migration method in one embodiment;
[0034] Figure 3 This is a schematic diagram of a first variable table or a second variable table before modification in one embodiment;
[0035] Figure 4 This is a schematic diagram illustrating the modification of the parent-child relationship identifier in the second variable table in one embodiment;
[0036] Figure 5 This is a schematic diagram illustrating the insertion of the second variable table into the target data table in one embodiment;
[0037] Figure 6 This is a schematic diagram of the tree-structured data in one embodiment;
[0038] Figure 7 This is a schematic diagram illustrating the repair of parent-child relationship identifiers in the processed variable table in one embodiment;
[0039] Figure 8 This is a schematic diagram of the repaired target data table in one embodiment;
[0040] Figure 9 This is a flowchart illustrating the data migration method in another embodiment;
[0041] Figure 10 This is a flowchart illustrating the process of repairing a new variable table in a target data table in one embodiment.
[0042] Figure 11This is a schematic diagram of the old variable table and the new variable table before and after the repair in one embodiment;
[0043] Figure 12 This is a structural block diagram of a data migration device in one embodiment;
[0044] Figure 13 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0046] The data migration method provided in this application embodiment can be applied to, for example, Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network.
[0047] Terminal 102 or server 104 loads data from the source data table into a first variable table, and then writes the data from the first variable table into a second variable table; the data in the first variable table and the data in the second variable table are both tree-structured data; the parent-child relationship identifiers in the second variable table are modified according to the auto-increment identifiers in the second variable table to obtain a modified second variable table; the modified second variable table is inserted into the target data table, and the auto-increment identifiers in the inserted second variable table are incremented according to a preset auto-increment strategy to obtain a processed variable table; the parent-child relationship identifiers in the processed variable table are repaired according to the processed auto-increment identifiers to obtain a repaired target data table; the repaired target data table is stored, such as in database a or database b.
[0048] The terminal 102 can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, IoT device, or portable wearable device. IoT devices can include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle devices, etc. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices, etc.
[0049] Server 104 can be an independent physical server or a service node in a blockchain system. The service nodes in the blockchain system form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol that runs on top of the Transmission Control Protocol (TCP).
[0050] In addition, server 104 can also be a server cluster consisting of multiple physical servers, which can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0051] Terminal 102 and server 104 can be connected via Bluetooth, USB (Universal Serial Bus) or network, etc., and this application does not impose any restrictions.
[0052] In one embodiment, such as Figure 2 As shown, a data migration method is provided, which is applied to... Figure 1 Taking the server in the example, the following steps are included:
[0053] S202, write the data from the first variable table into the second variable table.
[0054] In this context, both the first variable table and the second variable table can refer to table-type variables defined in a computer program. The first variable table can be called the old variable table (old_list), and the second variable table can be called the new variable table (new_list). Each row of data in the first and second variable tables can be called a data entry.
[0055] It should be noted that the data in the first variable table and the data in the second variable table are tree-structured data, as shown in 3. Figure 3 Each data entry can represent a node, such as Figure 3 The first data entry in the first variable table can represent the root node, the middle data entries represent intermediate nodes, and the last data entry represents a leaf node. There is a parent-child relationship, also known as a hierarchical relationship, between each data entry in the first and second variable tables, represented by a parent-child relationship identifier (parentId). For example, in... Figure 3 In the first variable table, the parent-child relationship identifier of the second data entry is 1, indicating that the second data entry belongs to the next level of data of the first data entry, such as sensing laser belonging to hardware; in addition, the parent-child relationship identifier of the third data entry is 2, indicating that the third data entry belongs to the next level of data of the second data entry, such as 3D sensing laser belonging to sensing laser.
[0056] In one embodiment, the server receives a data migration request initiated by the terminal, runs a corresponding computer program based on the data migration request, and creates a first variable table and a second variable table through the computer program.
[0057] After the creation of the first and second variable tables is completed, the server loads the data from the data table to be migrated into the first variable table. The first variable table contains an auto-incrementing identifier, the data to be migrated, and a parent-child relationship identifier representing the parent-child relationship between each data to be migrated. The auto-incrementing identifier, the data to be migrated, and the parent-child relationship identifier from the first variable table are written into the second variable table.
[0058] The auto-incrementing identifier can be a number used to indicate the position of data in the table, which is automatically updated after data migration. The data to be migrated includes business data from the first variable table, i.e., the data that needs to be migrated. For example, the data to be migrated could be... Figure 3 The data name in the file.
[0059] S204. Modify the parent-child relationship identifier in the second variable table according to the auto-increment identifier in the second variable table to obtain the modified second variable table.
[0060] When modifying the parent-child relationship identifiers in the second variable table, all parent-child relationship identifiers in the second variable table can be modified, or only some parent-child relationship identifiers in the second variable table can be modified. Specifically, the server reads the auto-incrementing identifiers in the second variable table; modifies the parent-child relationship identifiers in the second variable table to the read auto-incrementing identifiers; or, it searches for the parent-child relationship identifiers corresponding to non-root nodes in the second variable table and modifies the parent-child relationship identifiers corresponding to non-root nodes to the read auto-incrementing identifiers.
[0061] For example, such as Figure 4 As shown in Figure (a), Figure (a) represents the `new_list` before modification. In this `new_list`, the first data entry has an auto-incrementing identifier of 1, and its corresponding parent-child relationship identifier is 0; similarly, the second data entry has an auto-incrementing identifier of 2, and its corresponding parent-child relationship identifier is 1; the third data entry has an auto-incrementing identifier of 3, and its corresponding parent-child relationship identifier is 2. That is, the values of the parent-child relationship identifier and the auto-incrementing identifier are different. After obtaining the `new_list`, the server modifies the identifiers of all parent-child relationship nodes in the `new_list` to auto-incrementing identifiers, such as... Figure 4 As shown in Figure (b), the auto-incrementing identifier of the first data entry is 1, and the corresponding parent-child relationship identifier is 1; similarly, the auto-incrementing identifier of the second data entry is 2, and the corresponding parent-child relationship identifier is 2; the auto-incrementing identifier of the third data entry is 3, and the corresponding parent-child relationship identifier is 3, that is, the value of the parent-child relationship identifier is the same as the value of the auto-incrementing identifier.
[0062] In addition to the above modifications, the server can also modify the parent-child relationship node identifiers corresponding to non-root nodes in `new_list` to auto-incrementing identifiers, such as... Figure 4As shown in Figure (c), the first data entry has an auto-incrementing identifier of 1, and the corresponding parent-child relationship identifier is 0; the second data entry has an auto-incrementing identifier of 2, and the corresponding parent-child relationship identifier is 2; the third data entry has an auto-incrementing identifier of 3, and the corresponding parent-child relationship identifier is 3, meaning that the parent-child relationship identifier and the auto-incrementing identifier have the same value. Figure 4 As shown in Figures (b) and (c), the parent-child relationship identifiers of the first data entry in the two modified new_lists differ depending on the modification method used, while the parent-child relationship identifiers of the second and third data entries are the same.
[0063] S206, insert the modified second variable table into the target data table, and increment the auto-increment flags in the inserted second variable table according to the preset auto-increment strategy to obtain the processed variable table.
[0064] The target data table can be a data table in the target database. It should be noted that each data entry in the first variable table can be data from the target database. After repair, the repaired target data table is stored in the target database, thus enabling data migration between different data tables within the same database. Alternatively, each data entry in the first variable table can also be data from other source databases. After repair, the repaired target data table is stored in the target database, thus enabling data migration between different databases.
[0065] In one embodiment, the server reads the target data table from the target database according to a read instruction, and then inserts the modified second variable table into the target data table, thereby inserting each data entry from the modified second variable table into the target data table; then, based on the auto-increment identifier in the target data table, the auto-increment identifier in the inserted second variable table is incremented to obtain the processed variable table. The read instruction can be an instruction sent by the client.
[0066] In this context, auto-increment processing refers to incrementing the auto-increment identifier in the inserted second variable table based on the original auto-increment identifier in the target data table. For example, the server inserts each data entry from the modified `new_list` into the target data table, and then increments the auto-increment identifier in the inserted `new_list` according to the auto-increment identifier in the target data table, resulting in the processed variable table in the target data table, such as... Figure 5As shown, the first to fourth data entries in the target data table are the original data entries, and the fifth to seventh data entries are the newly inserted data entries. Since the original auto-incrementing identifiers in the target data table are 1 to 4, after inserting the data, referring to the original auto-incrementing identifiers 1 to 4, the auto-incrementing identifiers in the inserted second variable table are incremented (e.g., incremented based on the original auto-incrementing identifier 4, with each increment increment being 1), thus obtaining auto-incrementing identifiers 5 to 7. For details, please refer to... Figure 5 The bold black text in the image.
[0067] S208, Based on the processed auto-incrementing identifier, repair the parent-child relationship identifier in the processed variable table to obtain the repaired target data table.
[0068] In one embodiment, the server uses a target recursive algorithm and repairs the parent-child relationship identifiers in the processed variable table based on the processed auto-incrementing identifiers to obtain the repaired target data table.
[0069] Specifically, the server searches for the data corresponding to the target node in the first variable table to obtain the first data entry; in the processed variable table, it searches for the data corresponding to the parent-child relationship identifier that is equal to the auto-incrementing identifier in the first data entry to obtain the second data entry; in the processed variable table, it searches for the data corresponding to the parent-child relationship identifier that is the same as the parent-child relationship identifier in the first data entry to obtain the third data entry; based on the auto-incrementing identifier in the third data entry, the parent-child relationship identifier in the second data entry is repaired, that is, the parent-child relationship identifier in the second data entry is replaced with the auto-incrementing identifier in the third data entry.
[0070] The target node can be a root node, an intermediate node, or a leaf node. The root node is a node in the node tree that has no parent node. Considering that the data in the first variable table is tree-structured data, the root node can specifically be the first node in the tree structure data. Figure 6 In diagram (a), node A1, this node A1 is... Figure 3 The first data entry corresponds to, and also to Figure 5 The fifth data entry corresponds to this; leaf nodes are nodes in the node tree that have no child nodes, specifically the last node in the tree structure data, corresponding to... Figure 6 In diagram (a), node A3, this node A3 is... Figure 3 The third data entry corresponds to, and also to Figure 5 The seventh data entry corresponds to this; while the intermediate node is the node located between the root node and the leaf node, corresponding to... Figure 6 In diagram (a), node A2, this node A2 is... Figure 3 The second data entry corresponds to, and also to Figure 5 It corresponds to the sixth data entry in the list.
[0071] Furthermore, it should be noted that a single data table may contain multiple tree-structured data, such as... Figure 5 The target data table shown contains two tree-structured data sets. The first to fourth data entries correspond to one tree-structured data set, which can be referenced. Figure 6 Figure (b) shows that the fifth to seventh data entries correspond to a tree-structured data structure, which can be referenced. Figure 6 Figure (a) shows the graph. In Figure (b), node B1 is the root node, corresponding to... Figure 5 The first data entry in the array; node B2 is an intermediate node, corresponding to... Figure 5 The second data entry in the table; nodes B3 and B4 are leaf nodes, corresponding to... Figure 5 The third and fourth data entries in the data.
[0072] When the target node is the root node, the server retrieves the data corresponding to the root node from the first variable table, thus obtaining the first data entry in the first variable table. When the target node is a leaf node, the server retrieves the data corresponding to the root node from the first variable table, thus obtaining the last data entry in the first variable table.
[0073] In one embodiment, when the target node is not the root node, the server repeatedly executes the step of repairing the parent-child relationship identifiers in the processed variable table until the repair of the parent-child relationship identifiers corresponding to non-root nodes in the processed variable table is completed.
[0074] For example, such as Figure 7 As shown in (a), the data corresponding to the intermediate node is searched in the first variable table to obtain the first data entry; then, in the processed variable table, the data corresponding to the parent-child relationship identifier that is equal to the auto-incrementing identifier in the first data entry is searched to obtain the second data entry; and, in the processed variable table, the data corresponding to the parent-child relationship identifier that is the same as the parent-child relationship identifier in the first data entry is searched to obtain the third data entry. (See reference...) Figure 7 Figure (b) shows the process. After obtaining the second and third data entries, the parent-child relationship identifier in the second data entry is replaced with the auto-incrementing identifier in the third data entry to obtain the repaired third data entry. Similarly, for the leaf nodes of the first variable table, the above method can be used to repair all parent-child relationship identifiers in the processed variable table, thus obtaining the repaired target data table, as shown in Figure (b). Figure 8 As shown.
[0075] S210, store the repaired target data table.
[0076] In one embodiment, the server stores the repaired target data table in the target database.
[0077] In the above embodiments, the data in the first variable table to be migrated is first written into the second variable table. The parent-child relationship identifier in the second variable table is modified according to the auto-increment identifier in the second variable table. The modified second variable table is then inserted into the target data table, and the auto-increment identifier in the inserted second variable table is incremented according to a preset auto-increment strategy to obtain the processed variable table. The parent-child relationship identifier in the processed variable table is then repaired according to the processed auto-increment identifier. Therefore, it is not necessary to add a new field in the target data table to store the auto-increment identifier in the first variable table. The repaired target data table can be obtained without changing the structure of the target data table, thus smoothly completing the data migration. This helps to reduce code redundancy and workload, and also effectively avoids the impact of structural changes on the data in the target data table, thereby improving the speed of data migration.
[0078] To gain a more intuitive understanding of the solution proposed in this application, we will combine the following... Figure 9 , Figure 10 and Figure 11 The description is as follows:
[0079] First, the overall data migration process is described, which can be found in [reference]. Figure 9 The specific details are as follows:
[0080] (1) Load the data from the old data table into the old variable table;
[0081] (2) Copy the data from the old variable table to the new variable table;
[0082] (3) Modify the parent-child relationship identifiers in the new variable table according to the auto-increment identifier;
[0083] (4) Insert the data from the new variable table into the new data table;
[0084] (5) Repair the parent-child relationship identifiers in the new variable table using a recursive algorithm and store them.
[0085] For the repair process in step (5), please refer to... Figure 10 and Figure 11 The specific details are as follows:
[0086] S1, find the data entry in the old variable table whose parent-child relationship identifier is equal to 1. This data entry can be called the old data entry (denoted as old_item);
[0087] The old variable table can be referenced. Figure 11 Figure (a)
[0088] S2, in the new variable table, find the data entry whose parent-child relationship identifier is equal to the parent-child relationship identifier of the old data entry. The data entry found can be called the new data entry a;
[0089] The new variable table can be found here. Figure 11 (b) of the diagram.
[0090] For example, based on the parent-child relationship identifier of the old data entry, search for the data entry in the new variable table whose parent-child relationship identifier is equal to 1. This searched data entry can be called the new data entry a. The auto-incrementing identifier of the new data entry a is equal to 5.
[0091] S3. In the new variable table, find the data entry whose parent-child relationship identifier is equal to the auto-incrementing identifier in the old variable table. This data entry can be called the new data entry b.
[0092] After steps S1, S2, and S3, we can obtain the old data entry in the old variable table where the parent-child relationship identifier is equal to 1 and the auto-increment identifier is equal to 2; and we can obtain the new data entry a where the parent-child relationship identifier is equal to 1 and the auto-increment identifier is equal to 5, and the new data entry b where the parent-child relationship identifier is equal to 2 and the auto-increment identifier is equal to 6.
[0093] S4, replace the parent-child variable identifier in the new data entry b with the auto-incrementing identifier in the new data entry a, and obtain the repaired new data entry b;
[0094] S5, after completing the repair of the parent-child relationship identifier, determine whether a subset of the old data entry exists in the old variable table;
[0095] If yes, then the subset is treated as the old data entry, and the recursive program returns to execute steps S2 to S5 until the new variable table is repaired; otherwise, the process ends.
[0096] The revised variable table can be found here. Figure 12 (c) of the figure.
[0097] When migrating tree-like data with auto-incrementing identifiers as hierarchical relationships to a new data table with the same structure via code, the hierarchical relationships of the data in the new table are dynamically repaired while maintaining the original table structure. This helps reduce code redundancy and workload.
[0098] It should be understood that although the steps in the flowcharts of the embodiments described above 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 flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0099] Based on the same inventive concept, this application also provides a data migration apparatus for implementing the data migration method described above. The solution provided by this apparatus is similar to the implementation scheme described in the above method; therefore, the specific limitations in one or more data migration apparatus embodiments provided below can be found in the limitations of the data migration method described above, and will not be repeated here.
[0100] In one embodiment, such as Figure 12 As shown, a data migration device is provided, including: a writing module 1202, a modification module 1204, a processing module 1206, a repair module 1208, and a storage module 1210, wherein:
[0101] The write module 1202 is used to write data from the first variable table into the second variable table; the data in the first variable table and the data in the second variable table are tree structure data, respectively.
[0102] Modification module 1204 is used to modify the parent-child relationship identifier in the second variable table according to the auto-increment identifier in the second variable table, so as to obtain the modified second variable table;
[0103] The processing module 1206 is used to insert the modified second variable table into the target data table, and to increment the auto-increment flags in the inserted second variable table according to the preset auto-increment strategy to obtain the processed variable table.
[0104] Repair module 1208 is used to repair the parent-child relationship identifier in the processed variable table based on the processed auto-incrementing identifier, so as to obtain the repaired target data table;
[0105] Storage module 1210 is used to store the repaired target data table.
[0106] In one embodiment, the writing module 1202 is further configured to load data from the data table to be migrated into a first variable table; the first variable table contains an auto-incrementing identifier, the data to be migrated, and a parent-child relationship identifier representing the parent-child relationship between each data to be migrated; and write the auto-incrementing identifier, the data to be migrated, and the parent-child relationship identifier from the first variable table into a second variable table.
[0107] In one embodiment, the modification module 1204 is further configured to read the auto-incrementing identifier in the second variable table and modify the parent-child relationship identifier in the second variable table to the read auto-incrementing identifier.
[0108] In one embodiment, the repair module 1208 is further configured to: search for the data corresponding to the target node in the first variable table to obtain a first data entry; search for the data corresponding to the parent-child relationship identifier that is equal to the auto-incrementing identifier in the first data entry in the processed variable table to obtain a second data entry; search for the data corresponding to the parent-child relationship identifier that is the same as the parent-child relationship identifier in the first data entry in the processed variable table to obtain a third data entry; and repair the parent-child relationship identifier in the second data entry according to the auto-incrementing identifier in the third data entry.
[0109] In one embodiment, the repair module 1208, when the target node is not the root node, repeatedly executes the step of repairing the parent-child relationship identifiers in the processed variable table until the repair of the parent-child relationship identifiers that are not corresponding to the root node in the processed variable table is completed.
[0110] In the above embodiments, the data in the first variable table to be migrated is first written into the second variable table. The parent-child relationship identifier in the second variable table is modified according to the auto-increment identifier in the second variable table. The modified second variable table is then inserted into the target data table, and the auto-increment identifier in the inserted second variable table is incremented according to a preset auto-increment strategy to obtain the processed variable table. The parent-child relationship identifier in the processed variable table is then repaired according to the processed auto-increment identifier. Therefore, it is not necessary to add a new field in the target data table to store the auto-increment identifier in the first variable table. The repaired target data table can be obtained without changing the structure of the target data table, thus smoothly completing the data migration. This helps to reduce code redundancy and workload, and also effectively avoids the impact of structural changes on the data in the target data table, thereby improving the speed of data migration.
[0111] Each module in the aforementioned data migration device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0112] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 13 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores a first variable table, a second variable table, and a target data table. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements a data migration method.
[0113] Those skilled in the art will understand that Figure 13 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0114] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the data migration method described above.
[0115] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the data migration method described above.
[0116] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps of the data migration method described above.
[0117] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0118] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0119] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A data migration method, characterized by, The method includes: Write the data from the first variable table into the second variable table; the data in the first variable table and the data in the second variable table are tree structure data, and the data in the first variable table and the data in the second variable table both contain an auto-incrementing identifier, the data to be migrated, and a parent-child relationship identifier that represents the parent-child relationship between the data to be migrated in the same table. The auto-incrementing identifier is a number used to indicate the position of the data to be migrated in the variable table, and the number is automatically updated after the data migration. Modify the parent-child relationship identifier in the second variable table to the auto-incrementing identifier in the second variable table to obtain the modified second variable table; The target data table is read from the target database according to the read instruction, the modified second variable table is inserted into the target data table, and the auto-incrementing identifier in the inserted second variable table is incremented according to the preset auto-incrementing strategy to obtain the processed variable table; The parent-child relationship identifiers in the processed variable table are repaired based on the processed auto-incrementing identifiers to obtain a repaired target data table. This includes: searching for data corresponding to the target node in the first variable table to obtain a first data entry; searching for data in the processed variable table whose parent-child relationship identifier is equal to the auto-incrementing identifier in the first data entry to obtain a second data entry; searching for data in the processed variable table whose parent-child relationship identifier is the same as the parent-child relationship identifier in the first data entry to obtain a third data entry; and repairing the parent-child relationship identifiers in the second data entry based on the auto-incrementing identifier in the third data entry. The repaired target data table is stored.
2. The method according to claim 1, characterized in that, The step of writing data from the first variable table into the second variable table includes: Load the data from the data table to be migrated into the first variable table; Write the auto-incrementing identifier, the data to be migrated, and the parent-child relationship identifier from the first variable table to the second variable table.
3. The method according to claim 1, characterized in that, The step of modifying the parent-child relationship identifier in the second variable table based on the auto-incrementing identifier in the second variable table includes: Read the auto-incrementing identifier from the second variable table; Modify the parent-child relationship identifier in the second variable table to the read auto-incrementing identifier; or... The parent-child relationship identifier corresponding to the non-root node is found in the second variable table, and the parent-child relationship identifier corresponding to the non-root node is modified to the read auto-incrementing identifier.
4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: Receive data migration request initiated by the terminal; Run the corresponding computer program according to the data migration request, and create the first variable table and the second variable table through the computer program.
5. The method according to claim 1, characterized in that, The method further includes: When the target node is not the root node, the step of repairing the parent-child relationship identifier in the processed variable table is executed repeatedly until the repair of the parent-child relationship identifier corresponding to the non-root node in the processed variable table is completed.
6. A data migration device, characterized in that, The device includes: The writing module is used to write data from the first variable table into the second variable table. The data in the first variable table and the data in the second variable table are both tree-structured data. The data in the first variable table and the data in the second variable table both contain an auto-incrementing identifier, the data to be migrated, and a parent-child relationship identifier that represents the parent-child relationship between the data to be migrated in the same table. The auto-incrementing identifier is a number used to indicate the position of the data to be migrated in the variable table. The number is automatically updated after the data is migrated. The modification module is used to modify the parent-child relationship identifier in the second variable table to an auto-incrementing identifier in the second variable table, thus obtaining the modified second variable table; The processing module is used to read the target data table from the target database according to the read instruction, insert the modified second variable table into the target data table, and perform auto-increment processing on the auto-increment identifier in the inserted second variable table according to the preset auto-increment strategy to obtain the processed variable table; The repair module is used to repair the parent-child relationship identifiers in the processed variable table based on the processed auto-incrementing identifiers to obtain a repaired target data table. The repair module includes: searching for data corresponding to the target node in the first variable table to obtain a first data entry; searching for data in the processed variable table whose parent-child relationship identifier is equal to the auto-incrementing identifier in the first data entry to obtain a second data entry; searching for data in the processed variable table whose parent-child relationship identifier is the same as the parent-child relationship identifier in the first data entry to obtain a third data entry; and repairing the parent-child relationship identifiers in the second data entry based on the auto-incrementing identifier in the third data entry. The storage module is used to store the repaired target data table.
7. The apparatus according to claim 6, characterized in that, The writing module is further configured to load data from the data table to be migrated into the first variable table; and to write the auto-incrementing identifier, the data to be migrated, and the parent-child relationship identifier from the first variable table into the second variable table.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.