Code migration and merging methods, devices, electronic devices, and readable storage media
By using an automated code migration and merging method, and by using a pre-defined merging script to parse and merge engine code resource information, the problem of low efficiency in code migration and merging is solved, and efficient and accurate code merging is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2023-03-27
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, code migration and merging processes involve a large amount of repetitive work and errors caused by manual merging, resulting in low efficiency.
By running a preset merging script, the resource information of the engine code is obtained and parsed. The second engine code is migrated and merged into the first engine code according to the first engine format, realizing the automatic merging of functional code and resource statements and reducing manual intervention.
It automates code merging, reduces labor costs, improves merging efficiency, and lowers the error rate caused by manual merging, achieving the goal of one-time merging.
Smart Images

Figure CN116340345B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of communication technology, and in particular to a code migration and merging method, a code migration and merging apparatus, a corresponding electronic device, and a corresponding computer-readable storage medium. Background Technology
[0002] Differences exist between different versions of the code, resulting in different functional effects when the engine runs different versions of the code. This may manifest as the development of related new functions and / or the improvement of related old functions. Usually, the new engine code can be merged and modified with the old engine code.
[0003] In related technologies, when merging and modifying new engine code with old engine code, it is mainly done manually by merging and modifying each function separately. However, the manual merging method involves a lot of repetitive work, which is not only inefficient but also introduces errors caused by manual merging. Summary of the Invention
[0004] In view of the above problems, embodiments of the present invention are proposed to provide a code migration and merging method, a code migration and merging apparatus, a corresponding electronic device, and a corresponding computer-readable storage medium to overcome or at least partially solve the above problems.
[0005] This invention discloses a code migration and merging method, the method comprising:
[0006] In response to the code merging command, run the preset merging script to obtain the first engine code and the second engine code;
[0007] Obtain the first resource information of the first engine code and the second resource information of the second engine code;
[0008] The first engine format of the first engine code is determined based on the first resource information;
[0009] The second resource information is parsed according to the first engine format, and the first engine code is migrated and merged into the second engine code based on the parsed second resource information.
[0010] This invention also discloses a code migration and merging apparatus, the apparatus comprising:
[0011] The merge script execution module is used to respond to code merging commands, run preset merge scripts, and obtain the first engine code and the second engine code;
[0012] The resource information acquisition module is used to acquire the first resource information of the first engine code and the second resource information of the second engine code;
[0013] An engine format determination module is used to determine the first engine format of the first engine code based on the first resource information.
[0014] The code merging module is used to parse the second resource information according to the first engine format, and migrate and merge the first engine code into the second engine code based on the parsed second resource information.
[0015] This invention also discloses an electronic device, including: a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements any of the code migration and merging methods described above.
[0016] This invention also discloses a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the code migration and merging methods described above.
[0017] The embodiments of the present invention have the following advantages:
[0018] In this embodiment of the invention, a preset merging script can be executed in response to a code merging command. Through the preset merging script, the second resource information of the second engine code is parsed according to the first engine format of the first engine code. This achieves not only merging of corresponding resource statements while merging functional code, but also merging the first and second engine codes according to a unified format based on the parsing of the first engine format, thus realizing the migration and merging of the first and second engine codes. In the case of automatically merging localized functional code of the old engine to achieve a one-time merging goal, automation based on the preset merging script reduces labor costs, improves merging efficiency, and reduces the error rate caused by manual merging. Attached Figure Description
[0019] Figure 1 This is a flowchart illustrating the steps of an embodiment of the code migration and merging method of the present invention;
[0020] Figure 2 This is a flowchart illustrating the steps of another embodiment of the code migration and merging method of the present invention;
[0021] Figure 3 This is a schematic diagram illustrating an application scenario of code migration and merging provided in an embodiment of the present invention;
[0022] Figure 4 This is a schematic diagram of the merging process of table creation statements provided in an embodiment of the present invention;
[0023] Figure 5 This is a schematic diagram of the merging process of the export table statements provided in an embodiment of the present invention;
[0024] Figure 6 This is a schematic diagram of the merging process of functional codes provided in an embodiment of the present invention;
[0025] Figure 7 This is a schematic diagram of the positioning process manually modified according to an embodiment of the present invention;
[0026] Figure 8 This is a structural block diagram of an embodiment of a code migration and merging device according to the present invention. Detailed Implementation
[0027] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0028] In related technologies, when merging and modifying new engine code with old engine code, it is mainly done manually by merging and modifying each function separately. However, the manual merging method involves a lot of repetitive work, which is not only inefficient but also introduces errors caused by manual merging.
[0029] This invention utilizes scripts to efficiently migrate localized functions, eliminating the need for script redevelopment for subsequent merges. Specifically, by running a pre-defined merge script, which parses the second resource information according to the first engine's format, it not only merges the corresponding resource statements while merging functional code but also ensures a consistent code format. This automated approach to merging localized functional code from the old engine achieves a one-time merge, while reducing labor costs, increasing efficiency, and minimizing errors caused by manual merging.
[0030] Reference Figure 1 The diagram illustrates a flowchart of an embodiment of the code migration and merging method of the present invention, which may specifically include the following steps:
[0031] Step 101: Respond to the code merging instruction, run the preset merging script, and obtain the first engine code and the second engine code;
[0032] In this embodiment of the invention, a preset merging script can be run by responding to a code merging command through a client or a webpage of the client, thereby automatically merging the localization function code of the old engine.
[0033] In one embodiment of the present invention, the preset merging script may refer to a script for efficiently migrating localized functions. The obtained engine code may be the engine code to be merged, typically manifested as at least two engine codes before and after a function addition or update, such as a first engine code and a second engine code. The first engine code may refer to the engine code before the function addition or update, i.e., the old engine code, and the second engine code may refer to the engine code after the function addition or update, i.e., the new engine code. It should be noted that the embodiments of the present invention do not limit the number of engine codes to be merged; that is, at least one first engine code and at least one second engine code are allowed to be migrated and merged.
[0034] In practical applications, when merging engine code to be merged, the localized functional code and localized modifications of the old engine are typically merged into the new engine code. Specifically, this can be represented by merging the old localized functional code into the new original functional code. The localized functional code refers to the engine code that has been running for a period of time, while the original functional code refers to the newly developed engine code with new functionalities. In this embodiment of the invention, the first engine code representing the old engine code can be represented as the old localized functional code, and the second engine code representing the new engine code can be represented as the new original functional code. It should be noted that locally developed functionalities, i.e., localized functional code, will not have duplicate functionalities; if duplicate functionalities occur in the original functional code, the filename and class name in the functional code can be output to the modification file to be confirmed for deletion, so that relevant personnel can perform manual confirmation.
[0035] In practical applications, code merging instructions can be executed when the engine code is updated. For example, in response to the addition of features to the first engine code and / or an update to the second engine code, a code merging instruction is generated, which can then be used to run a pre-defined merging script. It should be noted that in the aforementioned example, the old engine code can be under continuous development, and the new engine code can also be continuously updated. In this case, the two different versions of engine code will coexist for a period of time.
[0036] Step 102: Obtain the first resource information of the first engine code and the second resource information of the second engine code;
[0037] Resource information for engine code can be information used to define engine code, i.e., reference information used by engine code, including table creation statement information, import table information, protocol documents, file information, etc.
[0038] In one embodiment of the present invention, first resource information of the first engine code and second resource information of the second engine code can be obtained so that the resource information can be parsed in a way that is suitable for merging the engine code.
[0039] Step 103: Determine the first engine format of the first engine code based on the first resource information;
[0040] The first engine format of the first engine code may differ from the second engine format of the second engine code. In order to maintain format consistency during subsequent code migration and merging, the corresponding first engine format of the first engine code can be determined based on the information format of relevant table creation statement information, import table information, protocol documents, file information, etc. in the first resource information, so that the engine format of the second engine code can be converted later.
[0041] In some embodiments of the present invention, the second engine format of the second engine code can be determined based on the information format of the relevant table creation statement information, table import information, protocol documents, file information, etc. in the second resource information, so as to transform the engine format of the first engine code and ensure the uniformity of the format when the code is migrated and merged.
[0042] Step 104: Parse the second resource information according to the first engine format, and migrate and merge the first engine code into the second engine code based on the parsed second resource information.
[0043] The engine format of the second engine code is transformed by parsing the second resource information of the second engine code, such as table creation statement information, table import information, protocol documents, and file information, according to the format of the first engine. The code migration and merging based on the second resource information obtained after parsing can ensure the uniformity of the format during code merging.
[0044] In practical implementation, the appropriate parsing for engine code merging can be manifested as parsing the second resource information according to the first engine format. While achieving format uniformity during code merging, it can also merge resource information including creation statement information, import table information, protocol documents, file information, etc., so as to merge the corresponding resource statements while merging the functional code, without having to manually merge the resource information after merging the functional code, thus achieving the purpose of one-time merging.
[0045] In one embodiment of the present invention, by running a preset merging script, the localized functional code of the old engine is automatically merged, and the localized functional code of the old engine and the localized modifications are merged into the new engine code. That is, the old localized functional code can be merged into the new original functional code, realizing the automatic migration and merging of the old and new engine code.
[0046] In this embodiment of the invention, a preset merging script can be executed in response to a code merging command. Through the preset merging script, the second resource information of the second engine code is parsed according to the first engine format of the first engine code. This achieves not only merging of corresponding resource statements while merging functional code, but also merging the first and second engine codes according to a unified format based on the parsing of the first engine format, thus realizing the migration and merging of the first and second engine codes. In the case of automatically merging localized functional code of the old engine to achieve a one-time merging goal, automation based on the preset merging script reduces labor costs, improves merging efficiency, and reduces the error rate caused by manual merging.
[0047] Reference Figure 2 The diagram illustrates a flowchart of another embodiment of the code migration and merging method of the present invention, which may specifically include the following steps:
[0048] Step 201: Merge the table creation statement information of the first engine code and the second engine code. The merged table creation statement information is used to represent the table creation statement information of the engine code obtained by merging the first engine code and the second engine code.
[0049] In this embodiment of the invention, a preset merging script can be run by responding to a code merging command through a client or a webpage of the client, thereby automatically merging the localization function code of the old engine.
[0050] In one embodiment of the present invention, the preset merging script may refer to the script for efficiently migrating localization functions, and the obtained engine code may be the engine code to be merged, wherein the first engine code may refer to the old engine code and the second engine code may refer to the new engine code.
[0051] In practical applications, code merging instructions can be executed when engine code is updated. For example, in response to a feature addition to the first engine code and / or an update to the second engine code, a code merging instruction is generated. Then, in response to the code merging instruction, a preset merging script is run. At this point, the first resource information of the first engine code and the second resource information of the second engine code can be obtained, facilitating subsequent parsing of the resource information to be appropriate for engine code merging. It should be noted that the purpose of parsing is to ensure a consistent format during code merging.
[0052] The resource information of the engine code can be information used to define the engine code, that is, the reference information used by the engine code, including table creation statement information, import table information, protocol documents, file information, etc.
[0053] The appropriate parsing of resource information for engine code merging can be expressed as determining the second engine format of the second engine code based on the second resource information, and parsing the first resource information of the first engine code according to the second engine format. Based on the parsed first resource information, resource information merging with unified format can be achieved when migrating and merging the first engine code and the second engine code.
[0054] Parsing resource information to achieve format uniformity during code merging can, in some embodiments of this application, manifest as parsing the table creation statement information of resource information. The parsing of the table creation statement information can be performed where the first resource information may include the first table creation statement information of the first engine code, and the second resource information may include the second table creation statement information of the second engine code. Specifically, this can be manifested as parsing the second table creation statement information according to the format of the first engine.
[0055] Specifically, the second table creation statement information can be parsed according to the first engine format to obtain the parsed second table creation statement information. Then, the first table creation statement information can be loaded, and the first table creation statement information and the parsed second table creation statement information can be merged to obtain the table creation statement information of the target database. This achieves the merging of the table creation statement information of the first engine code and the second engine code. That is, the merged table creation statement information can be used to represent the table creation statement information of the engine code based on the merged first engine code and the second engine code. In a preferred embodiment of the present invention, after obtaining the merged table creation statement information, this table creation statement information can be used as the table creation statement information of the merged engine code. When executing the merged engine code, the relevant SQL statements can be obtained from the merged table creation statement information.
[0056] For example, the table creation statement information can refer to the MySQL table creation statement in the engine code, such as `create table table_name`. The MySQL table creation statement can represent the functional and structural information of the engine code. Based on the merging process of the first table creation statement information and the parsed second table creation statement information, a one-time merging can be achieved without requiring manual merging of the corresponding SQL statements after functional merging. That is, a pre-defined merging script can be run to merge the corresponding SQL statements simultaneously with the functional code merging.
[0057] In the specific implementation, the table creation statement information exists in a corresponding macro definition table, which can point the storage of the table creation statement information to the corresponding database. Specifically, the macro definition table of the first table creation statement information corresponds to at least one first database, and the macro definition table of the parsed second table creation statement information corresponds to at least one second database. In the process of merging the first table creation statement information and the parsed second table creation statement information to obtain the table creation statement information of the target database, the target database to be merged from the first database can be determined from at least one second database. Then, the first table creation statement information of the at least one first database can be merged into the target database to be merged to generate the table creation statement information of the target database. It should be noted that the number of target databases to be merged can be more than one, and this embodiment of the invention does not limit this.
[0058] The identified target databases to be merged are primarily one or more of the second databases; that is, one or more of the first databases can be merged into the second database. In practical applications, the second table creation statement information (i.e., the new engine MySQL table creation file) is parsed, and then the second table creation statement information (i.e., the old engine MySQL table creation file) is exported and loaded. The old engine MySQL table creation file contains the databases corresponding to macro-defined tables. At this point, the new engine's table creation file can be parsed into the old engine's format, and the table creation statement information of the new and old engines can be merged according to the new engine's database to form the latest MySQL table creation statement information for different databases. For example, during the database merging process, assuming the first databases in the old engine MySQL table creation files are a, b, and c, and the second databases in the new engine MySQL table creation files are d and f, then the second databases b and f can be identified as the target databases. The first databases a and b in the old engine MySQL table creation files can be merged into the target database d, and the first database c can be merged into the target database f. Then, the corresponding init_d.SQL and init_f.SQL files are generated. The generated init_d.SQL and init_f.SQL files are the table creation statement information of the merged engine code, which can be used to represent the functional information and structural information of the merged engine code, respectively.
[0059] In a preferred embodiment of the present invention, to ensure compatibility with the server code and deployment structure of the new engine, and to also execute table creation statements in the target database, the following steps are taken: Assuming significant modifications (similar to refactoring) are made to the functionality and structure of the new engine code, localized modifications and functions from the old engine can be merged into the new engine code while retaining the original functionality (i.e., the new engine code). This also allows for a one-time merging of functional code and resource information, eliminating the need for manual merging of corresponding SQL statements after the functionality merge. It should be noted that the old engine code can be continuously under development, and the new engine code can also be continuously updated. In this case, if the new engine code is updated or new functions are added to the old engine code, the preset merging script can be run again to re-migrate and merge the engine code.
[0060] Step 202: Merge the export table information of the first engine code and the second engine code. The merged export table information is used to represent the export table information of the engine code obtained by merging the first engine code and the second engine code.
[0061] Parsing resource information to achieve format uniformity during code merging can, in some embodiments of this application, manifest as parsing the import table information of resource information. The parsing of the import table information can be performed by parsing the second import table information of the resource information according to the format of the first engine, where the first resource information may include the first import table information of the first engine code, and the second resource information may include the second import table information of the second engine code.
[0062] The exported table information refers to the configuration table information of the engine code, such as CSV (Comma-Separated Values) or XML (Extensible Markup Language) files. This configuration table information is primarily used to configure change data for planners and other personnel. For efficiency reasons, some file servers do not use it directly but need to convert it to other file formats for server use. In other words, the exported table information is mainly used to export all configuration tables to other file formats.
[0063] It should be noted that the import table methods of the old and new engine codes are different, and both have a large amount of code and are incompatible. In this case, it is usually necessary to refactor the import table process to be compatible with the configurations of the old and new engines, and to minimize the need to add new code when adding, deleting or modifying configurations in the old and new engines.
[0064] Specifically, the second export table information can be parsed according to the first engine format to obtain the parsed second export table statement information. Then, the first export table information is modified using the parsed second export table statement information to obtain the modified first export table information. At this point, the second engine format of the second engine code can be obtained, and the modified first export table information is modified according to the second engine format to obtain the merged export table information. The merged export table information can be used to represent the export table information of the engine code obtained by merging the first engine code and the second engine code. In a preferred embodiment of the present invention, after obtaining the merged export table information, this export table information can be used as the export table information of the merged engine code. When it is necessary to export the configuration table to a file of other format when executing the merged engine code, the merged export table information is used.
[0065] In practical applications, configuration tables from older engine code are generally more user-friendly, meaning they are more compatible than those from newer engine code. In this embodiment of the invention, the conversion method for the new engine code's configuration table can be adjusted to match that of the older engine code. This can be achieved by modifying the export table information of the new engine code to a generic API (Application Programming Interface). Specifically, the second export table information, i.e., the export table statement file of the new engine code, can be parsed to generate an old engine configuration table file (e.g., a CSV file) according to the old engine format (i.e., the first engine format). Then, an SQLite file for the server can be generated. At this point, the SQLite table creation structure needs to be known. However, the table creation structure of the new engine code's file differs from that of the old engine code; therefore, it can be modified to a unified table creation structure. Each CSV file contains a code file used to parse and generate SQLite insert statements (for efficient server queries). The parsing methods for the code files differ between the old and new engines. In this case, the old engine's export table statements and configuration table files can be generated. Then, by modifying the configuration table files in the old engine to conform to the new engine format, the parsing method can be unified.
[0066] Step 203: Merge the function codes of the first engine code and the second engine code. The merged function code is used to represent the function code of the engine code obtained by merging the first engine code and the second engine code.
[0067] The second resource information is parsed according to the format of the first engine, and the resource information is merged while merging the functional code of the first engine code and the second engine code.
[0068] In practical applications, when merging engine code to be merged, the localized functional code and localized modifications of the old engine are typically merged into the new engine code. Specifically, this can be represented by merging the old localized functional code into the new original functional code. The localized functional code refers to the engine code that has been running for a period of time, while the original functional code refers to the newly developed engine code with new functionalities. In this embodiment of the invention, the first engine code representing the old engine code can be represented as the old localized functional code, and the second engine code representing the new engine code can be represented as the new original functional code. It should be noted that locally developed functionalities, i.e., localized functional code, will not have duplicate functionalities; if duplicate functionalities occur in the original functional code, the filename and class name in the functional code can be output to the modification file to be confirmed for deletion, so that relevant personnel can perform manual confirmation.
[0069] Specifically, the first resource information of the first engine code may include a first protocol document, and the second resource information of the second engine code may include a second protocol document. At this time, the newly added protocol entry file in the second protocol document can be determined based on the second protocol document and the first protocol document. The determined newly added protocol entry file is added to the first protocol document to obtain the newly added first protocol document. Then, the file information of the second protocol document can be obtained. The obtained file information includes the name and class name of the executable file, the name and class name of the input / output check file, and the format of the database code file. At this time, the newly added protocol entry file, the first protocol document, can be modified according to the name and class name of the executable file, the name and class name of the input / output check file, and the format of the database code file to realize the merging of localized function code into the original function code.
[0070] The modified first protocol document can be used to represent the functional code of the engine code obtained by merging the first engine code and the second engine code. In a preferred embodiment of the present invention, after obtaining the modified first protocol document, since the modified first protocol document has added the protocol entry file newly added in the second protocol document, the modified first protocol document can be used as the protocol file of the merged engine code. When executing the merged engine code, the modified first protocol document can be used. The protocol document can usually represent the functional code of the engine code. At this time, the modified first protocol document can be executed to implement the relevant functions of the merged engine code.
[0071] In practical applications, all new protocol entry files can be added, the names and class names of the old engine protocol execution files can be modified, the names and class names of the old engine protocol input / output check files can be modified, and the format of the database code files in the old engine code can be modified. For example, the newly implemented protocol entry files mainly inherit from a parent class. The parent class has input / output check functions, initialization functions, and a `run` method for protocol execution (used to execute the code specified in the `run()` method). If the function only provides the filename to be executed by `run`, such as `Cmd::run(args)`, the protocol entry only provides the name `Cmd` (Command Prompt). In this case, protocol entry files can be uniformly generated based on the old engine's protocol documentation. For example, if the old engine's protocol documentation is `cmd_mod_act`, a `gate_cmd_mod_act` file can be generated. This file inherits from the protocol processing parent class and provides `cmd="cmd_mod_act"`.
[0072] The modification to the database code file format in the old engine's code is primarily for compatibility with the new engine's structure. For example, the old engine's access protocol flow was as follows: the client sends a protocol number, such as `cmdSend`, followed by the content; the server receives this and executes `cmdSend(args):cmdSend::checkInput(args); run(args),cmdSend::checkoutput()`. The new engine changes this to: the client sends a protocol number, such as `cmdSend`, followed by the content; the server receives this and executes `gate_CMD_SEND(args):CMD_SEND::checkInput(args); API_CMD_SEND::run(args),CMD_SEND::checkoutput()`. To ensure compatibility with the new engine, the old engine's protocol flow needs modification (adding a new protocol entry file, `gate_xxx`), and modifying the class and file names for input / output checks. Querying the database is a routine operation, and a large number of files are involved in database operations. Correspondingly, the way the old and new engines query the database has also changed. For example, in the old engine code, the table_test database was initialized by db:init(table_test), while in the new engine it has been changed to base_table_test::init(). Compared to the old engine, a new base_table_test file and class have been added, and the initialization operations have also changed accordingly. In addition, the initialization of the base table name for each table name is different. Therefore, it is necessary to uniformly modify the code file format of the old engine to be compatible with the new engine.
[0073] Step 204: Count the target reference information that exists in the first engine code but not in the second engine code, and generate an error file based on the target reference information. The generated error file is used to represent the content to be confirmed and modified.
[0074] In this embodiment of the invention, automatic migration cannot solve all problems. For example, if a class, function, or variable is deleted in the new engine but is still used in the old engine, manual modification and confirmation are usually required (e.g., function deletion, renaming, etc.). In this case, these contents to be confirmed can be output to the same file during the migration process to inform that manual confirmation is required, which facilitates efficient manual modification.
[0075] Specifically, the system can parse the first engine code and collect its first reference information, and parse the second engine code and collect its second reference information. The first reference information can include classes, functions, and variables in the first engine code, and the second reference information can include classes, functions, and variables in the second engine code. Then, it can identify target reference information that is not present in the second reference information, output this target reference information, and generate an error file based on the output target reference information. This error file indicates the content that needs to be confirmed and modified.
[0076] In practical applications, the new engine code file can be parsed to identify classes, functions, and variables, and the old engine code file can be parsed to identify referenced classes, functions, and variables. Then, classes, functions, and variables referenced in the old engine code but not present in the new engine code can be output to an error file.
[0077] In this embodiment of the invention, a preset merging script can be executed in response to a code merging command. Through the preset merging script, the second resource information of the second engine code is parsed according to the first engine format of the first engine code. This achieves not only merging of corresponding resource statements while merging functional code, but also merging the first and second engine codes according to a unified format based on the parsing of the first engine format, thus realizing the migration and merging of the first and second engine codes. In the case of automatically merging localized functional code of the old engine to achieve a one-time merging goal, automation based on the preset merging script reduces labor costs, improves merging efficiency, and reduces the error rate caused by manual merging.
[0078] Reference Figure 3The illustration shows an application scenario diagram of code migration and merging provided by an embodiment of the present invention. This application scenario can be executed when there is a code update in the new engine or the old engine. That is, when the first engine code adds new features and / or the second engine code is updated, a webpage of a client 310 can be opened, and a preset merging script can be run by responding to a code merging command. In practical applications, the code merging command can be manifested as an instruction generated when a merge click operation of the first engine code and the second engine code is performed on a webpage.
[0079] The merging process implemented by the pre-defined merging script includes parsing and merging table creation statement information, parsing and merging table export statement information, merging functional code, and locating manual modifications. It should be noted that the actual execution order of the aforementioned merging process is not limited in this embodiment of the invention.
[0080] Specifically, such as Figure 4 As shown, the process of merging table creation statement information can be represented by parsing the MySQL table creation file of the new engine code, then exporting and loading the MySQL table creation file of the old engine code to merge the latest MySQL table creation statements of different databases, and then executing the merged table creation statement information. For example, in the process of merging databases, assuming the old engine's databases are a, b, and c; and the new engine's databases are d and f, it is necessary to merge a and b of the old engine into d, and c into f, and generate the init_d.SQL and init_f.SQL files corresponding to the target databases being merged.
[0081] like Figure 5 As shown, the process of merging the export table statement information can be represented by parsing the export table statement file of the new engine code, generating the configuration table file of the old engine code, and then generating the configuration table file of the old engine code after generating the export table statement of the old engine code. At this time, the configuration table file in the old engine code can be modified to the configuration table file of the new engine code in the engine format.
[0082] like Figure 6 As shown, the process of merging functional code can be represented by adding all protocol entry files, then modifying the name and class name of the protocol execution file in the old engine code, modifying the name and category of the protocol input / output detection file in the old engine code, and modifying the file format of the database code in the old engine code.
[0083] like Figure 7As shown, the process of manually modifying the location can be represented by parsing the new engine code file, counting the classes, functions and variables, parsing the old engine code file, counting the referenced classes, functions and variables, and then outputting the classes, functions and variables referenced in the old engine code but not existing in the new engine code to the error file.
[0084] In this embodiment of the invention, localization functions are efficiently migrated by writing scripts, so that the script does not need to be redeveloped for subsequent merges. Specifically, by running a preset merge script, the second resource information is parsed according to the first engine format. This allows for the merging of functional code, not only merging corresponding resource statements but also ensuring a consistent format during code merging. While achieving a one-time merging of localized functional code from the old engine, the automation based on the preset merge script reduces labor costs, improves merging efficiency, and reduces the error rate caused by manual merging.
[0085] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0086] Reference Figure 8 The diagram illustrates a structural block diagram of an embodiment of the code migration and merging apparatus of the present invention, which may specifically include the following modules:
[0087] The merge script execution module 801 is used to respond to code merging instructions, run a preset merge script, and obtain the first engine code and the second engine code.
[0088] The resource information acquisition module 802 is used to acquire the first resource information of the first engine code and the second resource information of the second engine code;
[0089] Engine format determination module 803 is used to determine the first engine format of the first engine code based on the first resource information; code merging module 804 is used to parse the second resource information according to the first engine format, and migrate and merge the first engine code into the second engine code based on the parsed second resource information.
[0090] In one embodiment of the present invention, the first resource information includes the first table creation statement information of the first engine code, and the second resource information includes the second table creation statement information of the second engine code;
[0091] Code merging module 804 may include the following submodules:
[0092] The table creation statement information parsing submodule is used to load the first table creation statement information, parse the second table creation statement information according to the first engine format, and obtain the parsed second table creation statement information.
[0093] The table creation statement information merging submodule is used to merge the first table creation statement information and the parsed second table creation statement information to obtain the table creation statement information of the target database; the table creation statement information of the target database is used to represent the table creation statement information based on the engine code obtained by merging the first engine code and the second engine code.
[0094] In one embodiment of the present invention, after merging the table creation statement information of the target database, the code merging module 804 may further include the following sub-modules:
[0095] The table creation statement information execution submodule is used to execute the table creation statement information of the target database; wherein, the table creation statement information is used to represent the functional information and structural information of the merged engine code.
[0096] In one embodiment of the present invention, the macro definition table of the first table creation statement information corresponds to at least one first database, and the macro definition table of the parsed second table creation statement information corresponds to at least one second database.
[0097] The table creation statement information merging submodule may include the following units:
[0098] The target database determination unit is used to determine, from the at least one second database, one or more first databases to be merged to generate a target database;
[0099] The table creation statement information merging unit is used to merge the first table creation statement information of the one or more first databases into the target database to generate the table creation statement information of the target database.
[0100] In one embodiment of the present invention, the first resource information includes first import table information of the first engine code, and the second resource information includes second import table information of the second engine code;
[0101] Code merging module 804 may include the following submodules:
[0102] The export table information parsing submodule is used to parse the second export table information according to the second engine format to obtain the parsed second export table statement information;
[0103] The import table information modification submodule is used to load the first import table information, modify the first import table information using the parsed second import table statement information, and obtain the modified first import table information.
[0104] The export table information merging submodule is used to obtain the second engine format of the second engine code, modify the modified first export table information according to the second engine format, and obtain the merged export table information; wherein, the merged export table information represents the export table information of the engine code obtained by merging the first engine code and the second engine code, and is used to export the configuration table of the merged engine code into a file with a preset format.
[0105] In one embodiment of the present invention, the first resource information further includes a first protocol document of the first engine code, the second resource information further includes a second protocol document of the second engine code, and the code merging module 804 may further include the following sub-modules:
[0106] The protocol entry file addition submodule is used to determine the new protocol entry file in the second protocol document based on the second protocol document and the first protocol document, and add the new protocol entry file to the first protocol document to obtain the new first protocol document;
[0107] The file information acquisition submodule is used to acquire the file information of the second protocol document; the file information includes the name and class name of the executable file, the name and class name of the input / output check file, and the format of the database code file;
[0108] The file information modification submodule is used to modify the newly added first protocol document according to the name and class name of the executable file, the name and class name of the input / output check file, and the format of the database code file; wherein, the modified first protocol document is used to represent the functional code of the engine code obtained by merging the first engine code and the second engine code.
[0109] In one embodiment of the present invention, the code merging module 804 may further include the following sub-modules:
[0110] The reference information statistics submodule is used to parse the first engine code and count the first reference information of the first engine code, and to parse the second engine code and count the second reference information of the second engine code; wherein, the first reference information includes the classes, functions and variables of the first engine code, and the second reference information includes the classes, functions and variables of the second engine code;
[0111] The target reference information determination submodule is used to determine the target reference information that does not exist in the second reference information;
[0112] The error file output submodule is used to output the target reference information and generate an error file; the error file is used to represent the content to be confirmed and modified.
[0113] In one embodiment of the present invention, the code migration and merging apparatus provided by the present invention may further include the following modules:
[0114] The code merging instruction generation module is used to generate code merging instructions in response to the addition of features to the first engine code and / or the update of the second engine code.
[0115] In this embodiment of the invention, the code migration and merging device can respond to a code merging command and run a preset merging script. Through the preset merging script, the second resource information of the second engine code is parsed according to the first engine format of the first engine code. This achieves not only merging of corresponding resource statements while merging functional code, but also merging the first engine code and the second engine code according to a unified format based on the parsing of the first engine format, thus realizing the migration and merging of the first engine code and the second engine code. In the case of automatically merging the localized functional code of the old engine to achieve a one-time merging purpose, the automation based on the preset merging script reduces labor costs, improves merging efficiency, and reduces the error rate caused by manual merging.
[0116] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0117] This invention also provides an electronic device, comprising:
[0118] It includes a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described code migration and merging method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0119] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described code migration and merging method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0120] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0121] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0122] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0123] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0124] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0125] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.
[0126] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0127] The foregoing has provided a detailed description of a code migration and merging method, a code migration and merging device, a corresponding electronic device, and a corresponding computer-readable storage medium provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the technical solutions of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A code migration and merging method, characterized in that, The method includes: In response to the code merging command, run the preset merging script to obtain the first engine code and the second engine code; Obtain first resource information of the first engine code and second resource information of the second engine code. The first resource information includes first table creation statement information of the first engine code, and the second resource information includes second table creation statement information of the second engine code. The first engine format of the first engine code is determined based on the first resource information; The second resource information is parsed according to the first engine format, and the first engine code is migrated and merged into the second engine code based on the parsed second resource information. The step of parsing the second resource information according to the first engine format and migrating and merging the first engine code into the second engine code based on the parsed second resource information includes: The second table creation statement information is parsed according to the first engine format to obtain the parsed second table creation statement information. Load the first table creation statement information, and merge the first table creation statement information and the parsed second table creation statement information to obtain the table creation statement information of the target database; the table creation statement information of the target database is used to represent the table creation statement information based on the engine code obtained by merging the first engine code and the second engine code.
2. The method according to claim 1, characterized in that, After merging the table creation statement information of the target database, it also includes: Execute the table creation statement information of the target database; wherein, the table creation statement information is used to represent the functional information and structural information of the merged engine code.
3. The method according to claim 2, characterized in that, The macro definition table of the first table creation statement information corresponds to at least one first database, and the macro definition table of the parsed second table creation statement information corresponds to at least one second database. The step of merging the first table creation statement information and the parsed second table creation statement information to obtain the table creation statement information of the target database includes: From the at least one second database, determine one or more target databases to be generated by merging the first databases; The first table creation statement information of the one or more first databases is merged into the target database to generate the table creation statement information of the target database.
4. The method according to claim 1 or 2, characterized in that, The first resource information includes the first import table information of the first engine code, and the second resource information includes the second import table information of the second engine code; The step of parsing the second resource information according to the first engine format, and migrating and merging the first engine code into the second engine code based on the parsed second resource information, includes: The second export table information is parsed according to the first engine format to obtain the parsed second export table statement information; The first guide table information is modified using the parsed second guide table statement information to obtain the modified first guide table information; Obtain the second engine format of the second engine code, modify the format of the modified first export table information according to the second engine format, and obtain the merged export table information; wherein, the merged export table information is used to represent the export table information of the engine code obtained by merging the first engine code and the second engine code, and is used to export the configuration table of the merged engine code into a file with a preset format.
5. The method according to claim 1 or 2, characterized in that, The first resource information also includes a first protocol document for the first engine code, and the second resource information also includes a second protocol document for the second engine code. The method further includes: Based on the second protocol document and the first protocol document, determine the newly added protocol entry file in the second protocol document, and add the newly added protocol entry file to the first protocol document to obtain the newly added first protocol document; Obtain the file information of the second protocol document; the file information includes the name and class name of the executable file, the name and class name of the input / output check file, and the format of the database code file; The newly added first protocol document is modified according to the name and class name of the executable file, the name and class name of the input / output check file, and the format of the database code file; wherein, the modified first protocol document is used to represent the functional code of the engine code obtained by merging the first engine code and the second engine code.
6. The method according to claim 1 or 2, characterized in that, The method further includes: The first engine code is parsed and first reference information of the first engine code is collected, and the second engine code is parsed and second reference information of the second engine code is collected; wherein, the first reference information includes the classes, functions and variables of the first engine code, and the second reference information includes the classes, functions and variables of the second engine code; Determine the target reference information in which the first reference information does not exist in the second reference information; The target reference information is output and an error file is generated; the error file is used to indicate the content to be confirmed and modified.
7. The method according to claim 1, characterized in that, The method further includes: In response to the addition of features to the first engine code and / or an update to the second engine code, a code merging instruction is generated.
8. A code migration and merging apparatus, characterized in that, The device includes: The merge script execution module is used to respond to code merging commands, run preset merge scripts, and obtain the first engine code and the second engine code; The resource information acquisition module is used to acquire first resource information of the first engine code and second resource information of the second engine code. The first resource information includes first table creation statement information of the first engine code, and the second resource information includes second table creation statement information of the second engine code. An engine format determination module is used to determine the first engine format of the first engine code based on the first resource information. The code merging module is used to parse the second resource information according to the first engine format, and migrate and merge the first engine code into the second engine code based on the parsed second resource information; The code merging module includes: The table creation statement information parsing submodule is used to parse the second table creation statement information according to the format of the first engine to obtain the parsed second table creation statement information. The table creation statement information merging submodule is used to load the first table creation statement information, merge the first table creation statement information and the parsed second table creation statement information to obtain the table creation statement information of the target database; the table creation statement information of the target database is used to represent the table creation statement information based on the engine code obtained by merging the first engine code and the second engine code.
9. An electronic device, characterized in that, include: A processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the code migration and merging method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the code migration and merging method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Code generation method and device, electronic equipment and storage medium
CN112947912A
Website access verification method and device, electronic equipment and readable storage medium
CN113722639A