Method for realizing automatic updating of self-defined database table structure in version iteration upgrading
Through the comparison and generation of migration scripts based on base class table models, the automated update of database table structure is realized, and the cumbersome and inefficient problems of traditional database systems in data table structure changes and version iteration upgrades are solved, and the containerized environment and continuous Integration ensures data consistency and security.
Patent Information
- Application Number
- CN202411448657.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2024-11-15
- Estimated Expiration
- Not applicable · inactive patent
Smart Images

Figure CN118964362A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to database and data distribution storage technology, and in particular to a method for realizing automatic update of a custom database table structure in version iteration upgrade. Background Art
[0002] With the continuous changes in enterprise business needs and the rapid development of technology, database systems are facing unprecedented challenges. Traditional centralized database systems are unable to cope with scenarios such as distributed data storage and frequent changes in business needs. Therefore, database systems with cloud capabilities and the ability to support smooth upgrades have become an urgent need for modern enterprises.
[0003] Database migration to the cloud means that database services can expand and reduce resources more flexibly and adjust dynamically according to business needs. At the same time, the cloud computing environment provides features such as high availability, high reliability, and elastic scalability, enabling database systems to better respond to market challenges. Distributed storage further breaks the limitations of centralized data storage, allowing data to be distributed on different physical nodes according to actual needs, improving data access efficiency and system scalability.
[0004] During the software life cycle, enterprises will continue to develop new capabilities to meet market challenges, and will also fix some errors in previous versions to improve system stability and reliability. This requires the database system to support upgrade capabilities so that it can smoothly transition to the new version without affecting existing business.
[0005] The main challenges of database upgrades include: (1) Changes in data table structure: New business requirements may lead to complex changes in the data table structure, such as adding fields, modifying field types, deleting fields, etc.
[0006] (2) Table type change: It may be necessary to convert an existing table to a new table type to support new features or optimize performance.
[0007] (3) Updates to stored procedures and basic data: Stored procedures may need to be modified based on new business logic, and basic data may also need to be updated to meet new business requirements.
[0008] (4) Version compatibility: The upgrade package needs to be able to automatically identify the database table structures of different old versions and automatically complete complex changes to the new database table structure.
[0009] An automated database updating method, comprising: Step S1, storing the update data in a preset standard source database according to preset update requirement information, and obtaining configuration information of the required update, wherein the configuration information includes data table structure information, table type information, storage process information and basic data table information, and the update data includes data table structure data, table type data, storage process data and basic data table data; Step S2, reading the configuration information, and generating an update instruction containing the data table structure information, the table type information, the storage process information and the basic data table information according to the configuration information; Step S3, monitoring the update instruction, and creating a thread according to the update instruction; Step S4: According to the update instruction and the preset standard source database, the target database is updated using the thread.
[0010] The disadvantages of this database update method are: 1) Upgrade method restrictions: The current system only supports full match upgrades and cannot perform partial upgrades on specific database tables. This means that during the upgrade process, a complete version update of the entire database is required. 2) Containerized updates are not supported: The update instructions are not yet compatible with the containerized environment, so the database cannot be updated in a containerized manner. This limits the flexibility and convenience in containerized deployment scenarios. 3) Lack of exception recovery mechanism: The system currently does not provide an effective exception handling recovery method. During the upgrade process, if an exception occurs, the database cannot be rolled back to the state before the upgrade, which may increase the risk of data loss or service interruption.
[0011] Another automated database upgrade method includes: step S1: first, the version before the upgrade (taking version A as an example) is used to perform installation and deployment in a specified environment. Then, with the help of the auxiliary function of the third-party plug-in, a configuration file named mysql_old.ini is generated according to the characteristics of the MySQL database. This file contains key elements such as the structure information of the data table, the table type information, the stored procedure information and the basic data table information in detail. Step S2: Then, the upgraded version (taking version B as an example) is used to perform the same installation and deployment process. The third-party plug-in is used again to generate another configuration file named mysql_new.ini based on the current state of the MySQL database. This file also comprehensively covers various aspects of information such as the data table structure, table type, stored procedure and basic data table. Step S3: In the next stage, the configuration information in the two ini files needs to be carefully compared. This includes a detailed analysis of the differences in key aspects such as the data table structure, table type, and stored procedure. Based on these analysis results, a MySQL database upgrade script from version A to version B will be generated. Step S4: Finally, the generated upgrade script is packaged into the upgrade package and embedded into the process of the upgrade framework. In this way, during the upgrade process from version A to version B, the database table will be able to be automatically updated, thereby ensuring the smooth progress of the upgrade process. The disadvantages of this database upgrade method are: 1) Before performing the upgrade operation, the corresponding environment must be set up in advance. Since the current process does not support the direct generation of upgrade scripts through CI (continuous integration) tools or other automated methods, this step needs to be completed manually or rely on specific preset conditions. 2) The generated upgrade script is only designed for the specific upgrade scenario from version A to version B and does not have wide versatility. This means that for upgrade requirements between other versions, the script may not be directly applicable and requires additional customization or development.
[0012] It should be noted that the information disclosed in the above background technology section is only used for understanding the background of the present application, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the invention
[0013] The main purpose of the present invention is to solve the problems existing in the above-mentioned background technology and provide a method for realizing automatic update of custom database table structure in version iteration upgrade.
[0014] To achieve the above object, the present invention adopts the following technical solutions: A method for automatically updating a custom database table structure in version iteration upgrades includes the following steps: Step 1. Define a table model based on the base class and build a relationship mapping between the table model and the database table structure; Step 2. Connect and obtain the table structure information of the current database, and convert it into a mapping structure based on the base class; Step 3. Selectively import the new version of the database table model according to the custom requirements, and convert its structural information into a mapping structure based on the base class; Step 4. Identify the differences between the mapping structures generated in step 2 and step 3 by comparing them. Step 5. Generate a migration script for updating the database table structure based on the identified differences; Step 6: Execute the migration script to update the current database table structure to the new version of the database table structure.
[0015] Further: The method further comprises: Before executing the database table structure update in step 6, back up the current database table structure and the data contained therein; if the upgrade fails in step 6, the rollback mechanism is triggered, and the database table structure and data are restored to the state before the upgrade using the backup file. After the database rollback is completed, the database data is verified to confirm that the rollback operation is successful.
[0016] The metadata information of the table model includes the attributes, relationships, types and names of the table.
[0017] According to the definition of the table model based on the base class, all table models inherit from the base class; when the table model is imported in step 3, the metadata information of the table model is saved in the table structure information file, and the new version of the database table structure information is obtained through the table structure information file.
[0018] In step 4, the database table structures of the new and old versions are traversed, the differences between the two are compared in detail, and a list containing all the differences is generated based on the comparison results, providing a basis for generating the migration script.
[0019] In step 5, each element in the difference list is traversed to assemble corresponding database operation commands, and the assembled database operation commands are serially connected in sequence to form a complete database table upgrade script as the migration script.
[0020] In step 6, before executing the migration script, the current system environment is first identified, and a corresponding execution mode is selected according to the identified system environment to execute the migration script.
[0021] The system environment includes a host mode and a containerized mode. In the host mode, it can be executed directly on the database server. In the containerized mode, the database update is automatically completed in the corresponding database container environment.
[0022] The migration script includes instructions for adding, deleting or modifying the database table structure.
[0023] A computer program product includes a computer program, wherein when the computer program is executed by a processor, the method for automatically updating a custom database table structure in version iteration upgrade is implemented.
[0024] The present invention has the following beneficial effects: In view of the problems of cumbersomeness, inefficiency and error-proneness in the current database update process, the present invention proposes an automated database update method, which can greatly simplify the database table structure update process, improve the update efficiency, and reduce the risk of human error. The significant advantages of the present invention also include: Achieve seamless integration with the software upgrade lifecycle: In order to ensure that database updates and software upgrades are carried out synchronously, the system designed by the present invention can be seamlessly integrated into the software upgrade lifecycle. This allows the database upgrade to be automatically carried out with the iteration of the software version without manual intervention, thereby ensuring the consistency of the database and software versions.
[0025] Support smooth upgrades in containerized environments: With the popularity of containerization technology, this invention specifically considers the upgrade requirements of databases in containerized scenarios. The system can identify and adapt to containerized environments, ensuring that databases can be upgraded smoothly and reliably in such environments.
[0026] Provide flexible designated database table upgrade function: In order to avoid unnecessary overhead caused by full update, the present invention allows users to flexibly select and upgrade specific database tables according to actual needs at different stages of the software upgrade life cycle. This function makes database updates more accurate and efficient.
[0027] Failure rollback and data consistency guarantee: In the process of database upgrade, it is inevitable to encounter various problems or exceptions. In order to ensure the security and consistency of data, the system designed by the present invention is equipped with a powerful failure rollback mechanism. When the upgrade fails, the system can quickly restore the database to the state before the upgrade, thereby avoiding data loss or damage.
[0028] In general, the embodiments of the present invention achieve seamless updates of database table structures during software upgrades through multiple innovative means such as automated integration, customized upgrade strategies, environmental adaptability and containerization support, and data security mechanisms. It not only improves upgrade efficiency and reduces potential risks, but also fully guarantees data security, providing users with an efficient, reliable, and secure software upgrade solution.
[0029] Other beneficial effects of the embodiments of the present invention will be further described below. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 The present invention is a flow chart of a method for realizing automatic update of a custom database table structure in version iteration upgrade.
[0031] Figure 2 A process flow chart of constructing a relationship mapping between a table model and a table structure in an embodiment of the present invention.
[0032] Figure 3 A flowchart of a process for obtaining the new and old versions of database table structures according to an embodiment of the present invention.
[0033] Figure 4 A processing flow chart of generating a database table structure migration script according to an embodiment of the present invention.
[0034] Figure 5 A flowchart of a process for rolling back a database table structure according to an embodiment of the present invention. DETAILED DESCRIPTION
[0035] The following is a detailed description of the embodiments of the present invention. It should be emphasized that the following description is only exemplary and is not intended to limit the scope and application of the present invention.
[0036] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0037] See also Figure 1 The embodiment of the present invention provides a method for automatically updating a custom database table structure in version iteration upgrade, comprising the following steps: Step 1. Define a table model based on the base class and build a relationship mapping between the table model and the database table structure; Step 2. Connect and obtain the table structure information of the current database, and convert it into a mapping structure based on the base class; Step 3. Selectively import the new version of the database table model according to the custom requirements, and convert its structural information into a mapping structure based on the base class; Step 4. Identify the differences between the mapping structures generated in step 2 and step 3 by comparing them. Step 5. Generate a migration script for updating the database table structure based on the identified differences; Step 6: Execute the migration script to update the current database table structure to the new version of the database table structure.
[0038] In some embodiments, in a method for implementing automatic update of a custom database table structure in a version iteration upgrade, first, by connecting to the database software, the database table structure before the upgrade is obtained. These table structures are converted into structures based on base class mapping for subsequent operations. Then, the database tables that need to be upgraded are customized. These tables can be full database tables or specified single or multiple database tables. According to the base class, the mapping structures of these tables are mapped to prepare for subsequent comparisons. Next, the mapping structures generated by the above two steps are compared. The table structure and the column structure in the table are traversed to find out the differences and generate a difference list. This difference list will serve as the basis for the subsequent generation of the upgrade script. Finally, the difference list generated by the above steps is assembled into a database table structure upgrade script in sequence, and this script is executed to complete the automatic upgrade of the database table structure and data.
[0039] The method of the present invention aims to solve the problem of automatic updating of database table structure when the software transitions from version A (i.e., the version before upgrading) to version B (i.e., the version after upgrading). The core of the method is that, without manual intervention, the system can autonomously connect to the version A database, obtain its table structure, and obtain the database table structure of version B according to the table model defined in version B during the software upgrading process. By comparing the differences between the two, the system automatically generates and executes the migration script to ensure that after the software upgrade, its version and the database table structure remain synchronized.
[0040] The present invention integrates the automatic update process of the database table structure into the software upgrade life cycle. By connecting to the software database and parsing the table model, the system can accurately obtain the database table structure of version A and version B. Subsequently, the system autonomously generates and executes the migration script to achieve smooth iteration of the database table structure and ensure the consistency of the software version and the database table structure.
[0041] The method of the present invention can greatly simplify the database table structure update process, improve update efficiency, and reduce the risk of human error.
[0042] The present invention allows specifying the database table range that needs to be updated during the different stages of software upgrades according to the specific needs of the business. This flexible customization strategy meets the diverse needs of users, enables the system to accurately update the database table structure specified by the business, avoids unnecessary full updates, improves upgrade efficiency, and reduces potential risks.
[0043] In some embodiments, the present invention provides two operating modes, host mode and containerized mode, to adapt to different operating environments. If it is a containerized mode, it is necessary to use container tools to automatically update and roll back the database table structure in the container. When the operating environment is identified as a containerized environment, the corresponding containerized mode is selected to automatically update and roll back the database table structure to ensure stable and reliable upgrades in a containerized environment. During the software upgrade process, it is identified whether the database is based on a containerized deployment or is directly deployed to the host machine. According to different deployment forms, the corresponding database upgrade script is automatically switched to execute, which can ensure that the database table cannot be upgraded due to differences in deployment forms.
[0044] In some embodiments, the present invention also provides a data security mechanism. Before updating the database table structure, the system fully backs up the current database table structure and data. Once the upgrade fails, the system can quickly use the backed-up database data to safely reconstruct the database and restore it to the state before the upgrade, thereby effectively avoiding the risk of data loss or damage. Before the database is upgraded, a full backup of the database table structure and data can prevent unexpected situations during the upgrade process, resulting in data loss or damage. If the database fails to upgrade due to a malfunction during the upgrade process, the database table structure and data are restored to the state before the upgrade through the database backup file before the upgrade, thereby ensuring that the integrity and accuracy of the data are not affected.
[0045] The embodiment of the present invention realizes seamless update of database table structure during software upgrade process through multiple innovative means such as automated integration, customized upgrade strategy, environmental adaptability and containerization support, and data security mechanism. It not only improves upgrade efficiency and reduces potential risks, but also fully guarantees data security, providing users with an efficient, reliable and secure software upgrade solution.
[0046] The processing flow of a specific embodiment of the present invention is further described below.
[0047] See also Figures 1 to 5 , a method for automatically updating a custom database table structure in version iteration upgrades. The processing flow specifically includes the following core steps: Step 1. Build the mapping relationship between the table model and the database table structure:
[0048] The first step is to define the table model, which includes key information such as table attributes, relationships, types, and names. There is a direct mapping relationship between the table model and the table in the database. Direct operations on the database can be achieved by operating the table model. All table models inherit from the base class (Base class). When importing a table model, its metadata information (such as attributes, relationships, table name, type, etc.) is saved in Base.metadata to facilitate subsequent acquisition of table structure information.
[0049] Step 2. Connect and obtain the current database table structure:
[0050] The system connects to the current version of the database and obtains its table structure information for comparison with the new version. At the same time, the system identifies the operating environment, selects the host mode or container mode, and backs up the current database data to ensure data security.
[0051] Step 3. Import the table model and obtain the new version database table structure:
[0052] Based on user needs, the system chooses to import some or all table models. After importing, the current version of the database table structure and the new version of the database table model will exist in the environment at the same time. Through Base.metadata, the system can obtain the metadata information of the table model and then obtain the new version of the database table structure.
[0053] Step 4. Generate a list of database table structure differences:
[0054] The system traverses the database table structure of the old and new versions and compares the differences in detail. Based on the comparison results, the system generates a list of all differences to provide a basis for the subsequent generation of migration scripts.
[0055] Step 5. Generate and execute the database table structure migration script:
[0056] Based on the database table structure difference list, the system automatically generates the corresponding database upgrade script. Then, the system identifies the operating environment, selects the host mode or container mode to execute the upgrade script, and realizes the automatic update of the database table structure.
[0057] Step 6. Process the software upgrade results:
[0058] If the software upgrade is successful, the automatic update of the database table structure will also be completed smoothly. If the software upgrade fails, the system will start the rollback process. Based on the previously backed up database data, the system can quickly reconstruct the current environment database and restore it to the state before the upgrade to ensure data integrity and security.
[0059] For step 1, Figure 2 The process flow of constructing a relationship mapping between a table model and a table structure in one embodiment is shown.
[0060] Building a relational mapping between table models and table structures is the bridge between the database and the code. In SQLAlchemy, this process is implemented by declaring a base class, which is the core of defining an object-relational mapping (ORM) model.
[0061] The specific steps are as follows: Step 1.1. Create a declarative base class through Base = declarative_base(). The declarative base class is the core of SQLAlchemy for defining ORM (object-relational mapping) models. All table model definitions inherit the base class Base, thereby building a relationship mapping between the table model in the code and the table in the database. Define attributes, relationships, table names, etc. in the table model, and these attributes, relationships, and table names are directly mapped to database tables and columns.
[0062] Step 1.2. After building the relationship mapping between the table model and the table structure, you can use the table model to perform operations such as adding, deleting, modifying, and querying the database. During the process of importing the table model, the metadata information of the table model (table name, attributes, and relationships) is saved in the Base.metadata object, and all database table structures can be obtained through the Base.metadata object.
[0063] Through this mapping process, the database can be operated and managed intuitively in the code, improving development efficiency and code maintainability. At the same time, using the ORM function of SQLAlchemy, complex database relationships and data operations can be handled more easily.
[0064] For step 2, Figure 3 The flowchart of obtaining the new and old version database table structures in one embodiment is shown.
[0065] Get the old and new version database table structure: All table model definitions inherit the base class Base. During the software upgrade process, after the new version of the table model is imported, the metadata information of the table model is saved in Base.metadata. The database table structure is obtained through Base.metadata. The old version of the database table structure is directly obtained through the database of the connected environment. The processing steps for obtaining the new and old version of the database table structure are as follows: Step 2.1. Based on the fact that all table model definitions inherit the base class Base, during the software upgrade process, decompress the rpm about the table model in the new version of the software to obtain all the table models of the new version.
[0066] Step 2.2. According to user needs, choose to import part of the table model or all the table models. After importing, the metadata information of the table model (table name, attributes, relationships, etc.) is saved in the Base.metadata object.
[0067] Step 2.3. Get the new version of the database table structure through the Base.metadata object.
[0068] For step 3, the old version database table structure acquisition process: To obtain the old version of the database table structure, establish a stable connection with the current environment database. After successfully connecting to the database, use SQL query or database management tools to extract the old version of the database table structure information.
[0069] For step 4, Figure 4 The process flow of generating a database table structure migration script in one embodiment is shown.
[0070] When the software system is iteratively upgraded, in order to ensure a smooth transition of the database table structure, a database table structure upgrade script is generated and executed. The processing steps are as follows: Step 4.1. Get the database table structure: Through the database connection, obtain the database table structure of the old version and save it as structure_A.
[0071] Get the new version of the database table structure through the Base.metadata object and save it as structure_B.
[0072] Both structure_A and structure_B are saved in dictionary form, with the key being the table name and the value being the table structure information, including table relationships, column attributes, etc.
[0073] Step 4.2. Generate a list of database table structure differences: 1) Start traversing the table structure: Traverse structure_A and structure_B to obtain and store all table names and their corresponding column attribute information in the two versions.
[0074] 2) Identify differences in table structure: For a table that exists in structure_B but not in structure_A, such as table_1, it means that table_1 is added in the new version, so the element (create_table, table_1) is added to the difference list; For a table that exists in structure_A but not in structure_B, such as table_2, it means that table_2 is deleted in the new version, so add the element (drop_table, table_2) to the difference list; 3) Compare the differences in column structure within the table: For a table that exists in both structure_B and structure_A, such as table_3, traverse B_table_3_value in structure_B and A_table_3_value in structure_A. For example, some differences at the level of the database table are compared as follows: For a table that exists in B_table_3_value but not in A_table_3_value, such as table column_1, it indicates that a new column column_1 is added to table table_3 in the new version, so add an element (add_column, table_3, column_1) to the difference list; For a table that exists in A_table_3_value but not in B_table_3_value, such as table column_2, it indicates that column column_2 is deleted from table table_3 in the new version, so add the element (drop_column, table_3, column_2) to the difference list; For the same column column_3 of B_table_3_value and A_table_3_value, it is not nullable=false in the old version and nullable=true in the new version, so add the element (alter_column, table_3, column_3, nullable=true) to the difference list. 4) Record and generate a list of differences: After traversing all database table structures, the comparison results are recorded in a difference list according to a predetermined format. This difference list includes detailed information such as newly added tables, deleted tables, newly added columns, deleted columns, and columns with changed attributes.
[0075] For step 5, in one embodiment, the process of assembling and executing the migration script specifically includes: First, through the previous comparison process, a difference list containing the database table structures of the new and old versions has been obtained.
[0076] Next, traverse each element in the difference list and assemble it into the corresponding database operation command. The assembled database operation commands are connected in sequence to form a complete database table upgrade script. This script will contain all the necessary code languages to update the database table structure of the old version to the new version.
[0077] Finally, before executing the upgrade script, identify the current system environment, such as host mode or containerized mode. According to the identified system environment, select the appropriate execution mode to run the migration script. For example, in host mode, it can be executed directly on the database server; in containerized mode, the database update is automatically completed in the corresponding database container environment.
[0078] For step 6, Figure 5 The flowchart of rolling back the database table structure in one embodiment is shown.
[0079] During the software upgrade process, if the upgrade fails, in order to ensure the consistency between the software version and the database table structure it depends on, the database is rolled back. The processing steps are as follows: Step 6.1. Before starting the software upgrade, the first task is to fully back up the current database table structure and the data contained in it. This step is to ensure that when the upgrade fails, you can have a complete and accurate database backup so that you can perform a rollback operation.
[0080] Step 6.2. When the software upgrade fails, the system should automatically trigger the rollback mechanism and prepare to restore the database to the state before the upgrade.
[0081] Step 6.3. Before performing the rollback operation, the system checks whether the previously created database backup file exists and is intact.
[0082] Step 6.4. Automatically identify whether to use host mode or containerized mode based on the current system operating environment. Use the verified database backup file and select the corresponding rollback tool or method based on the identified system environment. Reconstruct the database table structure and data according to the established rollback process to ensure that the database can be quickly and safely restored to the state before the upgrade.
[0083] Step 6.5. After the database rollback is completed, verify the database data. Confirm the success and accuracy of the rollback operation by comparing the database table structure and data before and after the rollback. Ensure that the software can seamlessly connect with the restored database and operate normally.
[0084] In summary, compared with the traditional method, the automatic updating method of the database table structure of the present invention has the following significant advantages: 1) Achieve efficient and automated version upgrades: Through the upgrade framework, the present invention supports automatic upgrades of software from previous versions to the latest version. In this process, not only the software itself is updated, but also the database table structure is automatically upgraded, thereby ensuring the consistency of the software and database versions. This automated upgrade method greatly improves the upgrade efficiency and reduces the cost and risk of manual intervention.
[0085] 2) Flexible database table upgrade strategy: The present invention allows flexible selection and upgrade of specified database tables according to actual needs at different stages of the software upgrade life cycle. This strategy makes database upgrades more accurate and efficient, avoids unnecessary full updates, and thus saves resources and time. Ultimately, all database tables can be smoothly upgraded to the latest structure, ensuring data integrity and consistency.
[0086] 3) Comprehensive data consistency and business availability guarantee: During the upgrade process, the present invention provides a powerful failure rollback mechanism. Once the upgrade fails, the system can quickly restore the database to the state before the upgrade, thereby protecting the customer's data consistency and business function availability. This feature greatly improves the reliability and security of the upgrade and reduces the risk of business interruption and data loss that may be caused during the upgrade process.
[0087] 4) Wide range of deployment support: The present invention not only supports database upgrades in software form deployed on the host machine, but also supports automatic upgrades and failure rollbacks in containerized form. This wide range of deployment support enables the present invention to adapt to different application scenarios and requirements, providing customers with a more flexible and reliable database upgrade solution.
[0088] The present invention brings significant benefits and advantages by achieving efficient and automated version upgrades, flexible database table upgrade strategies, comprehensive data consistency and business availability guarantees, and support for a wide range of deployment forms.
[0089] An embodiment of the present invention further provides a storage medium for storing a computer program, which at least performs the above method when executed.
[0090] An embodiment of the present invention further provides a control device, comprising a processor and a storage medium for storing a computer program; wherein the processor is configured to execute at least the method described above when executing the computer program.
[0091] An embodiment of the present invention further provides a processor, wherein the processor executes a computer program and at least executes the method described above.
[0092] The storage medium can be implemented by any type of non-volatile storage device, or a combination thereof. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a ferromagnetic random access memory (Flash Memory), a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The storage medium described in the embodiments of the present invention is intended to include, but is not limited to, these and any other suitable types of memory.
[0093] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0094] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0095] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0096] A person skilled in the art can understand that: all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, etc. Various media that can store program codes.
[0097] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0098] The methods disclosed in the several method embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method embodiments.
[0099] The features disclosed in several product embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new product embodiments.
[0100] The features disclosed in several method or device embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0101] The above contents are further detailed descriptions of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art of the present invention, several equivalent substitutions or obvious variations can be made without departing from the concept of the present invention, and the performance or use is the same, which should be regarded as belonging to the protection scope of the present invention.
Claims
1. A method for realizing automatic update of a custom database table structure in version iteration upgrade, characterized in that: The following steps are involved: Step 1. Define a table model based on the base class and build a relationship mapping between the table model and the database table structure; Step 2. Connect and obtain the table structure information of the current database, and convert it into a mapping structure based on the base class; Step 3. Selectively import the new version of the database table model according to the custom requirements, and convert its structural information into a mapping structure based on the base class; Step 4. Identify the differences between the mapping structures generated in step 2 and step 3 by comparing them. Step 5. Generate a migration script for updating the database table structure based on the identified differences; Step 6: Execute the migration script to update the current database table structure to the new version of the database table structure.
2. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1, characterized in that: Also includes: Before executing the database table structure update in step 6, back up the current database table structure and the data contained therein; If the upgrade fails in step 6, the rollback mechanism is triggered, and the database table structure and data are restored to the state before the upgrade using the backup file. After the database rollback is completed, the database data is verified to confirm that the rollback operation is successful.
3. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1 or 2, characterized in that: The metadata information of the table model includes the attributes, relationships, types and names of the table.
4. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1 or 2, characterized in that: According to the definition of the table model based on the base class, all table models inherit from the base class; when the table model is imported in step 3, the metadata information of the table model is saved in the table structure information file, and the new version of the database table structure information is obtained through the table structure information file.
5. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1 or 2, characterized in that: In step 4, the database table structures of the new and old versions are traversed, the differences between the two are compared in detail, and a list containing all the differences is generated based on the comparison results, providing a basis for generating the migration script.
6. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 5, characterized in that: In step 5, each element in the difference list is traversed to assemble corresponding database operation commands, and the assembled database operation commands are serially connected in sequence to form a complete database table upgrade script as the migration script.
7. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1 or 2, characterized in that: In step 6, before executing the migration script, the current system environment is first identified, and a corresponding execution mode is selected according to the identified system environment to execute the migration script.
8. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1 or 2, characterized in that: The system environment includes a host mode and a containerized mode. In the host mode, it can be executed directly on the database server. In the containerized mode, the database update is automatically completed in the corresponding database container environment.
9. The method for realizing automatic update of a custom database table structure in version iteration upgrade according to claim 1 or 2, characterized in that: The migration script includes instructions for adding, deleting or modifying the database table structure.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for realizing automatic update of a custom database table structure in version iteration upgrade as described in any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
Database updating system and method, corresponding computer equipment and storage medium
CN115470191A
Cited By
Automatic generation method and device for database change script and medium
CN120596458A
