Script execution method, device, apparatus and storage medium
By adaptively encapsulating data models to generate structured datasets, performing template matching and dependency merging, the problem of high script adaptation difficulty and low execution efficiency in data modeling platforms is solved, achieving automation and high efficiency in script execution.
Patent Information
- Application Number
- CN202611424371.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-14
- Publication Date
- 2026-11-24
AI Technical Summary
In data modeling platforms, when outputting scripts to different databases after the model is completed, there are problems such as high adaptation difficulty and low execution efficiency.
By adaptively encapsulating the metadata of the data model, a structured dataset is generated. Based on this dataset, template matching and instantiation rendering are performed to obtain the initial script. The script is then merged and executed according to the dependencies between template components, thereby achieving script automation and efficiency.
It can extend new database and script capabilities without modifying the source code, and realizes the automation and efficiency of script execution. The adaptation logic is decoupled from the code to the template configuration.
Smart Images

Figure CN123157299A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computers, and more particularly to a script execution method, apparatus, device, and storage medium. Background Technology
[0002] In data modeling platforms, after the model is completed, it is necessary to output scripts to different databases and execute them. The relevant methods have embedded the script adaptation logic in the program code. Adding new database types or script capabilities requires modifying the source code, which leads to difficulties in script execution adaptation and low efficiency. Summary of the Invention
[0003] The main purpose of this application is to provide a script execution method, apparatus, device and storage medium, which aims to solve the technical problems of high adaptation difficulty and low execution efficiency when outputting scripts to different databases after the model is completed in the data modeling platform.
[0004] To achieve the above objectives, this application provides a script execution method, the script execution method comprising: In response to the input data model, the metadata of the data model is adaptively encapsulated to obtain a structured dataset; Template matching is performed based on the structured dataset to obtain a target template, wherein the target template includes template components; The structured dataset is instantiated and rendered according to the target template to obtain the initial script corresponding to the template component; Based on the dependencies between the template components, the initial scripts corresponding to each template component are merged to obtain a script, which is then executed.
[0005] Optionally, the step of instantiating and rendering the structured dataset according to the target template to obtain the initial script corresponding to the template component includes: Construct the rendering parameter set corresponding to the template component based on the structured dataset; Based on the target template, the rendering parameter set is rendered to obtain candidate scripts; The candidate scripts are subjected to syntax validation, and the candidate scripts that pass the validation are used as the initial scripts.
[0006] Optionally, the step of performing scene rendering on the rendering parameter set based on the target template to obtain candidate scripts includes: Based on the script type of the rendering parameter set, scene identification is performed to obtain the current rendering scene; Based on the current rendering scene and the rendering parameter set, the target template is substituted with variables to obtain a script fragment; The script fragment is formatted to obtain candidate scripts.
[0007] Optionally, the step of merging the initial scripts corresponding to each template component based on the dependencies between the template components to obtain a script includes: Construct a dependency graph based on the dependency relationships between the template components; The dependency graph is topologically sorted to obtain the execution order of the initial scripts corresponding to each template component; The initial script is assembled according to the execution order to obtain a new script, which is then executed.
[0008] Optionally, before executing the script, the method further includes: Obtain the runtime environment of the preset library instance and the runtime environment of the script; The consistency of the runtime environment of the preset library instance and the runtime environment of the script is compared and verified to obtain the comparison results; If the comparison results are inconsistent, the script execution process will be blocked, and a detailed difference message will be output. If the comparison results are consistent, a dynamic mapping relationship is established based on the runtime environment of the preset library instance and the runtime environment of the script, and the script is routed to the preset library instance.
[0009] Optionally, the step of performing template matching based on the structured dataset to obtain the target template includes: In response to an input script generation request, the database type is determined based on the target library identifier in the script generation request; Based on the database type, filter by conditions to obtain the component type; The structured dataset is parsed to obtain the change type; The target template is obtained by performing template matching based on the database type, the component type, and the change type.
[0010] Optionally, after obtaining the target template through template matching based on the structured dataset, the process further includes: If no target template is found, a template missing message will be returned, and the default template will be used as the target template.
[0011] Furthermore, to achieve the above objectives, this application also proposes a script execution device, which includes: The metadata encapsulation module is used to adaptively encapsulate the metadata of the input data model in response to the input data model, so as to obtain a structured dataset. The template matching module is used to perform template matching based on the structured dataset to obtain a target template, wherein the target template includes a template component; The template rendering module is used to instantiate and render the structured dataset according to the target template to obtain the initial script corresponding to the template component; The script execution module is used to merge the initial scripts corresponding to each template component based on the dependency relationship between the template components, obtain a script, and execute the script.
[0012] In addition, to achieve the above objectives, this application also proposes a script execution device, which includes a memory, a processor, and a script execution program stored in the memory and executable on the processor, the script execution program being configured to implement the script execution method as described above.
[0013] In addition, to achieve the above objectives, this application also proposes a storage medium storing a script execution program, which, when executed by a processor, implements the script execution method described above.
[0014] One or more technical solutions proposed in this application have at least the following technical effects: This application discloses a method that responds to an input data model by adaptively encapsulating the metadata of the data model to obtain a structured dataset, performing template matching based on the structured dataset to obtain a target template, the target template including template components, instantiating and rendering the structured dataset according to the target template to obtain the initial script corresponding to the template component, merging the initial scripts corresponding to each template component based on the dependencies between template components to obtain a script, and executing the script. Because this application encapsulates the data model metadata into a structured parameter set, automatically matches templates and renders and generates initial scripts, and merges and executes them according to component dependencies, the adaptation logic is decoupled from the code to the template configuration. This allows for the expansion of new databases and script capabilities without modifying the source code, achieving automated and efficient script execution. Attached Figure Description
[0015] 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.
[0016] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating the first embodiment of the script execution method of this application; Figure 2This is a flowchart illustrating the second embodiment of the script execution method of this application; Figure 3 This is a flowchart illustrating the third embodiment of the script execution method of this application; Figure 4 This is a flowchart illustrating the fourth embodiment of the script execution method of this application; Figure 5 This is a schematic diagram of the script generation process of one embodiment of the script execution method of this application; Figure 6 This is a schematic diagram of the module structure of the script execution device according to an embodiment of this application; Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the script execution method in this application embodiment.
[0018] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0019] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0020] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0021] This application provides a script execution method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the script execution method of this application.
[0022] In the first embodiment, the script execution method includes: Step S10: In response to the input data model, adaptively encapsulate the metadata of the data model to obtain a structured dataset.
[0023] It should be noted that the execution subject in this embodiment can be a script execution device with data processing, network communication and program running functions, such as a computer, server, etc., or other electronic devices that can achieve the same or similar functions. This embodiment does not limit this.
[0024] It should be understood that a data model can be a physical model or a logical-physical model designed by the user in a data modeling platform. Metadata can be data describing the attributes and structure of the data model itself (e.g., default database type, default database instance and tables, views, fields, primary keys, foreign keys, indexes, partitions, tablespaces, and supplementary table creation options, etc.). A structured dataset can be a set of parameters with fixed field names and value structures obtained by uniformly collecting and formatting metadata according to preset rules.
[0025] In the implementation, a field type mapping dictionary can be pre-established for each database type. For example, Oracle's VARCHAR2 corresponds to MySQL's VARCHAR, and Oracle's NUMBER corresponds to MySQL's DECIMAL. Once the input data model is loaded, all tables and fields in the model are traversed, and the data types of the fields in the model are automatically converted to the corresponding data types in the target database using the mapping dictionary. Simultaneously, table names and field names are standardized according to preset naming rules; for example, Chinese names in the model or names that do not conform to the target database's naming conventions are converted to valid English identifiers. After conversion and standardization, all metadata is uniformly assembled into a key-value pair set, i.e., a structured dataset.
[0026] In one example, it is also possible to traverse the entity nodes in the data model, extract information such as table names, field lists, primary and foreign keys, and convert them into a structured parameter set in JSON format according to a predefined data contract.
[0027] Step S20: Perform template matching based on the structured dataset to obtain a target template, wherein the target template includes template components.
[0028] It should be understood that the target template can be a pre-written template file stored in a template library, or it can be a set of script generation rules that match the current data model and the target database type. Template components can be independent functional units that constitute a complete DDL script (e.g., table structure definition components, primary key definition components, index definition components, partition definition components, and table comment components, etc.).
[0029] In the specific implementation, the database type is first read from the structured dataset (e.g., MySQL 8.0), and the database type is used as a first-level index to locate the relevant template directory in the template library. Then, the operation intent information in the structured dataset is read. This operation intent information can be specified by the user through interface options when inputting the data model (e.g., the user selects to generate a table creation script or a table deletion script in the generation interface), or it can be automatically inferred based on model change status (e.g., if a new table is detected, the operation intent is to create a table; if a table is detected to be deleted, the operation intent is to delete a table). Using the operation intent as a second-level index, the corresponding template file is further located in the database type directory; this is the target template. The target template contains several template components related to the current operation intent. For example, when the operation intent is to create a table, the target template includes components such as table structure definition, primary key definition, and index definition; when the operation intent is to delete a table, the target template only contains a single component corresponding to the table deletion statement.
[0030] Step S30: Instantiate and render the structured dataset according to the target template to obtain the initial script corresponding to the template component.
[0031] It should be understood that the initial script can be a fragment of SQL script text generated by populating variables from a single template component.
[0032] In the implementation, each template component in the target template can be traversed. For the currently traversed component, a specific subset of parameters is extracted from the structured dataset. For example, if the current component is a table structure definition, information such as the table name, field list, and table comments are extracted from the structured dataset. If the current component is an index definition, information such as the index name, index field, and index type are extracted from the structured dataset. The extracted parameter subset is input into the template engine in key-value pair format. The template engine replaces the placeholders with the actual parameter values one by one according to the placeholder names defined in the component template, executes the loop logic in the template (e.g., traversing the field list to generate multiple field definition statements), and outputs a complete script text as the initial script.
[0033] In one example, a structured dataset can be passed to the template engine as a context object. The template engine automatically finds and extracts the corresponding parameter values from this context object based on the variable reference paths defined in each component template within the target template, and then populates them. For instance, if a component template contains `{tableName}`, the template engine reads the value corresponding to `{tableName}` from the context object and replaces it. The template engine processes all component templates sequentially during the same rendering process, with each component template outputting a corresponding initial script, ultimately resulting in a collection of multiple initial scripts.
[0034] Step S40: Based on the dependencies between the template components, merge the initial scripts corresponding to each template component to obtain a script, and execute the script.
[0035] It should be understood that dependencies can be constraints on the execution order of the initial scripts corresponding to different template components. A script can be a complete, executable sequence of DDL statements assembled with correct syntax and execution logic.
[0036] In the implementation, different component priority configurations are predefined for different operational intentions. For example, in the creation scenario, the preset priorities from high to low are: Schema component, tablespace component, table structure component, primary key component, index component, foreign key component, and comment component. In the deletion scenario, the priority order is automatically adjusted to: foreign key component, index component, table structure component, tablespace component, and Schema component. During merging, the corresponding priority configuration is selected according to the current operational intention, and the initial scripts are sorted in ascending order of priority number. Scripts of the same priority are arranged according to their order of appearance in the structured dataset. After sorting, semicolons and newlines are added between the scripts to concatenate them into a complete final script.
[0037] After the scripts are merged, they are output to the target database for execution. The execution process can be as follows: the script is sent to the target database server over the network, the database server parses and executes each statement in the script, receives the execution results, and records the execution log. The target database can be the default database instance bound to the data model, or a data source selected by the user in the script generation interface.
[0038] This embodiment encapsulates data model metadata into a structured parameter set, automatically matches templates and renders the initial script, and merges and executes it according to component dependencies. This decouples the adaptation logic from the code to the template configuration, allowing for the expansion of new databases and script capabilities without modifying the source code, thus achieving automated and efficient script execution.
[0039] Reference Figure 2 , Figure 2 This is a flowchart illustrating the second embodiment of the script execution method of this application, based on the above. Figure 1 The first embodiment shown presents a second embodiment of the script execution method of this application.
[0040] In the second embodiment, step S30 includes: Step S301: Construct the rendering parameter set corresponding to the template component based on the structured dataset.
[0041] It should be understood that the rendering parameter set can be a dedicated set of parameters extracted, transformed, or supplemented from the original structured dataset to meet the rendering requirements of a specific template component. These parameters include, but are not limited to, database name, schema name, table name, field list, primary key list, foreign key list, index list, partition configuration information, partition field name list, tablespace name, table creation option, table comment, field comment, view query statement, and case conversion rules.
[0042] In the implementation, a parameter mapping list is pre-configured for each component type. This list records which parameters need to be extracted from the structured dataset for each component type, and how they should be named after extraction. For example, for an index component, the predefined parameter mapping list includes: index name, index type, list of index fields, and table name. When traversing each template component in the target template, the component type is identified. Based on the mapping list corresponding to the component type, the corresponding values are extracted from the structured dataset by name. The extracted results are then repackaged into a key-value pair set according to the new names specified in the mapping list. This set is the rendering parameter set for the component. The rendering parameter set built for each template component is equivalent to a customized template context object for the component, used to provide a variable population environment for the template engine.
[0043] Step S302: Render the scene based on the target template and the rendering parameter set to obtain candidate scripts.
[0044] It should be understood that the candidate script can be the script text initially obtained after scenario-based condition judgment and variable injection.
[0045] In its implementation, the template engine activates the corresponding conditional branch based on the context identifier in the rendering parameter set. For example, when the parameters indicate that the target database is MySQL 8.0 or higher, it renders the index definition containing the VISIBLE keyword; otherwise, it generates simplified syntax compatible with older versions.
[0046] Step S303: Perform syntax verification on the candidate scripts, and use the candidate scripts that pass the verification as the initial scripts.
[0047] In the specific implementation, a lightweight SQL parser matching the target database type is invoked to perform lexical and syntactic analysis on the candidate script. If the parser does not indicate an exception and returns a valid abstract syntax tree, the validation is deemed successful, and the candidate script is confirmed as the initial script; if a syntax error is detected (e.g., mismatched brackets, misuse of reserved words), the error location is recorded and an alarm is triggered to prevent illegal scripts from entering the merging stage.
[0048] Furthermore, in order to accurately match the template rendering rules under the corresponding scene and improve the standardization and readability of the output script, step S302 includes: performing scene identification based on the script type of the rendering parameter set to obtain the current rendering scene; performing variable replacement on the target template according to the current rendering scene and the rendering parameter set to obtain a script fragment; and performing formatting processing on the script fragment to obtain a candidate script.
[0049] It should be understood that the current rendering scene can be a rendering context environment jointly determined by the operation type of the script to be generated and the database object type. Script fragments can be raw code strings that have completed variable injection but have not yet been formatted.
[0050] In the specific implementation, script type information is first read from the rendering parameter set. This script type information includes the operation type and the database object type. The operation type and the database object type are combined to form a scene identifier, which is then matched against a preset scene configuration table to obtain the current rendering scene. The current rendering scene includes, but is not limited to, table creation scenes, modification scenes, case conversion scenes, and database type mapping scenes.
[0051] In table creation scenarios, field definitions are generated iteratively based on the field list, primary key fragments are generated based on the primary key list, and tablespace, table creation supplementary options, partition definitions, index definitions, table comments, and field comments are added as needed. In change scenarios, DDL fragments are generated based on the change type, including deleting a table, renaming a table, adding a field, deleting a field, modifying a field, adding or deleting primary keys, adding or deleting foreign keys, adding or deleting indexes, adding or deleting partitions, adding or deleting schemas, and adding or deleting tablespaces. In tablespace script generation scenarios, if the tablespace uses parameter configuration, the tablespace DDL is dynamically assembled after reading the parameters and values; if it uses a custom method, the configured custom script text is used directly. In case conversion scenarios, identifiers such as table names, field names, index names, and schema names are processed by default, converted to uppercase, or converted to lowercase. In multi-table and multi-view scenarios, fragments are sorted according to script type dependencies, with schema or tablespace scripts generated first, followed by table or view creation scripts, and then comments, indexes, partitions, and constraint scripts. In database type mapping scenarios, the model field types are converted to data types supported by the target database based on the data type mapping relationship defined in the library script configuration. After variable substitution and fragment assembly are completed, the SQL formatter bound to the current rendering scene is called to perform formatting processing on the script fragments according to scene specifications, such as keyword capitalization, indentation alignment, and line break rearrangement, to obtain a candidate script with a clear structure that conforms to platform standards.
[0052] This embodiment constructs a rendering parameter set, combines it with the target template to complete scene rendering and generate candidate scripts, and performs syntax verification to achieve decoupling and adaptation between the original data and the rendering template, effectively improving the accuracy of the initial script generation and reducing the probability of errors in the subsequent execution stage.
[0053] Reference Figure 3 , Figure 3 This is a flowchart illustrating the third embodiment of the script execution method of this application. Based on the above embodiments, a third embodiment of the script execution method of this application is proposed.
[0054] In the third embodiment, step S40 includes: Step S401: Construct a dependency graph based on the dependency relationships between the template components.
[0055] It should be understood that a dependency graph can be a graph data structure with template components as nodes and the dependency constraints between components as directed edges.
[0056] In the specific implementation, for example, the metadata of each component in the target template is traversed, and the list of prerequisites for each component is read (e.g., the index component depends on the table component, the comment component depends on both the table and column components), thereby constructing a dependency graph in the form of an adjacency list. Weight attributes (e.g., component type priority, object hierarchy) are injected into each node. If a cycle is detected in the dependency graph (e.g., component A depends on component B and component B inversely depends on component A), the process is interrupted and a circular dependency warning is output, prompting the user to correct the template configuration.
[0057] In one example, a dependency matrix can be created for all possible component types, with rows and columns corresponding to different component types. Each cell in the matrix records the dependency direction between two component types. For example, the cell where the row "Table Component" intersects the column "Index Component" is recorded as "Dependent," indicating that the table component precedes the index component; the cell where the row "Index Component" intersects the column "Table Component" is recorded as "Dependent," indicating that the index component depends on the table component. The process iterates through all template component types corresponding to the initial script, searching for the dependency directions between these component types in the dependency matrix. For each dependency pair found, a corresponding directed edge is added to the graph. After the traversal is complete, a complete dependency graph is constructed using all template components as nodes and the found dependencies as directed edges.
[0058] Step S402: Perform topological sorting on the dependency graph to obtain the execution order of the initial scripts corresponding to each template component.
[0059] It should be understood that the execution order can be a linear sequence obtained by topologically sorting the dependency graph.
[0060] In the implementation, a depth-first search traversal is performed on each node in the dependency graph. For the currently visited node, all adjacent nodes (i.e., the component nodes that the current node depends on) are recursively visited first. After all adjacent nodes have been processed, the current node is pushed onto a stack. After all nodes have been traversed, the nodes in the stack are popped out in the order they are popped, which is the execution order obtained by topological sorting. To prevent circular dependencies from causing the algorithm to fail to terminate, an access status flag is maintained for each node during the recursive process. If a node marked as being visited is encountered during the traversal, a circular dependency is determined, the list of components involved in the circular dependency is recorded, the sorting is stopped, and the user is prompted to check the dependency configuration.
[0061] In one example, the Kahn algorithm (in-degree reduction method) can also be used to perform topological sorting of the dependency graph. First, the in-degree of each node in the dependency graph is counted, i.e., how many directed edges point to that node. Nodes with an in-degree of zero, i.e., nodes that do not depend on any other components (e.g., schema components), are added to a queue. Then, a node is removed from the queue and added to the end of the execution sequence, while all directed edges emanating from that node are removed, and the in-degree of the nodes pointed to by these edges is decremented by one. If the in-degree of a node becomes zero, it is added to the queue. This process is repeated until the queue is empty; the resulting sequence is the topological sorting result.
[0062] Step S403: Concatenate and synthesize the initial script according to the execution order to obtain a script, and execute the script.
[0063] In the specific implementation, the initial scripts corresponding to each template component are retrieved sequentially according to the execution order. During the concatenation process, the statement type of each initial script is automatically identified, and a delimiter corresponding to the database type is added to the end of each complete statement (for example, MySQL and Oracle use semicolons ";" as statement delimiters, and SQL Server uses "GO" as batch delimiters). The corresponding delimiter configuration is loaded based on the database type information in the current rendering scene. For table creation scenarios, the scripts are concatenated in the following order: Schema creation script, tablespace creation script, table structure creation script, primary key script, index script, foreign key script, and comment script. For table deletion scenarios, the concatenation order is reversed: foreign key deletion script, index deletion script, table deletion script, tablespace deletion script, and Schema deletion script, ensuring that the deletion operation can be executed smoothly without being hindered by dependent objects.
[0064] After concatenation, a complete script is obtained. In scenarios involving the batch generation of scripts for multiple tables or views, the scripts are sorted according to the dependencies between database objects. Schema or tablespace scripts are generated first, followed by scripts for creating tables or views, and then comment scripts, index scripts, partitioning scripts, and constraint scripts. This ensures that the overall execution order of the scripts in multi-object scenarios also conforms to the database's dependency constraints.
[0065] After obtaining the complete script, execute it. Execution can be achieved by establishing a network connection with the target database via a database connection driver, and submitting the script content to the database server for execution in batches. During execution, receive execution status information returned by the database server, including the success or failure result of each statement, the number of rows affected, and error messages. If a statement fails, record the failure location and reason, and decide whether to continue executing subsequent statements or terminate the entire execution process based on a preset strategy. After execution, record the results in the log for later viewing and traceability.
[0066] In one example, the script execution method can be applied to various script generation scenarios, including single-table script generation, single-view script generation, multi-table batch script generation, multi-view batch script generation, script generation under a single database instance, script generation in a multi-schema environment, and script generation when the database instance information is unclear or unknown. In all these scenarios, the dynamic template generation mechanism can be reused. That is, regardless of whether the input data model contains one or more tables, one or more schemas, or whether the database instance is explicit, the target script is output according to a unified processing chain of metadata encapsulation, template matching, instantiation rendering, and dependency merging, without the need to develop independent script generation logic for different scenarios.
[0067] Furthermore, to effectively prevent scripts from being executed in unexpected environments and improve the security and controllability of script execution in the library, step S40, before executing the script, further includes: obtaining the runtime environment of a preset library instance and the runtime environment of the script; performing a consistency comparison check between the runtime environment of the preset library instance and the runtime environment of the script to obtain a comparison result; if the comparison result is inconsistent, blocking the script execution process and outputting a detail of the difference prompt; if the comparison result is consistent, establishing a dynamic mapping relationship based on the runtime environment of the preset library instance and the runtime environment of the script, and routing the script to the preset library instance.
[0068] It should be understood that the runtime environment of the default database instance can be a collection of the actual running status and configuration information of the target database instance, including but not limited to the database type and version number, the environment identifier of the instance (e.g., development environment, testing environment, pre-release environment, production environment), connection address and port, character set encoding, schema ownership, tablespace configuration, and the read and write permission status of the current instance.
[0069] The script's runtime environment can be the expected execution environment information bound to the script during the generation phase. Difference details can be a structured list of inconsistencies.
[0070] In the specific implementation, when the script is generated and the database insertion operation is triggered, the database instance bound during the data model design phase is not directly used as the execution target. Instead, a list of authorized data sources is read from the public management platform for the user to select. The user selects a data source from this list as the actual database insertion target according to their actual needs and specifies the target schema under that data source. After selection, the runtime environment information of the preset database instance is read from the user-selected data source configuration. The runtime environment information includes, but is not limited to, the database type, database instance identifier, and schema name. At the same time, the runtime environment information of the script is parsed from the generated initial script or the merged script. The parsing method can be to extract database object references appearing in the script through regular expression matching or syntax parsing tools (such as the schema part in the "USE database_name" statement, the "CREATE TABLE schema_name.table_name" statement, or environment tags carried in script comments). The extracted database type, database instance name, and schema name are used as the runtime environment of the script.
[0071] Consistency verification can be divided into three dimensions. The first dimension compares the database type of the preset library instance with the database type in the script execution environment based on the correspondence between the database types of the preset library instance and the public management platform, determining if they match. The second dimension compares the library instance identifier of the preset library instance with the library instance information in the script execution environment based on the association between the library instance and the data source. The third dimension compares the schema of the preset library instance with the schema in the script execution environment based on the correspondence between the schema and the schema of the target data source. If all three dimensions match, the comparison result is considered consistent; if any dimension does not match, the comparison result is considered inconsistent, and the specific dimension in which the difference exists and the details of the difference are recorded.
[0072] If the comparison results are inconsistent, the script execution process is blocked, meaning subsequent script submission operations are not performed. Simultaneously, a detailed difference message is displayed to the user via a pop-up window, notification bar, or log. For example, if the default database instance's database type is "MySQL" while the script's runtime environment's database type is "Oracle," the output difference message will be: "Environment mismatch. The currently selected data source is MySQL, but the script to be executed uses Oracle syntax. Please reselect a matching data source and try again." After adjusting the default database instance selection based on the message, the user can re-trigger the execution process.
[0073] If the comparison results are consistent, a dynamic mapping relationship is established between the runtime environment of the preset library instance and the runtime environment of the script. The mapping is established as follows: the library type in the script runtime environment is mapped to the actual database type of the preset library instance; the library instance name or identifier in the script runtime environment is mapped to the actual connection address or instance ID of the preset library instance; and the schema name in the script runtime environment is mapped to the corresponding target schema name in the preset library instance. When names are inconsistent, a preset mapping table can be used for conversion. For example, the design-state "dev_schema" is mapped to the execution-state "prod_schema". After the mapping relationship is established, the script is routed to the preset library instance. The specific routing method is as follows: a network connection to the target database is established using the connection information of the preset library instance (e.g., connection address, port, authentication credentials), and the mapped script content is submitted to this connection for execution, ensuring that the target environment where the script is actually executed is completely consistent with the preset library instance selected by the user. Furthermore, during the dynamic mapping process, if the script references multiple schemas or cross-database objects, the mapping relationship can be established one by one according to preset rules, ensuring that all database object references are correctly mapped to the corresponding environment of the preset library instance.
[0074] After successful script execution, the system determines whether to synchronize metadata based on user configuration. This involves synchronizing database structure changes after execution back to the data model to ensure consistency between the model state and the actual database. Simultaneously, execution logs, failure reasons, and target data source information are recorded, forming a complete closed-loop chain from model design and script generation to execution and database insertion, facilitating subsequent traceability.
[0075] This embodiment constructs a dependency graph based on the dependencies between template components, then performs a topological sorting calculation on the dependency graph to obtain the execution order of each initial script, and finally completes the splicing and synthesis of the initial scripts according to this order. This mechanism ensures that the script order conforms to the database object dependency logic and completely avoids execution failure caused by disordered order.
[0076] Reference Figure 4 , Figure 4 This is a flowchart illustrating the fourth embodiment of the script execution method of this application. Based on the above embodiments, a fourth embodiment of the script execution method of this application is proposed.
[0077] In the fourth embodiment, step S20 includes: Step S201: In response to the input script generation request, determine the database type based on the target library identifier in the script generation request.
[0078] It should be understood that the target database identifier can be identifying information about the target database instance (e.g., the database instance name, instance number, host address and port combination in the connection string, or a unique code selected by the user from the data source drop-down list in the interface). The database type can be the database product category and version information to which the target database instance belongs (e.g., MySQL 8.0, Oracle 19c, PostgreSQL 14, SQL Server 2019, etc.).
[0079] In the actual implementation, upon receiving a script generation request, the target library identifier is extracted from the request parameters. Then, the data source registry maintained by the public management platform or local configuration center is queried to retrieve the associated database type field based on the identifier. If no corresponding record is found, an error message indicating an invalid target library identifier is returned, and the process terminates. If multiple records are found, a secondary filtering is performed using the project ID in the current session context to determine the database type.
[0080] Step S202: Filter based on the database type to obtain the component type.
[0081] It should be understood that a component type can be the smallest functional unit category that makes up a DDL script (e.g., table creation component, primary key component, foreign key component, index component, partition component, comment component, view component, sequence component, etc.).
[0082] In the implementation, based on the determined database type, the set of component types supported by that database type is selected from a pre-defined list of supported components. For example, for MySQL, components such as table creation, primary keys, foreign keys, indexes, and comments are selected. For Oracle, unique components such as sequences, synonyms, and materialized views are selected. The selection results are cached in the current request context as a list.
[0083] In one example, when a user selects a specific script content type in the script generation request via the interface (for example, the user only selects "table structure" and "index", but not "partition" and "foreign key"), the user's selection result and the preset component support list are intersected, and the overlapping part is taken as the component type to be used.
[0084] Step S203: Parse the structured dataset to obtain the change type.
[0085] It should be understood that the change type can be a classification identifier of the model operation semantics targeted by the script generation (e.g., adding a table, modifying a field, deleting an index, renaming a view, adding constraints, synchronizing the full structure, etc.).
[0086] In practical implementation, change type fields can be read directly from structured datasets. These fields are automatically marked based on model change status during the adaptive metadata encapsulation phase. For example, if a new table is added to the data model, the change type field is marked as "CREATE"; if a table is deleted, it is marked as "DROP"; and if the data type of a field in a table changes, it is marked as "ALTER".
[0087] In one example, the current model state in the structured dataset can be compared item by item with the model snapshot recorded when the script was last generated, to identify newly added database objects, deleted database objects, and database objects whose attributes have changed.
[0088] Step S204: Perform template matching based on the database type, the component type, and the change type to obtain the target template.
[0089] In the specific implementation, a "three-dimensional coordinate" consisting of database type, component type, and change type is used as the search criteria to perform precise matching in the template library. Each template entry in the template library is labeled with a corresponding database type tag, component type tag, and change type tag. For example, a template entry for creating a table in a MySQL database has the tag combination "MySQL 8.0, table component, CREATE". The database type, each component type in the component type set, and the change type are combined into multiple three-dimensional query criteria, and matching template entries are retrieved from the template library for each criterion. All matching template entries together constitute the target template.
[0090] In one example, a separate list of component DDL templates is maintained for each database type. These template lists are stored as a template library, with each database type corresponding to a separate template directory or set. Each template entry in the list supports management actions such as adding, modifying, enabling, disabling, importing, or exporting via the user interface. When adapting to a new database type, simply add the corresponding component template file to the template directory for that database type, or import a pre-written template file from an external source; no modification to any business logic code is required. When the syntax of a database is upgraded or changed, simply disable the old template and modify or add the new template in the interface to complete the syntax adaptation.
[0091] Furthermore, in order to ensure the continuity of the script generation process and facilitate the gradual improvement of the template library coverage, after step S20, the method further includes: if no target template is matched, a template missing prompt is returned, and a preset default template is used as the target template.
[0092] It should be understood that a template missing message can be a notification displayed to the user when a template match fails, including but not limited to missing database type names, component type names, and change type names. The default template can be a generic template file that does not contain specific database dialects.
[0093] In the specific implementation, after the template matching operation is completed, it checks whether the matching result is empty. If the matching result is empty, it means that there is no template in the template library that completely matches the current three-dimensional combination. At this time, a template missing message is returned, and the missing information is written to the system log. Along with returning the message, a default template is returned as the target template. The default template can be written in SQL syntax, without any database-specific syntax extensions, only containing the most basic CREATE, DROP, and ALTER statement framework. For example, when a MySQL-specific partitioned table creation template is missing, the default template generates a basic table creation statement without a partition clause. Although the partitioning function cannot be implemented, the table creation operation can be completed normally. Templates can also use template engine syntax such as Freemarker, supporting conditional judgments, loop iterations, function calls, and optional fragment control to adapt to the differences in indexing methods, partitioning expressions, tablespace syntax, and comment syntax between different databases.
[0094] For ease of understanding, please refer to Figure 5 Examples are provided for illustration only, but are not intended to limit this application. Figure 5 This is a schematic diagram of the script generation process according to an embodiment of the script execution method of this application. Figure 5 As shown, the process begins with receiving a script generation request, which includes, but is not limited to, the target library identifier, model identifier, and the range of script types selected by the user. Upon receiving the request, the metadata in the data model is read based on the request parameters and filtered according to criteria such as target library type, library instance, and schema to obtain the model metadata to be processed (e.g., tables, views, fields, indexes, partitions, etc.). Then, a corresponding rendering parameter set (or template context object) is constructed for each selected component. The rendering parameter set includes table names, field lists, primary key lists, index lists, partition configurations, etc. After construction, the corresponding DDL template is matched from the template library based on a three-dimensional combination of database type, component type, and change type. If a match is successful, the target template is loaded, the rendering parameter set is input into the template engine for variable substitution and logic execution, and each component is rendered according to the target database's syntax rules to generate corresponding DDL fragments. The fragments are then merged into a complete DDL script based on the dependencies between components and output. If no matching template is found in the template library, a template missing message is returned to notify the user or administrator to supplement the corresponding template configuration.
[0095] This embodiment generates a request by responding to a script and determines the database type based on the target library identifier. Then, it filters the component types based on the database types and parses the structured dataset to obtain the change types. By combining these three dimensions, it completes the target template matching, achieves accurate template positioning, and effectively improves the overall efficiency of template retrieval and invocation.
[0096] This application also provides a script execution device, please refer to... Figure 6 The script execution device includes: Metadata encapsulation module 10 is used to adaptively encapsulate the metadata of the input data model in response to the input data model to obtain a structured dataset; Template matching module 20 is used to perform template matching based on the structured dataset to obtain a target template, wherein the target template includes template components; The template rendering module 30 is used to instantiate and render the structured dataset according to the target template to obtain the initial script corresponding to the template component; The script execution module 40 is used to merge the initial scripts corresponding to each template component based on the dependency relationship between the template components to obtain a script and execute the script.
[0097] The script execution device provided in this application, employing the script execution method described in the above embodiments, can solve the technical problems of high adaptation difficulty and low execution efficiency faced by data modeling platforms when outputting scripts to different databases after model completion. Compared with the prior art, the beneficial effects of the script execution device provided in this application are the same as those of the script execution method provided in the above embodiments, and other technical features in the script execution device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0098] This application provides a script execution device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the script execution method in the first embodiment described above.
[0099] The following is for reference. Figure 7The diagram illustrates a structural schematic of a script execution device suitable for implementing embodiments of this application. The script execution device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 7 The script execution device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0100] like Figure 7 As shown, the script execution device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in ROM (Read Only Memory) 1002 or a program loaded from storage device 1003 into RAM (Random Access Memory) 1004. RAM 1004 also stores various programs and data required for the operation of the script execution device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via bus 1005. Input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touch screens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, LCDs (Liquid Crystal Displays), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the script execution device to communicate wirelessly or wiredly with other devices to exchange data. Although the figures show script execution devices with various systems, it should be understood that implementation or possession of all the systems shown is not required. More or fewer systems may be implemented alternatively.
[0101] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0102] The script execution device provided in this application, employing the script execution method described in the above embodiments, can solve the technical problems of high adaptation difficulty and low execution efficiency faced by data modeling platforms when outputting scripts to different databases after model completion. Compared with the prior art, the beneficial effects of the script execution device provided in this application are the same as those of the script execution method provided in the above embodiments, and other technical features of the script execution device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0103] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0104] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0105] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the script execution method in the above embodiments.
[0106] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, RAM (Random Access Memory), ROM (Read Only Memory), EPROM (Erasable Programmable Read Only Memory), or flash memory, optical fiber, CD-ROM (CD-Read Only Memory), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0107] The aforementioned computer-readable storage medium may be included in the script execution device; or it may exist independently and not be assembled into the script execution device.
[0108] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by a script execution device, cause the script execution device to perform the aforementioned script execution method.
[0109] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including LAN (Local Area Network) or WAN (Wide Area Network)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0110] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0111] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0112] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., computer programs) for executing the above-described script execution method. This solves the technical problems of high adaptation difficulty and low execution efficiency faced by data modeling platforms when outputting scripts to different databases after model completion. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the script execution method provided in the above embodiments, and will not be elaborated upon here.
[0113] The above description is only a part of the embodiments of this application and does not limit the scope of this application. All equivalent structural transformations made under the technical concept of this application and using the content of this application specification and drawings, or direct / indirect applications in other related technical fields, are included within the protection scope of this application.
[0114] It should be noted that the data collection, tag management, rule setting, and push decision-making processes involved in this application are designed to work with other technical features to solve technical problems. They do not involve or support any illegal activities. Any data processing that may violate laws and regulations (such as unauthorized collection of privacy data, generation of discriminatory tags, setting unfair rules, or pushing illegal information) is not within the scope of protection of this application's technical solution. Of course, the user data in this application will be encrypted, anonymized, or de-identified before storage to ensure user data security.
Claims
1. A script execution method, characterized in that, The script execution method includes: In response to the input data model, the metadata of the data model is adaptively encapsulated to obtain a structured dataset; Template matching is performed based on the structured dataset to obtain a target template, wherein the target template includes template components; The structured dataset is instantiated and rendered according to the target template to obtain the initial script corresponding to the template component; Based on the dependencies between the template components, the initial scripts corresponding to each template component are merged to obtain a script, which is then executed.
2. The script execution method as described in claim 1, characterized in that, The step of instantiating and rendering the structured dataset according to the target template to obtain the initial script corresponding to the template component includes: Construct the rendering parameter set corresponding to the template component based on the structured dataset; Based on the target template, the rendering parameter set is rendered to obtain candidate scripts; The candidate scripts are subjected to syntax validation, and the candidate scripts that pass the validation are used as the initial scripts.
3. The script execution method as described in claim 2, characterized in that, The step of rendering the scene based on the target template and obtaining candidate scripts includes: Based on the script type of the rendering parameter set, scene identification is performed to obtain the current rendering scene; Based on the current rendering scene and the rendering parameter set, the target template is substituted with variables to obtain a script fragment; The script fragment is formatted to obtain candidate scripts.
4. The script execution method as described in any one of claims 1 to 3, characterized in that, The step of merging the initial scripts corresponding to each template component based on the dependencies between the template components to obtain a script, and then executing the script, includes: Construct a dependency graph based on the dependency relationships between the template components; The dependency graph is topologically sorted to obtain the execution order of the initial scripts corresponding to each template component; The initial script is assembled according to the execution order to obtain a new script, which is then executed.
5. The script execution method as described in any one of claims 1 to 3, characterized in that, Before executing the script, the process also includes: Obtain the runtime environment of the preset library instance and the runtime environment of the script; The consistency of the runtime environment of the preset library instance and the runtime environment of the script is compared and verified to obtain the comparison results; If the comparison results are inconsistent, the script execution process will be blocked, and a detailed difference message will be output. If the comparison results are consistent, a dynamic mapping relationship is established based on the runtime environment of the preset library instance and the runtime environment of the script, and the script is routed to the preset library instance.
6. The script execution method as described in any one of claims 1 to 3, characterized in that, The step of performing template matching based on the structured dataset to obtain the target template includes: In response to an input script generation request, the database type is determined based on the target library identifier in the script generation request; Based on the database type, filter by conditions to obtain the component type; The structured dataset is parsed to obtain the change type; The target template is obtained by performing template matching based on the database type, the component type, and the change type.
7. The script execution method as described in any one of claims 1 to 3, characterized in that, After obtaining the target template through template matching based on the structured dataset, the process further includes: If no target template is found, a template missing message will be returned, and the default template will be used as the target template.
8. A script execution device, characterized in that, The script execution device includes: The metadata encapsulation module is used to adaptively encapsulate the metadata of the input data model in response to the input data model, so as to obtain a structured dataset. The template matching module is used to perform template matching based on the structured dataset to obtain a target template, wherein the target template includes a template component; The template rendering module is used to instantiate and render the structured dataset according to the target template to obtain the initial script corresponding to the template component; The script execution module is used to merge the initial scripts corresponding to each template component based on the dependency relationship between the template components, obtain a script, and execute the script.
9. A script execution device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the script execution method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the script execution method as described in any one of claims 1 to 7.
