A heterogeneous database object migration method and apparatus
By using syntax transformation rules and syntax tree parsing during heterogeneous database migration, object creation statements compatible with the target end are generated, solving the problem of insufficient syntax compatibility assessment during migration in existing technologies and achieving efficient and secure object migration.
Patent Information
- Application Number
- CN202611286115.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-24
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies lack a mechanism for pre-evaluating the syntax compatibility of object creation statements after conversion during the migration of heterogeneous database objects. This results in time-consuming and labor-intensive manual modifications or a lack of verification after automated conversion, which can easily lead to syntax errors and repeated trial and error.
By obtaining object definition information from the source database, field type mapping and keyword replacement are performed based on preset syntax conversion rules to generate object creation statements compatible with the target database. The syntax tree is then used for parsing to obtain syntax compatibility evaluation results, ensuring that the statements are only sent to the target for execution if they meet the requirements.
It automates the migration of heterogeneous database objects, eliminating the need for manual modification, saving time and manpower costs, identifying and fixing incompatibility issues in advance, ensuring the security and controllability of the migration, and improving migration efficiency.
Smart Images

Figure CN123157683A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for migrating heterogeneous database objects. Background Technology
[0002] As domestic databases gradually replace non-domestic databases, database migration has become an important issue in the field of database operation and maintenance. In the process of database migration, it is usually divided into two stages: first, object migration and then data migration. However, due to differences in implementation architecture, design philosophy and operation mechanism, databases from different vendors have significant differences in the syntax of Structured Query Language (SQL). Object definition statements that can be executed correctly in the source database often cannot be directly executed in the target database due to syntax incompatibility.
[0003] In related technologies, mainstream heterogeneous database object migration solutions mainly include the following types: the first is manual modification, the second is automated conversion based on mapping rules, and the third is a standardized solution based on intermediate models. However, for manual modification, when the number of objects to be migrated is large, manual modification requires a lot of time and manpower; for automated conversion based on mapping rules, although it can automatically complete most of the syntax conversion, there is a lack of effective pre-verification mechanisms to ensure that the converted statements are truly compatible with the target syntax; for standardized solutions based on intermediate models, although the source and target ends are decoupled through the intermediate model, the construction and maintenance costs of the intermediate model are high, and it also lacks a mechanism for pre-evaluating the syntax compatibility of the converted statements.
[0004] In summary, the relevant technologies lack a heterogeneous database object migration solution that can perform a pre-assessment of the syntax compatibility of the converted object creation statements based on automated syntax conversion, thereby discovering and locating incompatibility issues in advance before formal execution and avoiding repeated trial and error. Summary of the Invention
[0005] This application provides a method and apparatus for migrating heterogeneous database objects, which can efficiently complete the migration of objects from heterogeneous databases.
[0006] Firstly, this application provides a method for migrating heterogeneous database objects, the method comprising: Obtain the object definition information of the object to be migrated from the source database; Based on preset syntax conversion rules, the object definition information is processed by field type mapping and keyword replacement to generate an object creation statement that conforms to the target database syntax rules; The syntax tree is used to parse the object creation statement to obtain the syntax compatibility evaluation result; If the syntax compatibility assessment result meets the preset conditions, the object creation statement is sent to the target database to complete the object migration.
[0007] In an optional embodiment of this application, before obtaining the object definition information of the object to be migrated from the source database, the method further includes: Create an object migration task, which includes a source database, a target database, and an object whitelist. The object whitelist includes pre-selected objects to be migrated in the source database, and the target database is a GoldenDB database.
[0008] In one optional embodiment of this application, obtaining the object definition information of the object to be migrated from the source database includes: When the objects to be migrated in the source database include table objects, the metadata information of the table objects is obtained and the metadata information is used as object definition information. The metadata information includes at least column information, index information, comment information, foreign key information, and constraint information. When the object to be migrated includes a non-table object, the definition statement of the non-table object is obtained and the definition statement is used as object definition information.
[0009] In one optional embodiment of this application, based on preset syntax conversion rules, field type mapping and keyword replacement processing are performed on the object definition information to generate an object creation statement that conforms to the target database syntax rules, including: Select syntax transformation rules that match the objects to be migrated from the rule management platform. The syntax transformation rules include at least field type conversion rules and keyword replacement rules. When the object definition information is metadata information, the field types associated with column information in the metadata information are converted according to the field type conversion rules, and all information in the converted metadata information is concatenated to obtain the object creation statement; When the object definition information is a definition statement, the keywords in the definition statement are replaced according to the keyword replacement rules to obtain the object creation statement.
[0010] In an optional embodiment of this application, the object creation statement is parsed using a syntax tree to obtain a syntax compatibility evaluation result, including: Construct a syntax tree for each of the object creation statements; Syntax parsing is performed on each syntax node in the syntax tree to obtain the syntax compatibility evaluation result.
[0011] In an optional embodiment of this application, the method further includes: Obtain the dependent object information for each of the object creation statements; If the syntax compatibility assessment results meet the preset conditions, based on the dependent object information, each object creation statement is sent to the target database in the order of dependency.
[0012] In an optional embodiment of this application, the method further includes: If the syntax compatibility assessment result does not meet the preset conditions, the object creation statement is modified according to the incompatibility information in the syntax compatibility assessment result, and the steps of parsing the object creation statement through the syntax tree are repeated until the syntax compatibility assessment result meets the preset conditions.
[0013] Secondly, this application provides a heterogeneous database object migration apparatus, the apparatus comprising: The acquisition module is used to obtain the object definition information of the objects to be migrated from the source database; The adjustment module is used to perform field type mapping and keyword replacement processing on the object definition information based on preset syntax conversion rules, and generate an object creation statement that conforms to the target database syntax rules; The parsing module is used to parse the object creation statement through a syntax tree to obtain the syntax compatibility evaluation result; The sending module is used when the syntax compatibility assessment result meets preset conditions. Next, the object creation statement is sent to the target database to complete the object migration.
[0014] In an optional embodiment of this application, the apparatus further includes a creation module, configured to: Create an object migration task, which includes a source database, a target database, and an object whitelist. The object whitelist includes pre-selected objects to be migrated in the source database, and the target database is a GoldenDB database.
[0015] In an optional embodiment of this application, the acquisition module is further configured to: When the objects to be migrated in the source database include table objects, the metadata information of the table objects is obtained and the metadata information is used as object definition information. The metadata information includes at least column information, index information, comment information, foreign key information, and constraint information. When the object to be migrated includes a non-table object, the definition statement of the non-table object is obtained and the definition statement is used as object definition information.
[0016] In an optional embodiment of this application, the adjustment module is further configured to: Select syntax transformation rules that match the objects to be migrated from the rule management platform. The syntax transformation rules include at least field type conversion rules and keyword replacement rules. When the object definition information is metadata information, the field types associated with column information in the metadata information are converted according to the field type conversion rules, and all information in the converted metadata information is concatenated to obtain the object creation statement; When the object definition information is a definition statement, the keywords in the definition statement are replaced according to the keyword replacement rules to obtain the object creation statement.
[0017] In an optional embodiment of this application, the parsing module is further configured to: Construct a syntax tree for each of the object creation statements; Syntax parsing is performed on each syntax node in the syntax tree to obtain the syntax compatibility evaluation result.
[0018] In an optional embodiment of this application, the acquisition module is further configured to: Obtain the dependent object information for each of the object creation statements; If the syntax compatibility assessment results meet the preset conditions, based on the dependent object information, each object creation statement is sent to the target database in the order of dependency.
[0019] In an optional embodiment of this application, the apparatus further includes a modification module, configured to: If the syntax compatibility assessment result does not meet the preset conditions, the object creation statement is modified according to the incompatibility information in the syntax compatibility assessment result, and the steps of parsing the object creation statement through the syntax tree are repeated until the syntax compatibility assessment result meets the preset conditions.
[0020] Thirdly, this application provides a heterogeneous database object migration device, comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the processor is configured to: Obtain the object definition information of the object to be migrated from the source database; Based on preset syntax conversion rules, the object definition information is processed by field type mapping and keyword replacement to generate an object creation statement that conforms to the target database syntax rules; The syntax tree is used to parse the object creation statement to obtain the syntax compatibility evaluation result; If the syntax compatibility assessment result meets the preset conditions, the object creation statement is sent to the target database to complete the object migration.
[0021] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described heterogeneous database object migration method.
[0022] Compared with related technologies, the technical solution provided in this application has the following advantages: obtaining object definition information of the object to be migrated from the source database; performing field type mapping and keyword replacement processing on the object definition information based on preset syntax conversion rules to generate an object creation statement that conforms to the syntax rules of the target database; parsing the object creation statement through a syntax tree to obtain a syntax compatibility evaluation result; and sending the object creation statement to the target database when the syntax compatibility evaluation result meets preset conditions to complete the object migration.
[0023] As can be seen, this application achieves automated conversion of object definition syntax between heterogeneous databases, eliminating the need for manual modification and significantly saving time and manpower costs. Before formal replay, this application pre-verifies the syntax compatibility of statements, enabling early detection and location of incompatibility issues, thus avoiding interruptions and repeated trial and error caused by direct execution. This application only sends object creation statements to the target database for execution when the evaluation result meets the conditions, ensuring the security and controllability of replay execution. Furthermore, when the evaluation result does not meet the conditions, this application provides a closed-loop mechanism for modification and re-parsing, allowing users to make targeted modifications based on the clearly identified problem locations and repair suggestions in the evaluation report until all critical issues are resolved. Attached Figure Description
[0024] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0025] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, those skilled in the art can obtain other drawings based on these drawings without creative effort.
[0026] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0027] Figure 1 A flowchart illustrating a heterogeneous database object migration method provided in an embodiment of this application; Figure 2 This is a flowchart illustrating the process of obtaining object definition information in a heterogeneous database object migration method provided in an embodiment of this application. Figure 3 A flowchart illustrating the generation of object creation statements in a heterogeneous database object migration method provided in this application embodiment; Figure 4 A schematic diagram illustrating the compatibility assessment process in a heterogeneous database object migration method provided in this application embodiment; Figure 5 A flowchart illustrating a heterogeneous database object migration device provided in this application embodiment; Figure 6 This is a schematic diagram of a heterogeneous database object migration device provided in an embodiment of this application. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0029] The following disclosure provides numerous different embodiments or examples for implementing various structures of this application. To simplify the disclosure, specific examples of components and arrangements are described below. These are merely examples and are not intended to limit the scope of this application. Furthermore, reference numerals and / or letters may be repeated in different examples. Such repetition is for simplification and clarity and does not in itself indicate a relationship between the various embodiments and / or arrangements discussed.
[0030] In related technologies, object migration between heterogeneous databases typically relies on manual modification of source-side object definition statements to adapt to the target-side syntax specifications. When the number of objects to be migrated is large, manual modification is time-consuming, costly, and prone to introducing syntax errors due to oversight, making it difficult to guarantee migration quality. Furthermore, while existing automated conversion schemes based on mapping rules can automatically complete syntax conversion, they lack a pre-validation mechanism for the converted statements. When the statements are executed directly on the target side, any errors will interrupt playback, requiring repeated trial and error, further reducing migration efficiency. This application provides a method for migrating heterogeneous database objects, which can solve the above-mentioned problems in related technologies.
[0031] In summary, this application provides a method for migrating objects from heterogeneous databases. This method can efficiently complete the migration of objects from heterogeneous databases, such as... Figure 1 As shown, the specific steps include: The system architecture used in this application embodiment includes a source database, a target database, and a management platform. The source database is the source database of the object to be migrated, which can be a database such as Oracle or DB2. The target database is the destination database for object migration, specifically a GoldenDB database. The management platform is deployed between the source and target ends and has built-in rule management module, collection and adaptation module, syntax parsing engine, and playback execution engine to execute the heterogeneous database object migration method provided in this application embodiment.
[0032] Before officially executing the object migration task, users need to perform the following preprocessing operations: Users can browse pre-configured syntax conversion rule packages on the rule management page of the management platform. These rule packages are organized and displayed by category, including: data type mapping rules such as mapping VARCHAR2 to VARCHAR, NUMBER to DECIMAL, function substitution rules such as replacing NVL with COALESCE, and SYSDATE with CURRENT_TIMESTAMP, keyword substitution rules, and special object adaptation rules. If the user does not make any modifications to the pre-configured rules, the management platform will directly use these pre-configured rules as the default syntax conversion rules in subsequent conversion processes. If, after analysis, the user believes that the pre-configured rules do not fully cover the specific needs of this migration scenario, such as the use of Oracle-specific custom functions in a certain business, or the need to adjust the mapping method of a certain field type according to business semantics, the user can manually add custom rules on the rule management page or modify and adjust existing rules. After the modifications are completed, the management platform will store the final confirmed rule set in the platform database and mark it as the effective rule version for this migration task. In other words, the pre-configured rules of this application are directly available as the default configuration, while also supporting user customization as needed, achieving a unity of out-of-the-box use and flexible customization.
[0033] Users can view query templates for collecting metadata information from the source database on the data source adaptation page of the management platform. These templates are a set of predefined SQL statements used to extract metadata such as column information, index information, and constraint information from the system views of the source database. This part of the operation is essentially the technical preparation for the core step S101 of this application. Since the system table structures of different database versions may differ, users need to verify whether the template is applicable to the current source version. For example, the field names of some system views may differ between Oracle 9i and Oracle 19c, and some views may exist or not exist in different versions. If differences are found, users can directly edit the SQL template on the page, replacing incompatible field names or view names with the corresponding names in the current version. After editing, users click the test connection, and the management platform executes a sample query to verify whether the template correctly returns results. After successful verification, the template is saved for use in subsequent data collection steps. If the user does not make any modifications, the management platform uses the system's default query template.
[0034] On the task management page of the management platform, users first select the pre-configured source database connection from the drop-down list, such as Oracle 19c, which includes information such as host address, port, service name, account password, and target database connection. Then, the management platform automatically connects to the source database, pulls a list of all migrateable objects, and displays it to the user in a graphical interface. Users then select the objects to be migrated one by one according to the actual business needs of this migration project, thus forming an object whitelist.
[0035] S101. Obtain the object definition information of the object to be migrated from the source database.
[0036] In this embodiment of the application, the objects to be migrated refer to various database objects in the source database that need to be migrated to the target database, which may include table objects, view objects, stored procedure objects, function objects, trigger objects, sequence objects, and package objects, etc.
[0037] In this step, we first determine whether the objects to be migrated from the source database in the object whitelist are table objects, non-table objects, or both. When the objects to be migrated from the source database include table objects, we obtain the metadata information of the table objects and use this metadata information as object definition information. The metadata information includes at least column information, index information, comment information, foreign key information, and constraint information. When the objects to be migrated include non-table objects, we obtain the definition statements of the non-table objects, i.e., DDL statements, and use these definition statements as object definition information. Non-table objects include view objects, stored procedure objects, function objects, trigger objects, sequence objects, and package objects, etc. Since non-table objects contain complex business logic, breaking them down into fragmented metadata and then reassembling them would likely result in lost logic or incorrect structure. Therefore, we adopt a strategy of collecting complete definition statements and replacing keywords for non-table objects.
[0038] Furthermore, after all objects to be migrated are collected, an object collection list is automatically generated. The number of objects of each type collected is then counted and compared with the number of objects of each type in the object whitelist to ensure that the number collected is consistent with the number in the whitelist. If a discrepancy is found, the management platform generates an alarm and lists the missing objects, notifying the user to check the source database connection permissions or whether the objects exist.
[0039] S102. Based on preset syntax conversion rules, perform field type mapping and keyword replacement processing on object definition information to generate object creation statements that conform to the target database syntax rules.
[0040] In this embodiment, object creation statements refer to DDL statements that can be successfully executed in the target GoldenDB database, such as CREATE TABLE statements and CREATE PROCEDURE statements. Since the source database and the target database differ in terms of data types, function names, keywords, and syntax structures, directly using the object definition information from the source database to execute on the target database will result in syntax errors. Therefore, it is necessary to eliminate syntax differences through conversion processing.
[0041] In this step, syntax conversion rules matching the object to be migrated are selected from the rule management platform. These rules include at least field type conversion rules and keyword replacement rules. When the object definition information is metadata information, the field types associated with the column information in the metadata information are converted according to the field type conversion rules, and all information in the converted metadata information is concatenated to obtain the object creation statement. When the object definition information is a definition statement, the keywords in the definition statement are replaced according to the keyword replacement rules to obtain the object creation statement.
[0042] S103. Parse the object creation statement using the syntax tree to obtain the syntax compatibility evaluation result.
[0043] In this embodiment, although the object creation statement obtained after conversion has been processed by syntax conversion rules, there may still be cases where the conversion rules are not covered or are not fully compatible. For example, some special functions may not be covered by keyword replacement rules, the length of some fields may exceed the maximum length supported by the target end after conversion, and the table referenced by the foreign key may not be in the migration whitelist. Therefore, it is necessary to perform a syntax compatibility pre-assessment on these statements before formal playback to identify potential problems in advance and avoid interruptions caused by syntax errors when executing directly on the target end.
[0044] In this step, a syntax tree is constructed for each object creation statement. Then, each syntax node in the syntax tree is parsed to obtain the syntax compatibility evaluation results.
[0045] S104. If the syntax compatibility assessment results meet the preset conditions, send the object creation statement to the target database to complete the object migration.
[0046] In this step, the prerequisite is that there are no fatal issues in the syntax compatibility evaluation results of all object creation statements. If fatal issues exist, direct replay will inevitably fail. Therefore, the system mandates that all fatal issues be cleared before replay execution can proceed. Specifically, it determines whether the syntax compatibility evaluation results meet the prerequisites. If they do, the object creation statements are sent to the target database. If they do not meet the prerequisites, the user modifies each problematic object creation statement in the statement editing interface of the management platform based on the detailed problem list in the compatibility evaluation report. For example, for the VARCHAR(20000) length exceeding the limit issue marked in the evaluation report, the user can change the field type to TEXT; for the missing dependency issue, the user adds the dependency table to the whitelist or adjusts the reference relationships in the statement.
[0047] Furthermore, after the user completes the modifications, clicking the "Re-parse" button in the editing interface causes the management platform to repeat the syntax tree parsing steps of S103 and regenerate the syntax compatibility assessment results. The user can repeat this cycle of modification and re-parsing until all critical issues are resolved and the assessment results meet preset conditions. In addition, the management platform provides a modification log recording function during the modification process, automatically recording the content before modification, the content after modification, the modification time, and the reason for modification for each statement, facilitating subsequent auditing and traceability.
[0048] Furthermore, after the syntax compatibility assessment results meet the preset conditions, the AST of each object creation statement is traversed, and information on all external objects referenced in the statement is extracted. Specifically, for table objects, the parent table referenced by foreign key constraints is extracted; for views, the base table referenced in their SELECT statements is extracted; and for stored procedures and functions, the tables referenced in their statement bodies and other stored procedures / functions called are extracted. Next, the extracted dependent objects are compared with the whitelist of objects to be migrated. If the dependent object is in the whitelist, the dependency relationship can be satisfied in this migration; if the dependent object is not in the whitelist, it is determined that the current object has a missing external dependency problem, and its dependent objects must be included in the migration scope and created on the target side before the current object can be created.
[0049] Subsequently, in cases of missing external dependencies, the management platform automatically generates a prompt displaying a list of missing dependency objects to the user and suggesting that the user add the dependency objects to the whitelist. After user confirmation, the management platform appends the dependency objects to the whitelist and repeats the collection, transformation, and parsing steps S101 to S103 to ensure that newly added dependency objects have also completed transformation and compatibility assessment. Once all dependency objects are in the whitelist and have passed the compatibility assessment, the replay execution engine uses a topological sorting algorithm to sort all object creation statements according to their dependencies, ensuring that the creation statements of the dependent objects are executed before the statements of the dependent objects. For example, if ACCOUNT_TABLE is referenced by a foreign key in ORDER_TABLE, then the table creation statement of ACCOUNT_TABLE is executed before ORDER_TABLE; if the stored procedure CALC_INTEREST calls the function GET_RATE, then the creation statement of GET_RATE is executed before CALC_INTEREST.
[0050] After sorting by dependency order, the statements are divided into multiple dependency levels. The first level consists of statements that do not depend on any other objects, the second level consists of statements that depend only on objects from the first level, and so on. Statements within the same level have no dependencies on each other, thus allowing for safe concurrent execution. Concurrent execution employs a multi-threaded approach, assigning object creation statements within the same level to different execution threads. Each thread connects to GoldenDB and executes the statements in parallel. For example, a fixed-size thread pool is started, and execution is scheduled layer by layer from lowest to highest dependency level. For multiple statements within the same level, they are distributed to idle threads in the thread pool for parallel execution. Dynamic scheduling by the thread pool ensures balanced load across all threads.
[0051] This application's combined strategy of dependency ordering and intra-level concurrency ensures the correct execution order of dependent statements, preventing execution failures due to non-existent objects during replay; simultaneously, it maximizes the high-performance advantages of concurrent execution, avoiding efficiency bottlenecks caused by simple serial execution. Since all statements to be executed are DDL creation statements, their execution result is the creation of database object structures on the target side, without involving transactional consistency requirements for business data. Therefore, concurrent execution within the same level does not present data consistency issues.
[0052] In the embodiments of this application, such as Figure 2 As shown in the figure, this application embodiment provides a flowchart of obtaining object definition information in a heterogeneous database object migration method, and the specific steps include: S201. When the objects to be migrated in the source database include table objects, obtain the metadata information of the table objects and use the metadata information as object definition information. The metadata information includes at least column information, index information, comment information, foreign key information, and constraint information.
[0053] In this step, when the object to be migrated is a table object, the metadata information of the table object is extracted in batches from the system view of the source database using the previously confirmed query template SQL. Taking Oracle database as an example, the following operations can be performed: The ALL_TAB_COLUMNS view extracts column information from the table, including column name (COLUMN_NAME), field type (DATA_TYPE), data length (DATA_LENGTH), precision (DATA_PRECISION), decimal places (DATA_SCALE), and whether it can be nullable (NULLABLE). The ALL_INDEXES and ALL_IND_COLUMNS views extract index information, including index name, index type, index fields, and sort order. The ALL_CONSTRAINTS and ALL_CONS_COLUMNS views extract constraint information, including primary key constraints (PRIMARY KEY), foreign key constraints (FOREIGNKEY), unique constraints (UNIQUE), and check constraints (CHECK). The ALL_COL_COMMENTS and ALL_TAB_COMMENTS views extract table and column comment information. All collected metadata is then grouped by table name and stored in the middleware database built into the management platform, with each record labeled with the name of the table object it belongs to.
[0054] S202. When the object to be migrated includes non-table objects, obtain the definition statement of the non-table objects and use the definition statement as object definition information.
[0055] In this step, when the object to be migrated is a non-table object, the complete original definition statement is directly extracted through the metadata interface of the source database. Taking Oracle database as an example, the definition statement is obtained using the DBMS_METADATA.GET_DDL interface. Then, the obtained definition statement is stored in the middleware database in complete text form, and the object name and object type are marked.
[0056] In the embodiments of this application, such as Figure 3 As shown in the figure, this application embodiment provides a flowchart illustrating the generation of object creation statements in a heterogeneous database object migration method. The specific steps include: S301. Select syntax conversion rules that match the object to be migrated from the rule management platform. The syntax conversion rules shall include at least field type conversion rules and keyword replacement rules.
[0057] In this step, the management platform loads the corresponding syntax conversion rules from the rule management module based on the conversion rule set ID in the task record. These conversion rules have been viewed and confirmed by the user during preprocessing and include at least field type conversion rules and keyword replacement rules.
[0058] For example, field type conversion rules could include: mapping VARCHAR2(n) to VARCHAR(n), mapping NUMBER(p,s) to DECIMAL(p,s), and mapping CLOB to TEXT, etc.; keyword substitution rules could include: replacing the keyword SYSDATE with CURRENT_TIMESTAMP, and replacing NVL(x, y) with COALESCE(x, y), etc. Furthermore, syntax conversion rules can also include special object adaptation rules. For instance, Oracle supports package structures, while GoldenDB does not. Therefore, the adaptation rules break down Oracle packages into independent functions and stored procedures, generating corresponding creation statements for each.
[0059] S302. When the object definition information is metadata information, the field types associated with the column information in the metadata information are converted according to the field type conversion rules, and all the information in the converted metadata information is concatenated to obtain the object creation statement.
[0060] In this step, when the object definition information is metadata information, the metadata information belonging to the same table is summarized, and then the following processing is performed: First, all column information records of the table object are traversed, and the source data type of each column is converted to the corresponding data type of the target according to the loaded field type conversion rules. If a mapping rule for a certain field type does not exist during the conversion process, a warning message is recorded to prompt the user to supplement the mapping rule. Second, after the field type conversion is completed, according to the table creation syntax specification of the GoldenDB database, all the converted metadata information corresponding to the table object is concatenated into a complete CREATE TABLE statement, which is used as the object creation statement. For example, the concatenation order is as follows: concatenate the table header, concatenate each column definition one by one, concatenate the primary key definition, concatenate the unique constraint definition, concatenate the foreign key constraint definition, and concatenate the index definition, etc.
[0061] S303. When the object definition information is a definition statement, the keywords in the definition statement are replaced according to the keyword replacement rules to obtain the object creation statement.
[0062] In this step, when the object definition information is a definition statement, keyword replacement is performed on the definition statement without changing its overall structure. Specifically, the definition statement text is scanned, and according to the aforementioned loaded keyword replacement rules, each matching source keyword is replaced with a target-compatible syntax. After the replacement is complete, the replaced complete definition statement is output as the object creation statement.
[0063] In the embodiments of this application, such as Figure 4 As shown in the figure, this application embodiment provides a flowchart of compatibility assessment in a heterogeneous database object migration method, and the specific steps include: S401. Construct the syntax tree corresponding to each object creation statement.
[0064] In this step, the management platform has a built-in GoldenDB-specific syntax parser developed based on ANTLR4. This parser defines a complete GoldenDB DDL syntax rule file, which includes lexical and syntax rules for various DDL statements such as CREATE TABLE, CREATE PROCEDURE, CREATE FUNCTION, CREATE VIEW, and CREATE INDEX.
[0065] Then, each generated object creation statement is taken as input and parsed by a syntax parser. The parser performs lexical and syntactic analysis on the input statement to generate a corresponding syntax tree. The syntax tree represents the syntax structure of the statement in a tree-like data structure. The root node is the statement type, and the child nodes are broken down into various syntactic units of the statement, such as table name, column definition, data type, constraint definition, index definition, etc.
[0066] S402. Perform syntax parsing on each syntax node in the syntax tree to obtain the syntax compatibility evaluation results.
[0067] In this step, the parser traverses each syntax node of the syntax tree corresponding to each object creation statement. First, it determines whether the statement's syntax structure fully conforms to the GoldenDB DDL syntax specification. For example, it checks if keywords are spelled correctly, parentheses match, the statement structure is complete, and necessary syntax units exist. If the syntax tree construction fails, a syntax validity error is identified. Second, it checks whether the data types of each column are supported in GoldenDB, whether the converted field length exceeds the maximum length supported by GoldenDB, and whether precision conversion might result in data loss. For example, the maximum length of VARCHAR in GoldenDB is 16383. If the source VARCHAR2(20000) is converted to VARCHAR(20000), it will exceed the length limit, requiring a type compatibility issue to be flagged and the user prompted to adjust.
[0068] The third step is to scan the syntax tree nodes and identify whether they contain functions, reserved words, or special keywords that GoldenDB does not support. If unsupported elements are found that are not covered by keyword replacement rules, they are marked as keyword compatibility issues. The fourth step is to verify whether the referenced object is in the whitelist of objects being migrated when the object creation statement contains references to external objects. If the referenced object is not in the whitelist, the statement will fail to execute due to the non-existent dependent object during replay on the target end. Such issues need to be identified and handled before replay.
[0069] The results of the above four types of verifications are summarized, and a corresponding syntax compatibility assessment result is generated for each object creation statement, which is then displayed to the user in HTML or PDF format. In addition, the syntax compatibility assessment result also includes basic information about the source database, such as database type, version, number of schemas, character set, etc.
[0070] In practical applications, taking the scenario of migrating a system from Oracle to GoldenDB as an example, the objects to be migrated include 127 business tables and 32 stored procedures. The business side creates a migration task on the management platform, selects the above 159 objects as the migration whitelist, and submits the task to the management platform.
[0071] First, the management platform connects to the Oracle 19c database using an account with SELECT ANY DICTIONARY privileges. Then, for table objects, it extracts metadata information for 127 tables in batches using the Oracle system view ALL_TAB_COLUMNS, extracts index information using ALL_INDEXES and ALL_IND_COLUMNS, extracts constraint information using ALL_CONSTRAINTS and ALL_CONS_COLUMNS, and extracts table and column comment information using ALL_COL_COMMENTS and ALL_TAB_COMMENTS. For non-table objects, it uses the DBMS_METADATA.GET_DDL interface to extract complete raw definition statements.
[0072] Next, the management platform loads the pre-configured syntax conversion rules, groups the metadata information of 127 tables by table name, and maps the field types for each table. After the field type conversion is completed, according to GoldenDB's table creation syntax specifications, all the converted metadata information of each table is concatenated into a complete CREATE TABLE statement. At the same time, keyword replacement processing is performed on the definition statements of 32 stored procedures. After keyword replacement, GoldenDB-compatible creation statements are generated. After the conversion, the management platform generates a total of 159 object creation statements.
[0073] Afterwards, the GoldenDB-specific syntax parser built into the management platform, based on ANTLR4, constructs an abstract syntax tree for each of the 159 object creation statements after conversion. Then, it traverses each syntax node to perform verification, summarizes the verification results, and generates a compatibility assessment report. Assuming the report shows that 156 statements pass the verification completely, 3 stored procedure statements have warning-level issues, no fatal issues, and meet the preset conditions.
[0074] Subsequently, after reviewing the compatibility assessment report and confirming that there were no fatal issues, the syntax tree of each statement was traversed to extract information on all external objects referenced in that statement. The extracted dependency objects were then compared and verified with the migration whitelist. Assuming that ORDER_TABLE depends on ACCOUNT_TABLE, ACCOUNT_TABLE was marked as a dependency of ORDER_TABLE. Finally, after a complete dependency analysis of all 159 statements, it was found that there were 80 foreign key dependencies and 32 stored procedures that referenced tables. Further verification revealed that all referenced objects were in the migration whitelist.
[0075] Then, all object creation statements are divided into 5 dependency levels based on their dependencies. The first level consists of statements that do not depend on any other objects, including 40 CREATE TABLE statements for base tables without foreign key dependencies, and 6 CREATE statements for stored procedures that do not reference any tables. The PROCEDURE layer contains 46 statements. All statements within this layer are independent of each other and can be executed concurrently. The second layer consists of 38 statements that depend solely on objects from the first layer, primarily business tables that use foreign keys to reference the base tables of the first layer. Statements in this layer also have no mutual dependencies and can be executed concurrently. The third layer contains 31 statements that depend on objects from the second layer. The fourth layer contains 12 stored procedures that perform read and write operations on tables and depend on objects from the third layer. The fifth layer contains the most complex business stored procedures, depending on multiple lower-level objects, totaling 32. Statements within the same layer are grouped according to their dependencies, and independent statements are assigned to different execution threads. Finally, a fixed-size thread pool of 16 is started, and execution is scheduled layer by layer from lowest to highest dependency level.
[0076] Ultimately, the management platform automatically connected to GoldenDB and queried the system views to verify the number of objects created, confirming that all 127 tables and 32 stored procedures had been successfully created. Throughout the migration process, users only needed to review the compatibility assessment report before playback. Manual intervention was limited to replacing the DECODE function with a CASE WHEN expression in three stored procedures. Compared to traditional manual modification methods, this significantly improved migration efficiency.
[0077] like Figure 5 As shown, this application embodiment provides a heterogeneous database object migration device, which corresponds to the method embodiment, and specifically includes: Module 501 is used to obtain the object definition information of the object to be migrated from the source database; The adjustment module 502 is used to perform field type mapping and keyword replacement processing on object definition information based on preset syntax conversion rules, and generate object creation statements that conform to the syntax rules of the target database. Parsing module 503 is used to parse object creation statements through a syntax tree to obtain syntax compatibility evaluation results; Sending module 504 is used when the syntax compatibility assessment result meets preset conditions. Next, the object creation statement is sent to the target database to complete the object migration.
[0078] In an optional embodiment of this application, the apparatus further includes a creation module 505, configured to: Create an object migration task. The object migration task includes a source database, a target database, and an object whitelist. The object whitelist includes pre-selected objects to be migrated in the source database, and the target database is the GoldenDB database.
[0079] In an optional embodiment of this application, the acquisition module 501 is further configured to: When the objects to be migrated in the source database include table objects, obtain the metadata information of the table objects and use the metadata information as object definition information. The metadata information includes at least column information, index information, comment information, foreign key information, and constraint information. When the objects to be migrated include non-table objects, obtain the definition statements of the non-table objects and use the definition statements as object definition information.
[0080] In an optional embodiment of this application, the adjustment module 502 is further configured to: Select syntax conversion rules that match the objects to be migrated from the rule management platform. The syntax conversion rules include at least field type conversion rules and keyword replacement rules. When the object definition information is metadata information, convert the field types associated with the column information in the metadata information according to the field type conversion rules and concatenate all the information in the converted metadata information to obtain the object creation statement. When the object definition information is a definition statement, replace the keywords in the definition statement according to the keyword replacement rules to obtain the object creation statement.
[0081] In an optional embodiment of this application, the parsing module 503 is further configured to: Construct a syntax tree for each object creation statement; perform syntax parsing on each syntax node in the syntax tree to obtain the syntax compatibility evaluation results.
[0082] In an optional embodiment of this application, the acquisition module 501 is further configured to: Obtain the dependency object information for each object creation statement; if the syntax compatibility evaluation result meets the preset conditions, send each object creation statement to the target database in the dependency order based on the dependency object information.
[0083] In an optional embodiment of this application, the apparatus further includes a modification module 506, configured to: If the syntax compatibility assessment result does not meet the preset conditions, the object creation statement is modified based on the incompatibility information in the syntax compatibility assessment result, and the steps of parsing the object creation statement through the syntax tree are repeated until the syntax compatibility assessment result meets the preset conditions.
[0084] like Figure 6As shown in the figure, this application embodiment provides a heterogeneous database object migration device, including a processor 601, a communication interface 602, a memory 603, and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604. Memory 603 is used to store computer programs; In one embodiment of this application, when the processor 601 executes a program stored in the memory 603, it implements a heterogeneous database object migration method provided in any of the foregoing method embodiments, including: Obtain the object definition information of the object to be migrated from the source database; Based on preset syntax conversion rules, the object definition information is processed by field type mapping and keyword replacement to generate an object creation statement that conforms to the target database syntax rules; The syntax tree is used to parse the object creation statement to obtain the syntax compatibility evaluation result; If the syntax compatibility assessment results meet the preset conditions, the object creation statement is sent to the target database to complete the object migration.
[0085] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of migrating heterogeneous database objects as provided in any of the foregoing method embodiments.
[0086] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0087] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0088] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also include the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.
[0089] The above description is merely a specific embodiment of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A method for migrating heterogeneous database objects, characterized in that, The method includes: Obtain the object definition information of the object to be migrated from the source database; Based on preset syntax conversion rules, the object definition information is processed by field type mapping and keyword replacement to generate an object creation statement that conforms to the target database syntax rules; The syntax tree is used to parse the object creation statement to obtain the syntax compatibility evaluation result; If the syntax compatibility assessment result meets the preset conditions, the object creation statement is sent to the target database to complete the object migration.
2. The method according to claim 1, characterized in that, Before obtaining the object definition information of the object to be migrated from the source database, the method further includes: Create an object migration task, which includes a source database, a target database, and an object whitelist. The object whitelist includes pre-selected objects to be migrated in the source database, and the target database is a GoldenDB database.
3. The method according to claim 2, characterized in that, Obtain the object definition information of the object to be migrated from the source database, including: When the objects to be migrated in the source database include table objects, the metadata information of the table objects is obtained and the metadata information is used as object definition information. The metadata information includes at least column information, index information, comment information, foreign key information, and constraint information. When the object to be migrated includes a non-table object, the definition statement of the non-table object is obtained and the definition statement is used as object definition information.
4. The method according to claim 3, characterized in that, Based on preset syntax conversion rules, the object definition information is processed by field type mapping and keyword replacement to generate an object creation statement that conforms to the target database syntax rules, including: Select syntax transformation rules that match the objects to be migrated from the rule management platform. The syntax transformation rules include at least field type conversion rules and keyword replacement rules. When the object definition information is metadata information, the field types associated with column information in the metadata information are converted according to the field type conversion rules, and all information in the converted metadata information is concatenated to obtain the object creation statement; When the object definition information is a definition statement, the keywords in the definition statement are replaced according to the keyword replacement rules to obtain the object creation statement.
5. The method according to claim 1, characterized in that, The syntax tree is used to parse the object creation statement to obtain the syntax compatibility evaluation results, including: Construct the syntax tree corresponding to each of the object creation statements; Syntax parsing is performed on each syntax node in the syntax tree to obtain the syntax compatibility evaluation result.
6. The method according to claim 5, characterized in that, The method further includes: Obtain the dependent object information for each of the object creation statements; If the syntax compatibility assessment results meet the preset conditions, based on the dependent object information, each object creation statement is sent to the target database in the order of dependency.
7. The method according to claim 6, characterized in that, The method further includes: If the syntax compatibility assessment result does not meet the preset conditions, the object creation statement is modified according to the incompatibility information in the syntax compatibility assessment result, and the steps of parsing the object creation statement through the syntax tree are repeated until the syntax compatibility assessment result meets the preset conditions.
8. A heterogeneous database object migration device, characterized in that, The device includes: The acquisition module is used to obtain the object definition information of the objects to be migrated from the source database; The adjustment module is used to perform field type mapping and keyword replacement processing on the object definition information based on preset syntax conversion rules, and generate an object creation statement that conforms to the syntax rules of the target database. The parsing module is used to parse the object creation statement through a syntax tree to obtain the syntax compatibility evaluation result; The sending module is used when the syntax compatibility assessment result meets preset conditions. Next, the object creation statement is sent to the target database to complete the object migration.
9. A heterogeneous database object migration device, characterized in that, include: At least one communication interface; At least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; At least one memory connected to the at least one bus, wherein the processor is configured to: Obtain the object definition information of the object to be migrated from the source database; Based on preset syntax conversion rules, the object definition information is processed by field type mapping and keyword replacement to generate an object creation statement that conforms to the target database syntax rules; The syntax tree is used to parse the object creation statement to obtain the syntax compatibility evaluation result; If the syntax compatibility assessment result meets the preset conditions, the object creation statement is sent to the target database to complete the object migration.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements a heterogeneous database object migration method according to any one of claims 1 to 7.
