A database structure updating method and a computing device
Patent Information
- Application Number
- CN202610970183.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-30
- Publication Date
- 2026-10-16
AI Technical Summary
[0005]本申请实施例提供一种数据库结构更新方法及计算设备,解决了数据库结构更新效率和准确度较低的问题
[0026] Thirdly, embodiments of this application provide a computer-readable storage medium comprising: computer software instructions; when the computer software instructions are executed in a computing device, they cause the computing device to implement the methods provided in the first aspect and its possible embodiments.
Smart Images

Figure CN122925399A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computing device technology, and in particular to a database structure update method and computing device. Background Technology
[0002] With the continuous advancement of enterprise informatization, updating the database structure has become an important part of software development and operation and maintenance.
[0003] For example, when a business system's database needs to add new business objects, add new fields to existing data tables, modify the length or type of fields, or add indexes to improve query performance, the database structure of the database needs to be updated accordingly.
[0004] When updating the database structure involves multiple forms, multiple fields, or complex constraints, how to quickly and accurately update the database structure is a technical problem that urgently needs to be solved. Summary of the Invention
[0005] This application provides a database structure update method and computing device, which solves the problem of low efficiency and accuracy in database structure updates.
[0006] In a first aspect, embodiments of this application provide a database structure update method, the method comprising: obtaining a first database structure and target entity information; the first database structure being used to represent the actual storage structure of the first entity information in the target database; the first entity information being entity information of an object entity already stored in the target database; the target entity information being entity information of an object entity to be updated in the target database; using bytecode tools to create entity classes from the target entity information to obtain entity classes carrying object-relational mapping annotations; the entity class being used to represent the object entity corresponding to the target entity information; the object-relational mapping annotations being used to define the storage structure of the target entity information in the database; loading the entity class into an object-relational mapping framework, and calling the object-relational mapping framework to parse the entity class and the object-relational mapping annotations to obtain a second database structure; the second database structure being used to represent the expected storage structure of the target entity information in the target database; generating a structure change script based on the structural differences between the first database structure and the second database structure, and calling the structure change script to update the target database; the updated database structure of the target database being the same as the second database structure; and the structure change script being used to indicate changes to the database structure of the target database.
[0007] This solution uses bytecode analysis to create entity classes from the target entity information, resulting in entity classes carrying Object-Relational Mapping (ORM) annotations. The ORM framework is then used to parse these entity classes and annotations to obtain a second database structure. This allows the expected database structure (the second database structure) to be automatically generated based on the target entity information. In this way, regardless of how much entity information needs to be updated (e.g., adding multiple tables, fields, or indexes), the expected database structure can be obtained uniformly and completely using this method, thereby improving the efficiency of database structure updates.
[0008] Furthermore, by generating a structure change script based on the structural differences between the first and second database structures, and then calling this script to update the target database, the structural differences are automatically converted into an executable structure change script, and the update of the target database is completed automatically. The structural differences between the first and second database structures can be directly identified and processed, eliminating the need for manual comparison of each table and field and execution of changes row by row, thereby improving the accuracy and efficiency of database structure updates.
[0009] In some embodiments, loading entity classes into an object-relational mapping (ORM) framework and calling the ORM framework to parse entity classes and ORM annotations to obtain a second database structure includes: loading entity classes into an ORM framework in a temporary storage environment independent of the target database, and calling the ORM framework to parse entity classes and ORM annotations to generate data definition language (DML) statements recognizable by the temporary storage environment; and executing the DML statements in the temporary storage environment to generate a second database structure in the temporary storage environment.
[0010] In this embodiment, by generating a second database structure in a temporary storage environment independent of the target database, the generation process of the second database structure is physically isolated from the target database. Since the temporary storage environment is independent of the target database, the generation and execution of data definition language statements do not affect the target database, thus avoiding irreversible modifications to the target database due to errors in entity class creation or annotation parsing, thereby improving the security of database structure updates.
[0011] In some embodiments, generating a structure change script based on the structural differences between a first database structure and a second database structure includes: using a database migration tool to generate a first structural snapshot of the first database structure and a second structural snapshot of the second database structure; comparing the structural snapshot differences between the first and second structural snapshots, and generating a structure change script based on the structural snapshot differences.
[0012] In this embodiment, a database migration tool is used to generate a first structural snapshot of the first database structure and a second structural snapshot of the second database structure. The first and second database structures are then described in a standardized manner using these structural snapshots, allowing for item-by-item comparison of the two database structures in a unified format. Since the structural snapshots contain complete descriptive information of all objects in the database structure (such as tables, fields, indexes, constraints, sequences, etc.), the database migration tool can completely identify all structural snapshot differences between the first and second database structures based on these snapshots. This avoids potential omissions that might occur when manually checking each table and field individually, thereby improving the accuracy of structural difference identification.
[0013] In some embodiments, obtaining target entity information includes: obtaining entity metadata of stored object entities from a target database and receiving entity metadata of object entities to be updated generated from a low-code platform; generating target entity information based on the entity metadata of stored object entities and the entity metadata of object entities to be updated.
[0014] In this embodiment, by obtaining the entity metadata of the stored object entities from the target database and receiving the entity metadata of the object entities to be updated generated by the low-code platform, the target entity information is generated by merging them. This ensures that the target entity information reflects both the existing entity metadata of the target database and the entity metadata to be changed from the low-code platform, thereby ensuring that the second database structure can be generated simultaneously to cover both the stored object entities and the object entities to be updated, reducing the possibility of missing entity metadata.
[0015] In some embodiments, generating target entity information based on the entity metadata of the stored object entity and the entity metadata of the object entity to be updated includes: when the object entity to be updated includes a first object entity, the stored object entity includes a second object entity, and the first object entity and the second object entity are the same object entity, updating the entity metadata of the second object entity based on the entity metadata of the first object entity, and generating target entity information based on the updated entity metadata.
[0016] In this embodiment, when the object entity to be updated and the stored object entity are the same object entity, the original entity metadata is replaced with the entity metadata to be updated to generate target entity information, so that the target entity information can update the entity metadata of the same entity object, thereby improving the completeness and accuracy of the target entity information generation.
[0017] In some embodiments, entity information includes at least one of the following: table information, field information, index information, constraint information, or sequence information.
[0018] In this embodiment, by limiting entity information to at least one of table information, field information, index information, constraint information, or sequence information, the target entity information can cover multiple core elements of the database structure, providing specific and operable comparison items for subsequent generation of the second database structure and difference comparison, thereby improving the accuracy of the structure description during the database structure update process.
[0019] In some embodiments, after invoking the structure change script to update the target database, the method further includes: storing the structure differences and / or the structure change execution information corresponding to the structure change script; the structure change execution information includes at least one of the following: the database structure change identifier of the target database, the database structure change execution time of the target database, the database structure change execution status of the target database, or the database structure change execution result of the target database.
[0020] In this embodiment, after the target database is updated, key information about each database structure change is persistently saved by storing structural differences and / or structural change execution information (including at least one of change identifier, execution time, execution status, and execution result) so as to facilitate subsequent traceability and problem localization, thereby improving the manageability and traceability of database structure updates.
[0021] In some embodiments, if the database structure change of the target database fails, the method further includes: rolling back the database structure of the target database to the same database structure as the first database structure.
[0022] In this embodiment, by rolling back the database structure to the same state as the first database structure when the target database structure change fails, the database structure of the target database can be automatically restored to the database structure before the update after the database structure change fails. This avoids inconsistency or incompleteness of the database structure caused by the change failure, thereby improving the fault tolerance and stability of the database structure update.
[0023] In some embodiments, before generating a structure change script based on the structural differences between the first database structure and the second database structure, the method further includes: filtering preset entity information from the first database structure and / or the second database structure; the preset entity information includes at least one of the following: temporary entity information, backup entity information, version entity information, and historical log entity information.
[0024] In this embodiment, by filtering preset entity information from the first database structure and / or the second database structure, the interference of invalid entity information on database structure updates is avoided, thereby improving the accuracy and efficiency of database structure updates.
[0025] In a second aspect, embodiments of this application provide a computing device including a processor and a memory; the processor is coupled to the memory; the memory is used to store computer instructions, which are loaded and executed by the processor to enable the computing device to implement the methods provided in the first aspect and its possible embodiments described above.
[0026] Thirdly, embodiments of this application provide a computer-readable storage medium comprising: computer software instructions; when the computer software instructions are executed in a computing device, they cause the computing device to implement the methods provided in the first aspect and its possible embodiments.
[0027] Fourthly, embodiments of this application provide a computer program product that, when run on a computing device, causes the computing device to execute the steps of the relevant method described in the first aspect above, so as to implement the method of the first aspect above.
[0028] The beneficial effects of the second to fourth aspects mentioned above can be referred to the corresponding description of the first aspect, and will not be repeated here. Attached Figure Description
[0029] Figure 1 A schematic flowchart illustrating a database structure update method provided in an embodiment of this application; Figure 2 A flowchart illustrating another database structure update method provided in this application embodiment; Figure 3 This is a schematic diagram of the architecture of a computing device provided in an embodiment of this application. Detailed Implementation
[0030] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0031] In the description of this application, unless otherwise stated, " / " indicates that the objects before and after are in an "or" relationship. For example, A / B can mean A or B. "And / or" in this application is merely a description of the relationship between the related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. A and B can be singular or plural.
[0032] Furthermore, in the description of this application, unless otherwise stated, "multiple" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of a single item or a plurality of items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0033] Furthermore, to facilitate a clear description of the technical solutions in the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that "first" and "second" are not necessarily different. Meanwhile, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is being used as an example, illustration, or description. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.
[0034] It should be noted that in the embodiments of this application, the words "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplarily" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.
[0035] The following provides an exemplary description of the application scenarios of the embodiments of this application.
[0036] As described in the background section, with the continuous advancement of enterprise informatization, updating the database structure has become an important part of software development and operation.
[0037] For example, a company's human resources management system needs to add a business object called "employee training records" and a "contact person" field to the employee basic information table. In this case, the computing device needs to update the original database structure, that is, add the "employee training records" and "contact person" fields to the target database to make the updated database structure consistent with the target database structure.
[0038] When employee training involves multiple forms and a large number of employees leading to a large number of emergency contact fields, how to quickly and accurately update the database structure is a pressing technical problem that needs to be solved.
[0039] Based on this, embodiments of this application provide a database structure update method, which can: obtain a first database structure and target entity information.
[0040] Wherein, the first database structure is used to represent the actual storage structure of the first entity information in the target database; the first entity information is the entity information of the object entity already stored in the target database; and the target entity information is the entity information of the object entity to be updated in the target database.
[0041] Then, bytecode tools can be used to create entity classes from the target entity information to obtain entity classes carrying object-relational mapping annotations.
[0042] Among them, the entity class is used to represent the object entity corresponding to the target entity information; the object relation mapping annotation is used to define the storage structure of the target entity information in the database.
[0043] Then, the entity class can be loaded into the object-relational mapping framework, and the object-relational mapping framework can be called to parse the entity class and object-relational mapping annotations to obtain the second database structure.
[0044] The second database structure is used to represent the expected storage structure of the target entity information in the target database.
[0045] Subsequently, a structure change script can be generated based on the structural differences between the first and second database structures, and this script can be invoked to update the target database. The updated target database will have the same structure as the second database; the structure change script is used to indicate changes to the target database's structure.
[0046] This solution uses bytecode analysis to create entity classes from the target entity information, resulting in entity classes carrying Object-Relational Mapping (ORM) annotations. The ORM framework is then used to parse these entity classes and annotations to obtain a second database structure. This allows the expected database structure (the second database structure) to be automatically generated based on the target entity information. In this way, regardless of how much entity information needs to be updated (e.g., adding multiple tables, fields, or indexes), the expected database structure can be obtained uniformly and completely using this method, thereby improving the efficiency of database structure updates.
[0047] Furthermore, by generating a structure change script based on the structural differences between the first and second database structures, and then calling this script to update the target database, the structural differences are automatically converted into an executable structure change script, and the update of the target database is completed automatically. The structural differences between the first and second database structures can be directly identified and processed, eliminating the need for manual comparison of each table and field and execution of changes row by row, thereby improving the accuracy and efficiency of database structure updates.
[0048] The system architecture of the embodiments of this application will be described exemplarily below.
[0049] The database structure update method provided in this application can be applied to computing devices.
[0050] This application does not impose any restrictions on the specific form of the computing device. For example, the computing device can be a server. The server can be a single server, or a server cluster consisting of multiple servers. In some embodiments, the server cluster can also be a distributed cluster, and this application does not limit this. As another example, the computing device can specifically be a terminal device.
[0051] The terminal device can be referred to as: terminal, user equipment (UE), terminal device, access terminal, user unit, user station, mobile station, remote station, remote terminal, mobile device, user terminal, wireless communication equipment, user agent, or user equipment, etc. Specifically, the terminal device can be a mobile phone, augmented reality (AR) device, virtual reality (VR) device, tablet computer, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc.
[0052] In some embodiments, the computing device may be deployed with a target database. This target database may store entity information of stored object entities using a first database structure (i.e., the current database structure).
[0053] In some embodiments, the target database may also be deployed in other electronic devices. When the target database is deployed in other electronic devices, the computing device can communicate with those electronic devices to update the database structure of the target database.
[0054] For ease of understanding, this application uses the example of deploying the target database in a computing device for illustration.
[0055] In some embodiments, the computing device may include a human-computer interaction device (including a display, keyboard and mouse, etc.). The computing device may also be deployed with a low-code platform. The computing device can display the user interface of the low-code platform on the display. Users can perform entity metadata update operations on the low-code platform's user interface, including: adding entity metadata for object entities, modifying and / or deleting entity metadata of object entities already stored in the target database, etc.
[0056] The computing device can receive entity metadata of the object entity to be updated generated from the low-code platform, and then generate target entity information based on the entity metadata of the object entity already stored in the target database and the entity metadata of the object entity to be updated generated by the low-code platform. Subsequently, a second database structure can be generated based on the target entity information, and the database structure of the target database can be updated by comparing the structural differences between the first database structure and the second database structure.
[0057] It should be noted that when a low-code platform is deployed on a computing device, the computing device can respond to the user's operation interface on the low-code platform to perform an entity metadata update operation and generate entity metadata of the object entity to be updated. Essentially, the processor of the computing device receives the entity metadata of the object entity to be updated generated from the low-code platform program or service instance.
[0058] In some embodiments, the low-code platform can also be deployed in other electronic devices. When the low-code platform is deployed in other electronic devices, the computing device can communicate with that electronic device to receive entity metadata of the object entity to be updated generated by the low-code platform.
[0059] For ease of understanding, this application uses the deployment of a low-code platform in a computing device as an example for illustration.
[0060] The database structure update method provided in the embodiments of this application will be described in detail below.
[0061] like Figure 1 The diagram shown is a flowchart illustrating a database structure update method provided in an embodiment of this application. Figure 1 The method shown can be applied to computing devices. This database structure update method includes: S101, The computing device acquires the first database structure and target entity information.
[0062] The first database structure represents the actual storage structure of the first entity information in the target database. This first entity information refers to the entity information of the object entity already stored in the target database. The target entity information refers to the entity information of the object entity to be updated in the target database.
[0063] Specifically, the computing device may be deployed with a target database. This target database can store the entity information of the stored object entities through a first database structure (i.e., the current database structure). The computing device can read the system tables of the target database through the target database's communication interface. These system tables record the structural information of the entire target database, such as: what tables are in the target database, what columns are in each table, what indexes are defined on the tables, and what primary keys, foreign keys, and unique constraints exist between the tables. The computing device retrieves the database structure information from the system tables by executing query statements, thereby obtaining the actual storage structure corresponding to the entity information of the stored object entities, i.e., the first database structure.
[0064] Optionally, the first database structure may include table names, field names, field types, field lengths, index definitions (such as index names, types, and included fields), constraint definitions (used to describe rules that ensure data integrity and consistency, such as primary keys, foreign keys, unique constraints, etc.), and sequence definitions (used to describe objects that automatically generate numerical sequences, such as sequence names, starting values, step sizes, etc.). This first database structure reflects the current physical storage state of the target database, such as which tables already exist, which fields each table contains, the data types and lengths of the fields, and the indexes and constraints that have been established.
[0065] In addition, computing devices can also acquire information about target entities.
[0066] In some embodiments, the target entity information can be divided into two parts: one part is the entity information of the already stored object entity, and the other part is the entity information of the object entity to be updated.
[0067] For existing object entities, the computing device can read existing entity metadata from the target database. For object entities to be updated, the computing device can receive entity metadata from the low-code platform or the business configuration port.
[0068] Metadata is a series of data describing data structures and cannot be directly used for subsequent database structure comparisons. Therefore, computing devices can parse the entity names, field definitions, and other content in the aforementioned entity metadata, and merge, update, or replace them, transforming them into a standardized entity information format to generate entity information that the computing device can recognize, i.e., target entity information.
[0069] In one feasible approach, the computing device can parse the entity name, field definitions, and other content in the aforementioned entity metadata, merge, update, or replace them, and then transform them into a standardized entity information format (e.g., a data structure containing table information, field information, index information, constraint information, etc.) to obtain complete target entity information.
[0070] The target entity information describes the latest structural definition of all object entity information (including the entity information of existing object entities and the entity information of object entities to be updated), providing a foundation for the subsequent generation of the expected database structure.
[0071] In some embodiments, entity information includes at least one of the following: table information, field information, index information, constraint information, or sequence information.
[0072] The table information may include the table name, table comments, storage engine, etc.
[0073] Field information can include field name, field type, field length, whether it can be nullable, default value, etc.
[0074] Index information can include the index name, index type (e.g., normal index, unique index, full-text index, etc.), the fields included in the index, and the sorting rules.
[0075] Constraint information can include primary key constraints, foreign key constraints, unique constraints, check constraints, etc.
[0076] Sequence information can include sequence name, starting value, step size, minimum value, maximum value, buffer size, etc.
[0077] These entity information collectively describe the complete structural definition of the object entity in the target database, providing a foundation for the subsequent generation of the expected database structure (i.e., the second database structure).
[0078] S102. The computing device uses bytecode tools to create entity classes from the target entity information to obtain entity classes carrying object-relational mapping annotations.
[0079] Entity classes are used to represent the object entities corresponding to the target entity information; for example, one entity class corresponds to one business table.
[0080] Object-relational mapping (ORM) annotations are used to define the storage structure of target entity information in the database. For example, they can map the attributes of an entity class to columns in a database table and specify the field type, length, constraints, as well as table-level indexes, unique constraints, etc.
[0081] Specifically, a bytecode generation tool is a code generation tool that can directly manipulate Java class bytecode during program execution. It can dynamically create new Java classes or modify the structure of existing classes in memory without writing source code files. By manipulating bytecode instructions recognizable by the Java Virtual Machine (JVM), the bytecode generation tool generates complete class definitions at runtime, including class names, attributes, methods, and annotation information. The generated classes can be directly loaded and instantiated by the JVM. This approach allows entity classes to be dynamically generated entirely based on the target entity information obtained at runtime (i.e., the latest non-broad metadata), without the need for pre-definition or manual coding.
[0082] After acquiring the target entity information, the computing device uses this information as input parameters for the bytecode tool. Based on the entity name in the target entity information, the bytecode tool creates a corresponding Java class and adds corresponding attributes and object-relational mapping annotations to this Java class according to the field definitions, index constraints, and other content in the target entity information.
[0083] For example, for an employee object entity described in the target entity information, the bytecode tool can generate a Java class named Employee, which contains the various attributes of the object entity, add an Object Relational Mapping annotation to the class that marks the database table corresponding to the entity, and add an Object Relational Mapping annotation to each attribute that marks the database column corresponding to the attribute.
[0084] Object-relational mapping (ORM) annotations are used to establish a mapping relationship between objects in a programming language and database structures such as tables, fields, indexes, and constraints in a relational database. These annotations can declare which database table a class corresponds to, which column in the table a specific attribute of a class corresponds to, and details such as the column's type, length, nullability, and uniqueness constraints.
[0085] In the embodiments of this application, the object-relational mapping annotation can be an annotation under the Java Persistence API (JPA) specification, or a Hibernate annotation, or any other annotation that can implement the function of mapping objects to database structures. This application does not make any specific limitations on this.
[0086] Among them, JPA annotations are a set of standardized object-relational mapping annotations in the Java platform, while Hibernate annotations refer to the annotations provided by the Hibernate object-relational mapping framework. The two are specific implementations of different ORM annotation methods.
[0087] Since the target entity information already clearly defines all the structural details of the object entity, such as tables, fields, indexes, and constraints, the bytecode tool can accurately map this information to the corresponding object-relational mapping annotation parameters, enabling the generated entity class to be recognized by the subsequent object-relational mapping framework and used to automatically generate the database structure.
[0088] Optionally, the computing device may be equipped with a dynamic entity generation module (also known as a dynamic entity generator). The computing device can utilize the dynamic entity generation module to generate corresponding entity classes based on the target entity information.
[0089] Then, the computing device can use the dynamic entity generation module to create the bytecode of a Java class based on the table information, field information, index information, constraint information, or sequence information in the target entity information, and add the corresponding ORM annotations to the Java class.
[0090] S103. The computing device loads the entity class into the object-relational mapping framework and calls the object-relational mapping framework to parse the entity class and object-relational mapping annotations to obtain the second database structure.
[0091] Specifically, after creating an entity class carrying an object-relational mapping (ORM) annotation, the computing device loads the entity class into the ORM framework and calls the ORM framework to parse the entity class and the ORM annotation to obtain a second database structure representing the expected storage structure.
[0092] Object-relational mapping frameworks can identify entity classes with specific annotations (such as those used to mark entities, fields, relationships, etc.) and parse the mapping rules defined in these annotations.
[0093] After the entity class is successfully loaded, the computing device can invoke the automatic table creation capabilities of the object-relational mapping framework, such as the schema export or schema update tools in the object-relational mapping framework, to parse the entity class and object-relational mapping annotations to obtain a second database structure.
[0094] The second database structure represents the expected storage structure of the target entity information in the target database. In other words, the second database structure describes the complete structure of tables, fields, indexes, constraints, sequences, etc., that should exist in the target database according to the latest entity information (including the entity information of the already stored object entities and the entity information of the object entities to be updated).
[0095] In some embodiments, the computing device can generate the second database structure based on the target entity information in a storage environment independent of the target database, so as to avoid direct or irreversible impact on the target database. For example, the computing device can generate the second database structure based on the target entity information in a temporary storage environment independent of the target database. The specific generation process can be referred to the description below, and will not be repeated here.
[0096] Following the example above, suppose the computing device uses a bytecode tool to generate a Java class named "Employee". Next, the computing device can load this Java class into the Hibernate object-relational mapping framework and call the framework to parse the Java class and its object-relational mapping annotations to obtain the "Employee" table, a second database structure.
[0097] In some embodiments, the computing device can also combine an artificial intelligence model to generate a second database structure. For example, after obtaining target entity information, the computing device can input the target entity information into an artificial intelligence model, and the artificial intelligence model can automatically recommend the content required to build the database structure, such as tables, fields, indexes, constraints, and sequences, thereby obtaining a second database structure to optimize the design of the database structure.
[0098] S104. The computing device generates a structure change script based on the structural differences between the first database structure and the second database structure.
[0099] The structure change script is used to indicate changes to the database structure of the target database.
[0100] Specifically, the computing device can compare the first database structure (actual storage structure) with the second database structure (expected storage structure) item by item to identify the differences between the two in terms of tables, fields, indexes, constraints, sequences, etc., i.e., structural differences.
[0101] The aforementioned structural differences include, but are not limited to: objects that exist in the second database structure but are missing in the first database structure (such as newly added tables, fields, indexes, etc.), objects that exist in the first database structure but are missing in the second database structure (such as redundant tables that need to be deleted, expired fields, etc.), and objects that exist in both but have inconsistent definitions (such as different field types, lengths, default values, or different index types, etc.).
[0102] Based on the above example, suppose the employee table in the first database structure, which records an entity named "employee," only contains two fields: employee ID and employee name. However, in the second database structure, the same employee table also includes a department ID field. By comparing these two fields, the computing device can identify the following structural difference: the first database structure lacks the department ID field.
[0103] In some embodiments, the computing device may invoke a difference comparison and change script generation module (also known as a database snapshot and comparator) to perform an item-by-item comparison of the first database structure and the second database structure.
[0104] During the comparison process, the computing device can generate structural snapshots (i.e., standardized description files describing all database objects) for the two database structures respectively, and then traverse the entity information in the two structural snapshots to identify the structural differences between them.
[0105] In some embodiments, the difference comparison and change script generation module can connect to the actual database (i.e., the target database) corresponding to the first database structure and the temporary storage environment (e.g., an H2 in-memory database) corresponding to the second database structure, respectively. It automatically generates difference results using the tool's built-in snapshot and diff commands. These difference results describe all structural points that need to be changed, i.e., the structural differences.
[0106] In some embodiments, the computing device may also convert the above-mentioned structural differences into a standardized changelog file and generate a structural change script based on the changelog file.
[0107] The change log file contains sequentially organized change sets, each corresponding to an atomic database structure change operation, such as creating a table, adding a column, modifying a column type, creating an index, or adding a constraint.
[0108] Optionally, the generated structural change script can be in the format of a Structured Query Language (SQL) script, or in the format of Extensible Markup Language (XML), JSON (javascript object notation), or YAML, depending on the configuration of the tool used.
[0109] Regardless of the format used, the structure change script describes all the operations required to convert the first database structure into the second database structure; that is, it instructs the target database structure to be changed according to the structural differences. In some embodiments, before comparing the structural differences between the first and second database structures, the computing device may also exclude certain entity information that is not of interest (such as temporary tables, backup tables, system-generated log tables, etc.) according to preset filtering rules to avoid invalid differences interfering with subsequent updates.
[0110] S105. The computing device calls the structural change script to update the target database.
[0111] The updated target database has the same database structure as the second database.
[0112] In some embodiments, the computing device may invoke a change executor to apply the aforementioned structural change script to the target database.
[0113] The change executor (also known as the change execution module) can establish a connection with the target database and execute the various change operations in the structure change script in sequence, thereby updating the target database.
[0114] Through the above steps, the computing device can automatically convert structural differences into executable change scripts, automatically execute the structural change scripts, complete the update of the target database structure, and ultimately make the structure of the target database the same as the structure of the second database.
[0115] Continuing with the above example, suppose the computing device identifies a structural difference in the first database structure where the department identifier field is missing. The computing device can perform an update operation on the target database, including adding the department identifier field to the employee table. After performing the update operation, the employee table in the target database will have three fields: employee identifier, employee name, and department identifier, consistent with the second database structure.
[0116] In summary, the database structure update method provided in this application can automatically generate a second database structure based on the target entity information. No matter how much content needs to be updated (e.g., adding multiple tables, fields, or indexes), the expected database structure can be obtained uniformly and completely through this method, thereby improving the efficiency of database structure updates.
[0117] The following describes the specific process by which the computing device generates the second database structure.
[0118] In some embodiments, the method in S103 above, in which the computing device loads entity classes into an object-relational mapping (ORM) framework and calls the ORM framework to parse entity classes and ORM annotations to obtain a second database structure, specifically includes: First, in a temporary storage environment independent of the target database, entity classes are loaded into the Object-Relational Mapping (ORM) framework. The ORM framework is then invoked to parse the entity classes and ORM annotations, generating Data Definition Language (DDL) statements recognizable by the temporary storage environment. Next, the DDL statements are executed within the temporary storage environment to generate a second database structure.
[0119] Specifically, the computing device first needs to prepare a temporary storage environment independent of the target database. This temporary storage environment can be an in-memory database (such as H2 database (an open-source Java relational database)) or other lightweight database instances.
[0120] The temporary storage environment is physically isolated from the target database, and all subsequent operations are performed in this environment without affecting the target database.
[0121] The Object-Relational Mapping (ORM) framework can automatically generate corresponding Data Definition Language (DDL) statements based on entity classes and their annotations, and execute these statements in a temporary storage environment to create a complete database structure. This database structure is the second database structure, which contains all the expected storage structures such as tables, fields, indexes, constraints, and sequences described by the target entity information.
[0122] The object-relational mapping framework can automatically handle the syntactic differences between different database languages (such as PostgreSQL, MySQL, etc.) and generate data definition language statements with corresponding syntax according to the database type of the temporary storage environment (such as H2 database), thereby successfully creating a second database structure in the temporary storage environment.
[0123] The object-relational mapping framework has good database compatibility, supports multiple database types (such as H2, PostgreSQL, MySQL, etc.), and can automatically adapt according to the actual data source type being connected.
[0124] After the difference comparison or database update is completed, the temporary storage environment can be destroyed to free up system resources.
[0125] Through the above steps, the computing device achieves automated generation of a second database structure from non-broad metadata, and is isolated from the target database, ensuring security and verifiability.
[0126] The following describes the specific process for generating structural change scripts using computing devices.
[0127] In some embodiments, the method for the computing device to generate a structure change script based on the structural differences between the first database structure and the second database structure in S104 specifically includes: First, the computing device uses a database migration tool to generate a first structural snapshot of a first database structure and a second structural snapshot of a second database structure. Then, the computing device compares the structural snapshot differences between the first and second structural snapshots and generates a structural change script based on these differences.
[0128] Database migration tools are open-source database change management solutions that use changelog files to sequentially record all structural changes to the database, enabling version control of the database structure to be managed like application code.
[0129] The database migration tool supports multiple database types, including MySQL and PostgreSQL, and allows the use of various formats such as Structured Query Language (SQL), Extensible Markup Language (XML), JSON (JavaScript Object Notation), or YAML to define database changes.
[0130] It should be noted that the database structure update method provided in this application is not limited to the above-mentioned database types, and can also be adapted to other relational databases, such as Oracle databases, SQL Server databases, etc.
[0131] Optionally, the database migration tool mentioned above can be Liquibase (an open-source database structure version management tool).
[0132] A structure snapshot is a standardized description of the current structural state of a database provided by a database migration tool. It represents the complete structural information of the database in memory in an object-oriented manner. The first structure snapshot describes the actual storage structure of the target database at the current moment, while the second structure snapshot describes the expected storage structure generated in the temporary storage environment.
[0133] Database migration tools retrieve information about various structural objects in the database by querying system tables or metadata views, and then convert this information into a structured object graph. The structure snapshot contains various entity objects within the database structure. These entity objects are organized in a structured manner, and each entity object contains complete attribute information, such as table names and comments, column names and data types, index names and their contained fields, etc.
[0134] The computing device can call the difference comparison function of the database migration tool to compare the first and second structural snapshots item by item and identify the structural snapshot differences between the two structural snapshots.
[0135] Snapshot differences refer to the differences between the first and second snapshots at the database structure object level. During the comparison process, the database migration tool performs object-level matching and comparison of objects in the two snapshots. Snapshot differences can be categorized into the following three types: The first type is the missing object, which is a structural object that exists in the second structural snapshot but not in the first structural snapshot. The second type is the redundant object, which is a structural object that exists in the first structural snapshot but not in the second. The third type is the changed object, which is a structural object that exists in both the first and second structural snapshots but has an inconsistent definition.
[0136] Database migration tools transform each difference item in the structure snapshot into a corresponding changeset, and organize all changesets into a structure change script according to dependencies and execution order. Each changeset corresponds to an atomic database structure change operation, such as creating a table, adding a column, modifying a column type, creating an index, or adding constraints.
[0137] For missing objects (objects that exist in the second structure snapshot but not in the first structure snapshot), the database migration tool generates corresponding creation operations; for redundant objects (objects that exist in the first structure snapshot but not in the second structure snapshot), the database migration tool generates corresponding deletion operations; for modified objects (objects that exist in both structure snapshots but have inconsistent definitions), the database migration tool generates corresponding modification operations.
[0138] Through the above process, the computing device uses a database migration tool to automatically generate structure change scripts from the first database structure and the second database structure. During the structure snapshot generation and difference comparison process, the database migration tool processes database structure information in a structured manner, avoiding omissions or errors that might occur during manual item-by-item comparison. Simultaneously, the generated standardized structure change scripts provide a traceable and auditable basis for subsequent database updates.
[0139] The following describes the specific process by which computing devices acquire information about target entities.
[0140] In some embodiments, the method for the computing device to obtain target entity information in S101 above specifically includes: S101-1 The computing device obtains the entity metadata of the stored object entity from the target database and receives the entity metadata of the object entity to be updated generated from the low-code platform.
[0141] Specifically, the entity metadata of the stored object entities describes the structural definition of the object entities that already exist in the current target database.
[0142] As shown above, the target database maintains a system table that records the structural information of the entire target database. Since this structural information is determined by entity metadata, the computing device can extract entity metadata from this system table to obtain the entity metadata of the stored object entities.
[0143] The entity metadata of the object to be updated comes from the low-code platform.
[0144] A low-code platform is a development environment that defines the structure of business objects through visual configuration. In this low-code platform, users can define the structural information of business objects, such as entity name, field name, field type, field length, index, and constraints, by dragging and dropping graphical components and filling in attribute forms, without having to write code manually.
[0145] Low-code platforms can transform the above configuration operations into a series of descriptive data (i.e., metadata). Because the types and attribute ranges of metadata are relatively fixed (e.g., entities, fields, indexes, constraints, etc., are preset and not arbitrarily extended or defined by end users), this design is called non-broad metadata. Computing devices can automatically generate identifiable entity information based on this well-structured metadata, thereby supporting subsequent automated updates to the database structure.
[0146] In this way, the computing device obtains both the entity metadata of the stored object entities that reflects the current actual situation of the database and the entity metadata of the object entities to be updated from the low-code platform, providing a data foundation for the generation of target entity information.
[0147] In some embodiments, the entity metadata of the object entity to be updated can also be generated through a business process engine or a permission system. For example, when a business process changes, the business process engine can automatically generate the corresponding entity structure change definition and trigger the low-code platform to generate the corresponding metadata. When permission data in the permission system needs to be adjusted, the low-code platform can be called to generate permission-related tables, fields, and other metadata.
[0148] By deeply integrating the method of this application with business process engines, permission systems, and other systems, more complex metadata-driven scenarios can be realized, further improving the automation level of database structure updates.
[0149] S101-2. The computing device generates target entity information based on the entity metadata of the stored object entity and the entity metadata of the object entity to be updated.
[0150] Specifically, after acquiring the entity metadata of the stored object entity and the entity metadata of the object entity to be updated, the computing device can merge, update or replace these two parts of entity metadata to form a complete set of target entity information that represents the latest structure of all object entities.
[0151] In some embodiments, the method for generating target entity information by the computing device based on the stored entity metadata of the object entity and the entity metadata of the object entity to be updated in S101-2 above specifically includes: If the object entity to be updated includes a first object entity, the stored object entity includes a second object entity, and the first object entity and the second object entity are the same object entity, then the entity metadata of the second object entity is updated according to the entity metadata of the first object entity, and the target entity information is generated according to the updated entity metadata.
[0152] Optionally, when generating entity metadata for the object entity to be updated, the low-code platform can also generate an entity identifier (such as an entity name or unique number) for the object entity to be updated. When retrieving entity metadata for a stored object entity from the target database, the computing device can also retrieve the entity identifier of the stored object entity from the target database.
[0153] Next, the computing device can determine whether the object entity to be updated includes an object entity that is the same as the stored object entity based on the entity identifier of the object entity to be updated and the entity identifier of the stored object entity.
[0154] When the object entity to be updated includes an object entity that is the same as an already stored object entity—that is, when the object entity to be updated includes a first object entity, the already stored object entity includes a second object entity, and the first and second object entities are the same object entity—the computing device can update the entity metadata of the second object entity based on the entity metadata of the first object entity, replacing the original entity metadata with the latest entity metadata. It should be noted that updating the aforementioned entity metadata includes both modifying the original entity metadata and deleting the original entity metadata.
[0155] When modifying the existing entity metadata, the entity metadata of the first object entity includes the specific data content (e.g., the field name is "name"). Modifying the existing entity metadata means changing the data content in the entity metadata of the second object entity to the data content in the entity metadata of the first object entity.
[0156] When deleting the original entity metadata, the entity metadata of the first object entity does not include any specific data content; that is, the entity metadata of the first object entity is empty. Deleting the original entity metadata also means deleting the data content from the entity metadata of the second object entity, which is to configure the data content in the entity metadata of the second object entity to be empty, thereby achieving the deletion of the original entity metadata.
[0157] In addition, the object entities to be updated may include object entities that are different from the already stored object entities. The entity metadata of these different object entities can be collectively referred to as other entity metadata.
[0158] Other entity metadata includes: entity metadata of other object entities in the object entity to be updated besides the first object entity, and / or entity metadata of other object entities in the object entity that has been stored besides the second object entity.
[0159] Specifically, the entity metadata of the object entities other than the first object entity in the object entity to be updated is entity metadata that is different from the entity metadata of the object entities in the already stored object entities; that is, the entity metadata of the newly added object entities. This newly added entity metadata needs to be added to the target database.
[0160] The entity metadata of the other object entities in the stored object entities, excluding the second object entity, is entity metadata that differs from the entity metadata of the object entities in the object entity to be updated; that is, the entity metadata of the object entities that have not been updated. This unupdated entity metadata needs to be retained in the target database.
[0161] In this scenario, the computing device can generate target entity information based on the updated entity metadata and other entity metadata.
[0162] In this way, the computing device can process the entity metadata of all stored object entities and the entity metadata of the object entities to be updated in the manner described above, and generate complete target entity information based on this entity metadata.
[0163] The following describes the specific process by which computing devices filter entity information in the first and / or second database structures.
[0164] In some embodiments, prior to S104 above, i.e. before the computing device generates a structure change script based on the structural differences between the first database structure and the second database structure, the method further includes: The computing device filters preset entity information from a first database structure and / or a second database structure.
[0165] The preset entity information includes at least one of the following: temporary entity information, backup entity information, version entity information, or historical log entity information.
[0166] Specifically, before comparing the first database structure with the second database structure and generating a structure change script, the computing device can preprocess both of them, that is, filter out entity information that does not need to participate in the difference comparison.
[0167] These pre-defined entity information are usually business-unrelated, automatically generated by the system, or temporarily existing structured objects, such as temporary tables (tables that can be named temporary or tmp), backup tables (tables that can be named backup or bak), version control fields (such as system fields such as version number and update time), and historical log tables (such as historical record tables automatically generated by object-relational mapping frameworks or database migration tools, such as database change log tables, lock tables, etc.).
[0168] By filtering this entity information, invalid differences caused by non-business entity information can be avoided from interfering with the generation of subsequent change scripts.
[0169] In some embodiments, the computing device may employ a database snapshot and comparison device (also known as a difference comparison module) to implement the above-mentioned filtering operation.
[0170] Database snapshot and comparator can call database structure comparison tools (such as Liquibase) to perform the above filtering operations and supports configuring filtering rules.
[0171] For example, computing devices can set filtering rules such as: ignoring all tables whose names contain "temporary" or "backup", ignoring tables whose names are "database change log" or "database change log lock", and ignoring system fields whose field names are "version number" or "creation time", etc.
[0172] The computing device filters the first database structure (the actual structure from the target database) and / or the second database structure (the expected structure from the temporary storage environment) according to preset filtering rules, removing entity information that does not need to be of interest.
[0173] Through the above steps, the computing device can eliminate interference from irrelevant entity information, providing an accurate basis for the subsequent automatic generation of structural change scripts.
[0174] The following describes the specific process after the computing device updates the target database.
[0175] In some embodiments, after invoking the structure change script to update the target database, the method further includes: Storage structure differences and / or structure change execution information corresponding to structure change scripts.
[0176] Specifically, after executing the structural change script, the computing device can persistently store the relevant information about this change for later traceability or problem localization. This information is divided into two categories: one is the structural differences themselves, such as which tables, fields, indexes, etc. are missing; the other is the structural change execution information, that is, the metadata generated during the execution of the script.
[0177] The structural change execution information includes at least one of the following: the database structure change identifier of the target database, the database structure change execution time of the target database, the database structure change execution status of the target database, or the database structure change execution result of the target database.
[0178] Database structure change identifiers are used to uniquely identify the number or name of a change operation, such as the identifier of a changeset or the filename of a change log file.
[0179] The database structure change execution time is used to represent the timestamp of the execution of the structure change script, including the start and end times.
[0180] The database structure change execution status is used to indicate the overall status of this change operation, such as success, partial success, failure, or rollback.
[0181] Database structure change execution results are used to represent more detailed execution information, such as the number of successfully executed change statements and detailed error information for failed statements.
[0182] Optionally, the computing device can store the above information in the target database's own system tables (such as the database change log table automatically generated by Liquibase), or it can store it in a separate storage medium (such as a log file or an external database).
[0183] By storing information on differences in the database structure and / or changes to the structure, users can query historical change records at any time to understand the evolution of the database structure.
[0184] In some embodiments, if the database structure change of the target database fails, the method further includes: Roll back the target database structure to the same structure as the first database structure.
[0185] Specifically, when an error occurs during the execution of the structure change script (such as a structured query language statement violating database constraints, network interruption, insufficient permissions, etc.), causing the database structure change of the target database to fail, the computing device can trigger a rollback operation.
[0186] The goal of a rollback operation is to restore the structure of the target database to the state before the change script was executed, that is, the same state as the first database structure.
[0187] In some embodiments, the computing device may employ different rollback methods depending on the capabilities of the database migration tools used.
[0188] For example, if the database migration tool used by the computing device maintains a change history table and records the rollback statements for each change set (e.g., rollback scripts are predefined when generating change logs), the computing device can automatically execute these rollback statements to undo the executed changes one by one.
[0189] After the rollback is completed, the structure of the target database is consistent with that of the first database, thus avoiding inconsistencies in database structure or data corruption caused by the failure of partial changes.
[0190] In some embodiments, the above method can be applied to multi-environment deployment scenarios, such as development, testing, and production environments. The computing device can execute the database structure modification method for each environment separately to ensure that the database structure of each environment remains consistent with the target entity information.
[0191] Furthermore, this database structure change method can be triggered by scripts or command-line instructions in a continuous integration (CI) or continuous deployment (CD) pipeline, thereby achieving automated operation and maintenance of database structure updates.
[0192] CI / CD pipelines typically consist of a series of automated tasks (such as code fetching, compilation, testing, packaging, and deployment). In this application, a database structure update method can be integrated into such an automated pipeline, automatically triggering database structure comparison and updates when code or configuration changes, thereby achieving automated operation and maintenance.
[0193] In some embodiments, the database structure update method provided in this application can also be widely applied to enterprise-level scenarios such as data middleware, data governance, and data asset management.
[0194] For example, in the construction of a data middle platform, the database structures of different data sources need to be managed and synchronized in a unified manner. The database structure update method provided in this application embodiment can be applied to each data source respectively: obtain the current first database structure of each data source, and generate a second database structure based on the unified target entity information. Through structural difference comparison and automatic update, the database structure of each data source is kept consistent with the target entity information, thereby realizing the automatic comparison and evolution of multi-source heterogeneous database structures.
[0195] During the data governance process, the structural differences and structural change execution information stored in the embodiments of this application can be used to trace and audit the structural changes of data assets throughout the entire process, that is, to query historical change records and understand when, who, and why which structural changes were initiated.
[0196] In the context of data asset management, the database structure update method provided in this application embodiment can be executed periodically to compare the differences between the actual database structure and the expected database structure. If an inconsistency is found, a change script or alarm will be automatically generated to ensure the consistency between the actual database structure and the expected database structure.
[0197] The complete process of the database structure update method provided in the embodiments of this application is described below with reference to the accompanying drawings.
[0198] like Figure 2 As shown, the database structure update method includes: S201. The computing device retrieves the entity metadata of the stored object entity from the target database.
[0199] S202. The computing device receives entity metadata from the low-code platform for the object entity to be updated.
[0200] It should be noted that there is no restriction on the execution order of S201 and S202. The computing device may execute S201 first and then S202, or S202 first and then S201, or both S201 and S202 may be executed simultaneously.
[0201] S203. The computing device generates target entity information based on the entity metadata of the stored object entity and the entity metadata of the object entity to be updated.
[0202] S204. In a temporary storage environment independent of the target database, the computing device uses bytecode tools to create entity classes from the target entity information to obtain entity classes carrying object-relational mapping annotations.
[0203] S205. The computing device loads the entity class into the object-relational mapping framework and calls the object-relational mapping framework to parse the entity class and object-relational mapping annotations to obtain the second database structure.
[0204] S206. The computing device obtains the first database structure.
[0205] It should be noted that there is no restriction on the execution order of S201-S205 and S206. The computing device may execute S206 first and then S201-S205, or it may execute S201-S205 first and then S206, or it may execute S201-S205 and S206 simultaneously.
[0206] S207. Compare the structural differences between the first and second database structures using computing devices.
[0207] S208. The computing device generates a structural change script based on the structural differences.
[0208] S209. The computing device calls the structural change script to update the target database.
[0209] In an exemplary embodiment, this application also provides a database structure updating apparatus. This database structure updating apparatus can be a computing device that performs the aforementioned database structure updating method, or it can be a processor within the computing device. The database structure updating apparatus may include one or more functional modules for implementing the database structure updating method of the above method embodiments.
[0210] This application also provides a computing device. Figure 3 This is a schematic diagram of the architecture of a computing device provided in an embodiment of this application. Figure 3 As shown, the computing device 100 includes: one or more memories 120, one or more processors 110, a communication bus 140, and a communication interface 130. The processors 110 and memories 120 are connected via the communication bus 140; the one or more memories 120 are used to store computer program code, which includes computer instructions; when the one or more processors 110 execute the computer instructions, the computing device 100 performs the database structure update method provided in this application embodiment.
[0211] Optionally, the memory 120 may be a non-transitory computer-readable storage medium, such as a read-only memory (ROM), random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc. The embodiments of this application do not impose any limitations on this.
[0212] The processor 110 may be a central processing unit (CPU), a network processor (NP), a digital signal processor (DSP), a microprocessor, a microcontroller, a programmable logic device (PLD), or any combination thereof, and the embodiments of this application do not impose any limitations on this.
[0213] The communication bus 140 can be an industry standard architecture (ISA) bus, a peripheral component interconnect (PCI) bus, or an extended industry standard architecture (EISA) bus, etc. This communication bus 140 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 It is represented by a single thick line, but this does not mean that there is only one bus or one type of communication bus.
[0214] Communication interface 130 uses any transceiver-like device for communicating with other devices or communication networks, such as control systems, radio access networks (RAN), wireless local area networks (WLAN), etc.
[0215] It should be noted that the system architecture and application scenarios described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided in the embodiments of this application. As those skilled in the art will know, with the evolution of system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0216] This application also provides a computer-readable storage medium. All or part of the processes in the above method embodiments can be executed by computer instructions instructing related hardware; for example, the related hardware can be a processor of a computing device. The program instructions can be stored in the above-mentioned computer-readable storage medium, and when executed, the processes of the above method embodiments can be implemented. The computer-readable storage medium can be memory. The above-mentioned computer-readable storage medium can also be an external storage device, such as a hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc. Further, the above-mentioned computer-readable storage medium can include both memory and external storage devices. The above-mentioned computer-readable storage medium is used to store the above-mentioned computer program instructions and other programs and data required by the above-mentioned database structure update method.
[0217] This application also provides a computer program product comprising a computer program that, when run on a computing device, causes the computing device to execute any of the database structure update methods provided in the above embodiments.
[0218] Although this application has been described herein in conjunction with various embodiments, those skilled in the art, by reviewing the accompanying drawings, disclosure, and appended claims, will understand and implement other variations of the disclosed embodiments in carrying out the claimed application. In the claims, the word "comprising" does not exclude other components or steps, and "a" or "an" does not exclude multiple instances. A single processor or other unit can implement several functions listed in the claims. While different dependent claims may recite certain measures, this does not mean that these measures cannot be combined to produce good results.
[0219] Although this application has been described in conjunction with specific features and embodiments, it is obvious that various modifications and combinations can be made thereto without departing from the spirit and scope of this application. Accordingly, this specification and drawings are merely exemplary illustrations of this application as defined by the appended claims, and are considered to cover any and all modifications, variations, combinations, or equivalents within the scope of this application. Clearly, those skilled in the art can make various alterations and modifications to this application without departing from the spirit and scope of this application. Thus, if such modifications and modifications of this application fall within the scope of the claims of this application and their equivalents, this application is also intended to include such modifications and modifications.
[0220] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope 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.
Claims
1. A database structure update method, characterized in that, include: Obtain the first database structure and target entity information; The first database structure is used to represent the actual storage structure of the first entity information in the target database; The first entity information is the entity information of the object entity already stored in the target database; The target entity information is the entity information of the object entity to be updated in the target database; The target entity information is used to create an entity class using bytecode tools, resulting in an entity class carrying an object-relational mapping annotation; the entity class is used to represent the object entity corresponding to the target entity information; the object-relational mapping annotation is used to define the storage structure of the target entity information in the database; The entity class is loaded into the object-relational mapping framework, and the object-relational mapping framework is called to parse the entity class and the object-relational mapping annotation to obtain a second database structure; the second database structure is used to represent the expected storage structure of the target entity information in the target database; Based on the structural differences between the first database structure and the second database structure, a structure change script is generated, and the structure change script is called to update the target database; The updated target database has the same database structure as the second database structure; the structure change script is used to indicate the change of the database structure of the target database.
2. The method according to claim 1, characterized in that, The step of loading the entity class into the object-relational mapping (ORM) framework and calling the ORM framework to parse the entity class and the ORM annotation to obtain the second database structure includes: In a temporary storage environment independent of the target database, the entity class is loaded into the object-relational mapping framework, and the object-relational mapping framework is invoked to parse the entity class and the object-relational mapping annotation, generating a data definition language statement that the temporary storage environment can recognize. The data definition language statements are executed in the temporary storage environment to generate the second database structure in the temporary storage environment.
3. The method according to claim 1 or 2, characterized in that, The step of generating a structure change script based on the structural differences between the first database structure and the second database structure includes: Using a database migration tool, a first structure snapshot of the first database structure and a second structure snapshot of the second database structure are generated. The structural snapshot differences between the first structural snapshot and the second structural snapshot are compared, and the structural change script is generated based on the structural snapshot differences.
4. The method according to any one of claims 1-3, characterized in that, Obtaining the target entity information includes: Retrieve entity metadata of the stored object entity from the target database, and receive entity metadata of the object entity to be updated generated from the low-code platform; The target entity information is generated based on the entity metadata of the stored object entity and the entity metadata of the object entity to be updated.
5. The method according to claim 4, characterized in that, The step of generating the target entity information based on the entity metadata of the stored object entity and the entity metadata of the object entity to be updated includes: When the object entity to be updated includes a first object entity, the stored object entity includes a second object entity, and the first object entity and the second object entity are the same object entity, the entity metadata of the second object entity is updated according to the entity metadata of the first object entity, and the target entity information is generated according to the updated entity metadata.
6. The method according to any one of claims 1-5, characterized in that, The entity information includes at least one of the following: table information, field information, index information, constraint information, or sequence information.
7. The method according to any one of claims 1-6, characterized in that, After the method calls the structure change script to update the target database, the method further includes: Store the structural differences and / or the structural change execution information corresponding to the structural change script; the structural change execution information includes at least one of the following: the database structural change identifier of the target database, the database structural change execution time of the target database, the database structural change execution status of the target database, or the database structural change execution result of the target database.
8. The method according to claim 7, characterized in that, In the event that the database structure change of the target database fails, the method further includes: Roll back the database structure of the target database to the same database structure as the first database structure.
9. The method according to any one of claims 1-8, characterized in that, Before generating the structure change script based on the structural differences between the first database structure and the second database structure, the method further includes: Filter preset entity information from the first database structure and / or the second database structure; the preset entity information includes at least one of the following: temporary entity information, backup entity information, version entity information, and historical log entity information.
10. A computing device, characterized in that, The computing device includes a processor and a memory; the processor is coupled to the memory. The memory is used to store computer instructions; The computer instructions are loaded and executed by the processor to enable the computing device to perform the method as described in any one of claims 1-9.