Database structure synchronization method and device, medium and equipment

By regularly generating database synchronization instructions and comparing the databases, data tables, and data fields of the production and test environments layer by layer, the problem of missing data in database structure synchronization is solved, and the stability and synchronization of the test environment are achieved.

CN120763244APending Publication Date: 2025-10-10SHANGHAI JIEYIN E-COMMERCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510840339.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

Existing database structure synchronization methods suffer from data loss problems due to the lack of standardized processes. Especially in financial management and digital medical applications, repeated operations or policy conflicts are prone to occur when synchronizing the database structures of the test environment and the production environment, leading to data loss.

Method used

By regularly generating database structure synchronization instructions, the databases, data tables, and data fields of the production and test environments are compared layer by layer, and corresponding modifications and configurations are made based on the comparison results to ensure that the test environment is fully synchronized with the production environment.

Benefits of technology

It achieves complete synchronization between the test environment and the production environment, avoids data loss, enhances the stability of the test environment, and reduces the workload of operation and maintenance personnel.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120763244A_ABST
    Figure CN120763244A_ABST
Patent Text Reader

Abstract

The invention discloses a database structure synchronization method and device, a medium and equipment, and relates to the technical field of digital medical and financial management, the method comprises the following steps: comparing a database name of a first database in a production environment with a database name of a second database in a test environment, and modifying the database in the test environment according to a comparison result; comparing the table name of the first data table in the first database with the table name of the second data table in the second database, which have the same database name, and modifying the data table in the second database according to a comparison result; and taking the first data table and the second data table with the same table name as a group of data tables, comparing data stored in the first data table with data stored in the second data table for each group of data tables, and modifying the data stored in the second data table according to a comparison result. According to the method, the database structure of the test environment does not need to be synchronized manually, data missing is avoided, and the stability of the test environment is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of digital medical treatment and financial management, and particularly relates to a database structure synchronization method and device, medium and equipment. BACKGROUND

[0002] The production environment and the test environment of an application program are two very important deployment environments in the software development life cycle. The application program is usually put into use after being tested and verified in the test environment, and the production environment is where the application program is finally run and directly faces real users or customers. If a major exception is found in the application program, the developer usually modifies the code in the test environment, and then puts it into use again after the modification is successful. With the continuous expansion and enrichment of business requirements in the application program, the technology research and development are also iteratively updated, and the structure of the database in the production environment also changes and adjusts. These changes need to be consistent in the test environment to ensure the stability of the test process and the verifiability of the results. Especially, the database structure of the production environment corresponding to the application program in the field of financial management or digital medical treatment changes every day, and the database structure of the test environment needs to be synchronized.

[0003] At present, the synchronization method of the database structure in the test environment is manually synchronized by the operation and maintenance personnel. Usually, the database and the data table are managed by different operation and maintenance personnel, and different operation and maintenance personnel are responsible for different modules. Due to the lack of standardized process, there may be repeated operation or strategy conflict due to untimely communication, thereby causing the problem of data loss during synchronization of the database structure. SUMMARY

[0004] Therefore, the application provides a database structure synchronization method, device, medium and equipment, which mainly aims to solve the problem of data loss in the existing database structure synchronization method.

[0005] According to one aspect of the application, a database structure synchronization method is provided, which comprises:

[0006] According to the synchronization requirement of the database structure, a database structure synchronization instruction is generated in a timely manner;

[0007] Based on the database structure synchronization instruction, the library name of a plurality of first databases located in the production environment and the library name of a plurality of second databases located in the test environment are obtained, the library name of the first database and the library name of the second database are compared to obtain a first comparison result, and the database of the test environment is modified according to the first comparison result;

[0008] A first database and a second database with the same database name are grouped as a group of databases. For each group of databases, the table names of multiple first data tables contained in the first database are compared with the table names of multiple second data tables contained in the second database to obtain a second comparison result. Based on the second comparison result, the data tables in the second database are modified.

[0009] A first data table and a second data table with the same table name are regarded as a group of data tables. For each group of data tables, data stored in the first data table and data stored in the second data table are compared to obtain a third comparison result. Based on the third comparison result, the data stored in the second data table is modified.

[0010] Optionally, modifying the database of the test environment according to the first comparison result includes:

[0011] Determine, based on the first comparison result, which databases the test environment lacks and which databases are extra compared to the production environment, and delete the extra databases from the test environment;

[0012] Obtaining the type and library name of the missing database, building a new second database in the test environment based on the type and library name of the missing database, and configuring the new second database;

[0013] The third data table and the data stored in the third data table included in the missing database are obtained, and the third data table and the data stored in the third data table are added to the new second database.

[0014] Optionally, modifying the data table in the second database according to the second comparison result includes:

[0015] Determining, based on the second comparison result, data tables that are missing and data tables that are extra in the second database compared to the first database, and deleting the extra data tables from the second database;

[0016] Obtaining the table name of the missing data table, and constructing a new second data table in the second database based on the table name of the missing data table;

[0017] The data stored in the missing data table is obtained, and the data stored in the missing data table is added to the newly created second data table.

[0018] Optionally, for each group of fields, the type of the first field and the type of the second field are compared to obtain a type comparison result, and the index of the first field and the index of the second field are compared to obtain an index comparison result.

[0019] Optionally, after determining the first field and the second field with identical content and the missing fields and the extra fields in the second data table, modifying the data stored in the second data table according to the third comparison result includes:

[0020] Get the content, type, length and index of the missing field.

[0021] Add the content, type, length and index corresponding to the missing field in the second data table;

[0022] The content, type, length and index corresponding to the extra fields are deleted from the second data table.

[0023] Optionally, for each group of fields, comparing the length of the first field with the length of the second field to obtain a length comparison result, and then modifying the data stored in the second data table according to the third comparison result includes:

[0024] According to the length comparison results, multiple groups of fields with the same content but different lengths are determined;

[0025] For each group of fields with the same content but different lengths, the length corresponding to the first field is obtained, and the length corresponding to the second field in the second data table is modified according to the length corresponding to the first field.

[0026] Optionally, for each group of fields, comparing the type of the first field with the type of the second field to obtain a type comparison result, comparing the index of the first field with the index of the second field to obtain an index comparison result, and then modifying the data stored in the second data table according to the third comparison result includes:

[0027] Based on the type comparison results, multiple groups of fields with the same content but different types are determined;

[0028] For each group of fields with the same content but different types, obtain the type corresponding to the first field, and modify the type corresponding to the second field in the second data table according to the type corresponding to the first field;

[0029] Based on the index comparison results, multiple groups of fields with the same content but different indexes are determined;

[0030] For each group of fields with the same content but different indexes, the index corresponding to the first field is obtained, and the index corresponding to the second field in the second data table is modified according to the index corresponding to the first field.

[0031] According to another aspect of the present application, a database structure synchronization device is provided, comprising:

[0032] a synchronization instruction generation module, configured to generate a database structure synchronization instruction according to a synchronization requirement of the database structure;

[0033] a database modification module, configured to obtain library names of a plurality of first databases located in a production environment and library names of a plurality of second databases located in a test environment based on the database structure synchronization instruction, compare the library names of the first databases and the library names of the second databases to obtain a first comparison result, and modify the databases in the test environment according to the first comparison result;

[0034] a data table modification module, configured to take the first databases and the second databases with the same library names as a group of databases, compare table names of a plurality of first data tables contained in the first databases and table names of a plurality of second data tables contained in the second databases for each group of databases to obtain a second comparison result, and modify the data tables in the second databases according to the second comparison result;

[0035] a field modification module, configured to take the first data tables and the second data tables with the same table names as a group of data tables, compare data stored in the first data tables and data stored in the second data tables for each group of data tables to obtain a third comparison result, and modify the data stored in the second data tables according to the third comparison result.

[0036] Optionally, the database modification module is further configured to:

[0037] determine, according to the first comparison result, databases that are absent in the test environment and databases that are in excess in the test environment compared with the production environment, and delete the databases in excess from the test environment;

[0038] obtain a type and a library name of the absent databases, construct a new second database in the test environment based on the type and the library name of the absent databases, and configure the new second database;

[0039] obtain third data tables contained in the absent databases and data stored in the third data tables, and add the third data tables and the data stored in the third data tables to the new second database.

[0040] Optionally, the data table modification module is further configured to:

[0041] determine, according to the second comparison result, data tables that are absent in the second databases and data tables that are in excess in the second databases compared with the first databases, and delete the data tables in excess from the second databases;

[0042] Obtaining the table name of the missing data table, and constructing a new second data table in the second database based on the table name of the missing data table;

[0043] The data stored in the missing data table is obtained, and the data stored in the missing data table is added to the newly created second data table.

[0044] Optionally, the data stored in the data table includes the content, type, length and index of the field, and the third comparison result includes the content comparison result, the type comparison result, the length comparison result and the index comparison result; the field modification module is further used to:

[0045] Comparing the content of the first field stored in the first data table with the content of the second field stored in the second data table to obtain a content comparison result;

[0046] Determining, based on the content comparison result, a first field and a second field with identical content, as well as missing fields and extra fields in the second data table;

[0047] A first field and a second field with the same content are taken as a group of fields, and for each group of fields, the length of the first field is compared with the length of the second field to obtain a length comparison result;

[0048] For each group of fields, the type of the first field and the type of the second field are compared to obtain a type comparison result, and the index of the first field and the index of the second field are compared to obtain an index comparison result.

[0049] Optionally, the field modification module is further configured to:

[0050] Get the content, type, length and index of the missing field.

[0051] Add the content, type, length and index corresponding to the missing field in the second data table;

[0052] The content, type, length and index corresponding to the extra fields are deleted from the second data table.

[0053] Optionally, the field modification module is further configured to:

[0054] According to the length comparison results, multiple groups of fields with the same content but different lengths are determined;

[0055] For each group of fields with the same content but different lengths, the length corresponding to the first field is obtained, and the length corresponding to the second field in the second data table is modified according to the length corresponding to the first field.

[0056] Optionally, the field modification module is further configured to:

[0057] For each group of fields, comparing the type of the first field with the type of the second field to obtain a type comparison result, comparing the index of the first field with the index of the second field to obtain an index comparison result, and then modifying the data stored in the second data table according to the third comparison result, including:

[0058] Based on the type comparison results, multiple groups of fields with the same content but different types are determined;

[0059] For each group of fields with the same content but different types, obtain the type corresponding to the first field, and modify the type corresponding to the second field in the second data table according to the type corresponding to the first field;

[0060] Based on the index comparison results, multiple groups of fields with the same content but different indexes are determined;

[0061] For each group of fields with the same content but different indexes, the index corresponding to the first field is obtained, and the index corresponding to the second field in the second data table is modified according to the index corresponding to the first field.

[0062] According to another aspect of the present application, a storage medium is provided, in which at least one executable instruction is stored. The executable instruction enables a processor to execute operations corresponding to the database structure synchronization method as described above.

[0063] According to another aspect of the present application, a computer device is provided, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus;

[0064] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute operations corresponding to the database structure synchronization method as described above.

[0065] By means of the above technical solution, the present application provides a method, device, medium and equipment for synchronizing a database structure. Through periodically generated database synchronization instructions, the database, data table and data stored in the data table corresponding to the production environment are compared layer by layer with the database, data table and data stored in the data table corresponding to the test environment. According to the comparison results, the database, data table and data stored in the data table in the test environment are modified accordingly, and the differences are adjusted to make the test environment database structure completely synchronized with the production environment database structure. There is no need to manually synchronize the test environment database structure, which avoids data loss, enhances the stability of the test environment, and also reduces the workload of operation and maintenance personnel in maintaining the test environment database structure.

[0066] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0067] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:

[0068] Figure 1 A flowchart showing a method for synchronizing a database structure provided by an embodiment of the present application is shown;

[0069] Figure 2 Another flowchart of a method for synchronizing a database structure provided by an embodiment of the present application is shown;

[0070] Figure 3 Another flowchart of a method for synchronizing a database structure provided by an embodiment of the present application is shown;

[0071] Figure 4 Another flowchart of a database structure synchronization method provided by an embodiment of the present application is shown;

[0072] Figure 5 Another flowchart of a method for synchronizing a database structure provided by an embodiment of the present application is shown;

[0073] Figure 6 A block diagram of a database structure synchronization device provided by an embodiment of the present application is shown;

[0074] Figure 7 A structural diagram of a computer device provided in an embodiment of the present application is shown.

[0075] In the figure: 602 - synchronization instruction generation module; 604 - database modification module; 606 - data table modification module; 608 - field modification module; 702 - processor; 704 - communication interface; 706 - memory; 708 - communication bus; 710 - program. DETAILED DESCRIPTION

[0076] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that, in the absence of conflict, the embodiments and features of the embodiments of the present invention can be combined with each other.

[0077] To further illustrate the technical means and effects employed by the present invention to achieve its intended objectives, the following detailed description of the specific implementation methods, structures, features, and effects of the present invention is provided in conjunction with the accompanying drawings and preferred embodiments. In the following description, different references to "one embodiment" or "embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics of one or more embodiments may be combined in any suitable manner.

[0078] In view of the problem of data loss in the existing database structure synchronization method, the embodiment of the present application provides a database structure synchronization method, such as Figure 1 As shown, the method includes:

[0079] 102: Generate database structure synchronization instructions regularly according to the synchronization requirements of the database structure;

[0080] 104: Based on the database structure synchronization instruction, obtain the library names of multiple first databases in the production environment and the library names of multiple second databases in the test environment, compare the library names of the first databases with the library names of the second databases to obtain a first comparison result, and modify the database in the test environment based on the first comparison result;

[0081] 106: The first database and the second database having the same database name are grouped as a group of databases. For each group of databases, the table names of the first data tables contained in the first database are compared with the table names of the second data tables contained in the second database to obtain a second comparison result. The data tables in the second database are modified according to the second comparison result.

[0082] 108: The first data table and the second data table with the same table name are regarded as a group of data tables. For each group of data tables, data stored in the first data table and data stored in the second data table are compared to obtain a third comparison result. According to the third comparison result, the data stored in the second data table is modified.

[0083] Specifically, each application corresponds to a production environment and at least one test environment. The database structure of at least one test environment is identical to that of the production environment, ensuring that modifications and testing can be performed in the same test environment if a serious anomaly occurs in the production environment. Because data in the production environment's database is frequently updated, the test environment's database structure requires frequent synchronization. Based on changes in the production environment's database structure, database structure synchronization instructions are periodically generated, or timed database structure synchronization instructions are generated. Based on these instructions, the test environment's database is periodically synchronized.

[0084] For example, the database structure in the production environment corresponding to a certain financial management APP changes significantly, and a database structure synchronization instruction is generated every three days; the database structure in the production environment corresponding to a certain medical service APP changes slightly, and a database structure synchronization instruction is generated every week.

[0085] When synchronizing database structures, first obtain the library names of multiple first databases in the production environment and the library names of multiple second databases in the test environment, compare the library names of the multiple first databases with the library names of the multiple second databases, and obtain a first comparison result. Based on the first comparison result, process the databases that are different between the test environment and the production environment. Based on the first comparison result, obtain the first database and the second database with the same library name. The first database and the second database with the same library name are regarded as a group of databases. For each group of databases, compare the table names of all data tables in the first database with the table names of all data tables in the second database to obtain a second comparison result. Based on the second comparison result, determine the first data tables and the second data tables with the same library name in the group of databases, determine the data tables in the second database of the group that are different from the first database, and perform corresponding processing on the different data tables.

[0086] A first data table and a second data table with the same database name in a set of databases are considered a group of data tables. For each group of data tables, the data stored in the first data table and the data stored in the second data table are obtained. The stored data includes field content, field type, field length, whether the same field has an index, and the index status. The stored data is compared item by item. Based on the comparison results, the data that differs between the second data table and the first data table is processed accordingly to ensure that the database structure corresponding to the test environment is exactly the same as the database structure corresponding to the production environment.

[0087] The method of the present application is applied to service platforms, including but not limited to financial management platforms, digital medical service platforms, public service platforms, etc., and the database structure synchronization method includes but is not limited to financial management, digital medical, and public service application scenarios.

[0088] Compared with the existing technology, the database structure synchronization method provided by the present application uses periodically generated database synchronization instructions to compare the database, data tables and data stored in the data tables corresponding to the production environment with the database, data tables and data stored in the data tables corresponding to the test environment layer by layer. According to the comparison results, the database, data tables and data stored in the data tables in the test environment are modified accordingly, and the differences are adjusted to make the test environment database structure completely synchronized with the production environment database structure. There is no need to manually synchronize the test environment database structure, which avoids data loss, enhances the stability of the test environment, and also reduces the workload of operation and maintenance personnel in maintaining the test environment database structure.

[0089] In another embodiment of the present invention, Figure 2 As shown, based on the first comparison result, the database of the test environment is modified, including:

[0090] 202: Based on the first comparison result, determine the missing and excess databases in the test environment compared to the production environment, and delete the excess databases from the test environment.

[0091] 204: Obtain the type and library name of the missing database, build a new second database in the test environment based on the type and library name of the missing database, and configure the new second database;

[0092] 206: Acquire the third data table and the data stored in the third data table contained in the missing database, and add the third data table and the data stored in the third data table to the new second database.

[0093] Specifically, the library names of multiple first databases corresponding to the production environment are compared with the library names of multiple second databases corresponding to the test environment, and the first databases and second databases with the same library name are regarded as a group of databases. The differences between the data tables contained in each group of databases and the data stored in the data tables are compared.

[0094] Based on the first comparison results, the test environment determines which databases are missing compared to the production environment. Based on the type and library name of the missing database, a new second database is constructed in the test environment. The newly constructed second database is configured so that the type and library name of the newly constructed second database are the same as those of the missing database. The data tables and data stored in the missing databases are obtained, and then the data tables and stored data are stored in the corresponding newly constructed second databases.

[0095] According to the first comparison result, it is found that the test environment has an extra database than the production environment. The extra database is directly deleted to keep the database in the test environment exactly the same as the database in the production environment.

[0096] In another embodiment of the present invention, Figure 3 , based on the second comparison result, modifying the data table in the second database, including:

[0097] 302: Determine, based on the second comparison result, which data tables the second database lacks and which data tables are extra in the second database compared to the first database, and delete the extra data tables from the second database;

[0098] 304: Obtain the table name of the missing data table, and construct a new second data table in the second database based on the table name of the missing data table;

[0099] 306: Acquire the data stored in the missing data table, and add the data stored in the missing data table to the newly created second data table.

[0100] Specifically, after the first database in the production environment and the second database in the test environment are consistent, the first database and the second database with the same database name are grouped as a group of databases, and then the differences in the data tables included in each group of databases are compared.

[0101] Based on the second comparison results, the data tables missing and extra in the second database compared to the first database are obtained. A new second data table is constructed in the second database of each group of databases. The table name of the new second data table is set to the table name of the missing data table. The data stored in the missing data table is copied in each group of databases, and the copied content is added to the newly created second data table in the second database. Data tables that exist in the second database of the group of databases but are not in the first database are deleted from the second database.

[0102] In another embodiment of the present invention, the data stored in the data table includes the content, type, length and index of the field, and the third comparison result includes the content comparison result, the type comparison result, the length comparison result and the index comparison result, such as Figure 4 As shown, comparing the data stored in the first data table with the data stored in the second data table to obtain a third comparison result includes:

[0103] 402: Compare the content of the first field stored in the first data table with the content of the second field stored in the second data table to obtain a content comparison result;

[0104] 404: Determine, based on the content comparison result, the first field and the second field with identical content, as well as the missing fields and the extra fields in the second data table;

[0105] 406: The first field and the second field with the same content are grouped as fields. For each group of fields, the length of the first field is compared with the length of the second field to obtain a length comparison result.

[0106] 408: For each group of fields, compare the type of the first field with the type of the second field to obtain a type comparison result, and compare the index of the first field with the index of the second field to obtain an index comparison result.

[0107] In this embodiment, after the first database in the production environment and the second database in the test environment are consistent, and the data tables in the first database and the data tables in the second database in each group of databases are also completely consistent, the differences in the data stored in each data table in each group of databases are then compared.

[0108] The data stored in a data table includes the content, type, length, and index of the field. Therefore, the content, type, length, and index of the field are compared separately. The field content stored in the first data table of a set of data tables is compared with the field content stored in the second data table. The fields in the second data table with the same content as the field content in the first data table are determined, as well as the fields missing or additional in the second data table compared to the first data table. The missing and additional fields are then processed accordingly.

[0109] In a group of data tables, the first field and the second field with the same field content are regarded as a group of fields. For a group of fields, the length of the first field and the length of the second field in the group are compared to determine the fields with different lengths. For the fields with different lengths, the length of the second field is processed accordingly.

[0110] For a group of fields, the type of the first field and the type of the second field in the group of fields are compared to determine the fields with different types, and for the fields with different types, the type of the second field is processed accordingly.

[0111] Finally, we compare whether the fields have indexes and whether they are unique indexes. For a group of fields, we compare the index of the first field with the index of the second field in the group, identify the fields with different indexes, and perform corresponding processing on the index of the second field.

[0112] In another embodiment of the present invention, Figure 5 As shown, according to the third comparison result, modifying the data stored in the second data table includes:

[0113] 502: Obtain the content, type, length, and index corresponding to the missing field, add the content, type, length, and index corresponding to the missing field to the second data table, and delete the content, type, length, and index corresponding to the extra field from the second data table;

[0114] 504: Determine, based on the length comparison result, multiple groups of fields with the same content but different lengths. For each group of fields with the same content but different lengths, obtain the length corresponding to the first field, and modify the length corresponding to the second field in the second data table according to the length corresponding to the first field.

[0115] 506: Based on the type comparison result, multiple groups of fields with the same content but different types are determined. For each group of fields with the same content but different types, the type corresponding to the first field is obtained, and the type corresponding to the second field in the second data table is modified according to the type corresponding to the first field.

[0116] 508: Based on the index comparison result, multiple groups of fields with the same content but different indexes are determined. For each group of fields with the same content but different indexes, the index corresponding to the first field is obtained, and the index corresponding to the second field in the second data table is modified according to the index corresponding to the first field.

[0117] In this embodiment, based on the content comparison results, the fields missing and the fields extra in the second data table of each group of data tables compared with the first data table are obtained, the content, type, length, index, etc. of the missing fields are completely copied in the first data table of each group of data tables, and the copied content is added to the second data table of the group of data tables; the content, type, length and index corresponding to the fields that exist in the second data table of the group of data tables but not in the first data table are deleted from the second data table.

[0118] When the field contents of a group of fields are the same but the field lengths are different, it is necessary to modify the length of the second field in the group of fields according to the length of the first field so that the length of the second field in the group of fields is the same as the length of the first field, and the lengths of the fields with the same content in the second data table and the first data table are exactly the same.

[0119] When a group of fields have the same field content but different field types, it is necessary to modify the type of the second field in the group of fields according to the type of the first field so that the type of the second field in the group of fields is the same as the type of the first field, and the types of the fields with the same content in the second data table and the first data table are exactly the same.

[0120] When the field contents of a group of fields are the same but the field lengths are different, it is necessary to modify the length of the second field in the group of fields according to the length of the first field so that the length of the second field in the group of fields is the same as the length of the first field, and the lengths of the fields with the same content in the second data table and the first data table are exactly the same.

[0121] When a group of fields have the same content but different indexes, the index of the second field in the group of fields needs to be modified according to the index of the first field, so that the index of the second field in the group of fields is the same as the index of the first field, and the indexes of the fields with the same content in the second data table and the first data table are exactly the same, ensuring that the content, type, length and index of the second field in the group of fields are exactly the same as the content, type, length and index of the first field.

[0122] For example, a test environment is synchronized with the production environment, and the missing indexes in the corresponding fields of the corresponding tables in the corresponding databases are supplemented to avoid call timeouts due to slow queries.

[0123] Furthermore, as a response to the above Figure 1 The implementation of the method shown, such as Figure 6As shown, an embodiment of the present invention provides a synchronization device for a database structure, including:

[0124] A synchronization instruction generation module 602 is used to generate database structure synchronization instructions at regular intervals according to the synchronization requirements of the database structure;

[0125] The database modification module 604 is configured to obtain, based on the database structure synchronization instruction, the library names of multiple first databases in the production environment and the library names of multiple second databases in the test environment, compare the library names of the first databases with the library names of the second databases to obtain a first comparison result, and modify the databases in the test environment based on the first comparison result;

[0126] The data table modification module 606 is configured to treat the first database and the second database having the same database name as a group of databases, compare the table names of the first data tables contained in the first database with the table names of the second data tables contained in the second database for each group of databases, obtain a second comparison result, and modify the data tables in the second database according to the second comparison result;

[0127] The field modification module 608 is used to treat the first data table and the second data table with the same table name as a group of data tables, compare the data stored in the first data table with the data stored in the second data table for each group of data tables, obtain a third comparison result, and modify the data stored in the second data table according to the third comparison result.

[0128] Compared with the prior art, the database structure synchronization device provided by the present application uses periodically generated database synchronization instructions to compare the databases, data tables, and data stored in the data tables corresponding to the production environment with the databases, data tables, and data stored in the data tables corresponding to the test environment layer by layer. According to the comparison results, corresponding modifications are made to the databases, data tables, and data stored in the data tables in the test environment, and the differences are adjusted to ensure that the test environment database structure is fully synchronized with the production environment database structure. There is no need to manually synchronize the test environment database structure, which avoids data loss, enhances the stability of the test environment, and also reduces the workload of operation and maintenance personnel in maintaining the test environment database structure.

[0129] In one embodiment, the database modification module is further configured to:

[0130] Based on the first comparison result, determine the missing and extra databases in the test environment compared to the production environment, and delete the extra databases from the test environment;

[0131] Obtaining the type and library name of the missing database, building a new second database in the test environment based on the type and library name of the missing database, and configuring the new second database;

[0132] The third data table and the data stored in the third data table included in the missing database are obtained, and the third data table and the data stored in the third data table are added to the new second database.

[0133] In one embodiment, the data table modification module is further configured to:

[0134] Determine, based on the second comparison result, which data tables the second database lacks and which data tables are extra in comparison with the first database, and delete the extra data tables from the second database;

[0135] Obtaining the table name of the missing data table, and constructing a new second data table in the second database based on the table name of the missing data table;

[0136] The data stored in the missing data table is obtained, and the data stored in the missing data table is added to the newly created second data table.

[0137] In one embodiment, the data stored in the data table includes the content, type, length, and index of the field, and the third comparison result includes the content comparison result, the type comparison result, the length comparison result, and the index comparison result; the field modification module is further used to:

[0138] Comparing the content of the first field stored in the first data table with the content of the second field stored in the second data table to obtain a content comparison result;

[0139] Determine, based on the content comparison result, the first field and the second field with identical content, as well as the missing fields and the extra fields in the second data table;

[0140] The first field and the second field with the same content are regarded as a group of fields. For each group of fields, the length of the first field and the length of the second field are compared to obtain a length comparison result.

[0141] For each group of fields, the type of the first field is compared with the type of the second field to obtain a type comparison result, and the index of the first field is compared with the index of the second field to obtain an index comparison result.

[0142] In one embodiment, the field modification module is further configured to:

[0143] Get the content, type, length and index of the missing fields;

[0144] Add the content, type, length and index of the missing fields in the second data table;

[0145] Delete the content, type, length and index corresponding to the extra fields from the second data table.

[0146] In one embodiment, the field modification module is further configured to:

[0147] According to the length comparison results, multiple groups of fields with the same content but different lengths are determined;

[0148] For each group of fields with the same content but different lengths, the length corresponding to the first field is obtained, and the length corresponding to the second field in the second data table is modified according to the length corresponding to the first field.

[0149] In one embodiment, the field modification module is further configured to:

[0150] Based on the type comparison results, multiple groups of fields with the same content but different types are determined;

[0151] For each group of fields with the same content but different types, obtain the type corresponding to the first field, and modify the type corresponding to the second field in the second data table according to the type corresponding to the first field;

[0152] Based on the index comparison results, multiple groups of fields with the same content but different indexes are determined;

[0153] For each group of fields with the same content but different indexes, the index corresponding to the first field is obtained, and the index corresponding to the second field in the second data table is modified according to the index corresponding to the first field.

[0154] According to another aspect of the present application, a storage medium is provided, in which at least one executable instruction is stored. The executable instruction enables a processor to execute operations corresponding to the above-mentioned database structure synchronization method.

[0155] According to one embodiment of the present invention, a storage medium is provided. The storage medium stores at least one executable instruction. The computer-executable instruction can execute the database structure synchronization method in any of the above method embodiments.

[0156] Figure 7 A schematic structural diagram of a computer device provided according to an embodiment of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the computer device.

[0157] like Figure 7 As shown, the computer device may include: a processor (processor) 702 , a communication interface (Communications Interface) 704 , a memory (memory) 706 , and a communication bus 708 .

[0158] The processor 702 , the communication interface 704 , and the memory 706 communicate with each other via a communication bus 708 .

[0159] The communication interface 704 is configured to communicate with network elements such as clients or other servers.

[0160] The processor 702 is configured to execute the program 710, and specifically, execute the related steps in the synchronization method embodiments of the database structure.

[0161] Specifically, the program 710 can include program codes, which include computer operation instructions.

[0162] The processor 702 can be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present application. The one or more processors included in the computer device can be processors of the same type, such as one or more CPUs, or processors of different types, such as one or more CPUs and one or more ASICs.

[0163] The memory 706 is configured to store the program 710. The memory 706 can include a high-speed RAM memory, and can also include a non-volatile memory, such as at least one disk memory.

[0164] The program 710 can be specifically configured to cause the processor 702 to perform the following operations:

[0165] According to the synchronization requirement of the database structure, the database structure synchronization instruction is generated in a timely manner;

[0166] Based on the database structure synchronization instruction, the library names of the plurality of first databases located in the production environment and the library names of the plurality of second databases located in the test environment are obtained, the library names of the first databases and the library names of the second databases are compared, a first comparison result is obtained, and the database in the test environment is modified according to the first comparison result;

[0167] The first database and the second database with the same library name are taken as a group of databases, for each group of databases, the table names of a plurality of first data tables contained in the first database and the table names of a plurality of second data tables contained in the second database are compared, a second comparison result is obtained, and the data tables in the second database are modified according to the second comparison result;

[0168] The first data table and the second data table with the same table name are taken as a group of data tables, for each group of data tables, the data stored in the first data table and the data stored in the second data table are compared, a third comparison result is obtained, and the data stored in the second data table is modified according to the third comparison result.

[0169] The above embodiments are merely exemplary embodiments of the present application and are not intended to limit the scope of the present application. The scope of protection of the present application is defined by the claims. Those skilled in the art may make various modifications or equivalent substitutions to the present application within the essence and scope of protection of the present application, and such modifications or equivalent substitutions shall also be deemed to fall within the scope of protection of the present application.

Claims

1. A method for synchronizing a database structure, characterized in that: include: Generate database structure synchronization instructions regularly according to the synchronization requirements of the database structure; Based on the database structure synchronization instruction, obtaining the library names of multiple first databases located in the production environment and the library names of multiple second databases located in the test environment, comparing the library names of the first databases with the library names of the second databases to obtain a first comparison result, and modifying the databases in the test environment according to the first comparison result; A first database and a second database with the same database name are grouped as a group of databases. For each group of databases, the table names of multiple first data tables contained in the first database are compared with the table names of multiple second data tables contained in the second database to obtain a second comparison result. Based on the second comparison result, the data tables in the second database are modified. A first data table and a second data table with the same table name are regarded as a group of data tables. For each group of data tables, data stored in the first data table and data stored in the second data table are compared to obtain a third comparison result. Based on the third comparison result, the data stored in the second data table is modified.

2. The method for synchronizing a database structure according to claim 1, wherein: The modifying of the database of the test environment according to the first comparison result includes: Determine, based on the first comparison result, which databases the test environment lacks and which databases are extra compared to the production environment, and delete the extra databases from the test environment; Obtaining the type and library name of the missing database, building a new second database in the test environment based on the type and library name of the missing database, and configuring the new second database; The third data table and the data stored in the third data table included in the missing database are obtained, and the third data table and the data stored in the third data table are added to the new second database.

3. The method for synchronizing a database structure according to claim 1, wherein: The modifying the data table in the second database according to the second comparison result includes: Determining, based on the second comparison result, data tables that are missing and data tables that are extra in the second database compared to the first database, and deleting the extra data tables from the second database; Obtaining the table name of the missing data table, and constructing a new second data table in the second database based on the table name of the missing data table; The data stored in the missing data table is obtained, and the data stored in the missing data table is added to the newly created second data table.

4. The method for synchronizing a database structure according to claim 1, wherein: The data stored in the data table includes the content, type, length and index of the field, and the third comparison result includes the content comparison result, the type comparison result, the length comparison result and the index comparison result; the data stored in the first data table and the data stored in the second data table are compared to obtain the third comparison result, including: Comparing the content of the first field stored in the first data table with the content of the second field stored in the second data table to obtain a content comparison result; Determining, based on the content comparison result, a first field and a second field with identical content, as well as missing fields and extra fields in the second data table; A first field and a second field with the same content are taken as a group of fields, and for each group of fields, the length of the first field is compared with the length of the second field to obtain a length comparison result; For each group of fields, the type of the first field and the type of the second field are compared to obtain a type comparison result, and the index of the first field and the index of the second field are compared to obtain an index comparison result.

5. The method for synchronizing a database structure according to claim 4, wherein: After determining the first field and the second field with the same content and the missing fields and the extra fields in the second data table, modifying the data stored in the second data table according to the third comparison result includes: Get the content, type, length and index of the missing field. Add the content, type, length and index corresponding to the missing field in the second data table; The content, type, length and index corresponding to the extra fields are deleted from the second data table.

6. The method for synchronizing a database structure according to claim 4, wherein: The step of comparing the length of the first field with the length of the second field for each group of fields to obtain a length comparison result, and then modifying the data stored in the second data table according to the third comparison result, includes: According to the length comparison results, multiple groups of fields with the same content but different lengths are determined; For each group of fields with the same content but different lengths, the length corresponding to the first field is obtained, and the length corresponding to the second field in the second data table is modified according to the length corresponding to the first field.

7. The method for synchronizing a database structure according to claim 4, wherein: For each group of fields, comparing the type of the first field with the type of the second field to obtain a type comparison result, comparing the index of the first field with the index of the second field to obtain an index comparison result, and then modifying the data stored in the second data table according to the third comparison result, including: Based on the type comparison results, multiple groups of fields with the same content but different types are determined; For each group of fields with the same content but different types, obtain the type corresponding to the first field, and modify the type corresponding to the second field in the second data table according to the type corresponding to the first field; Based on the index comparison results, multiple groups of fields with the same content but different indexes are determined; For each group of fields with the same content but different indexes, the index corresponding to the first field is obtained, and the index corresponding to the second field in the second data table is modified according to the index corresponding to the first field.

8. A synchronization device for a database structure, characterized in that: include: A synchronization instruction generation module is used to generate database structure synchronization instructions at regular intervals according to the synchronization requirements of the database structure; a database modification module, configured to obtain, based on the database structure synchronization instruction, library names of a plurality of first databases in a production environment and library names of a plurality of second databases in a test environment, compare the library names of the first databases with the library names of the second databases to obtain a first comparison result, and modify the databases in the test environment according to the first comparison result; a data table modification module, configured to treat a first database and a second database having the same database name as a group of databases, compare, for each group of databases, the table names of a plurality of first data tables contained in the first database with the table names of a plurality of second data tables contained in the second database, obtain a second comparison result, and modify the data tables in the second database according to the second comparison result; The field modification module is used to treat a first data table and a second data table with the same table name as a group of data tables. For each group of data tables, the data stored in the first data table and the data stored in the second data table are compared to obtain a third comparison result. According to the third comparison result, the data stored in the second data table is modified.

9. A storage medium storing at least one executable instruction, characterized in that: The executable instructions enable the processor to execute operations corresponding to the database structure synchronization method according to any one of claims 1 to 7.

10. A computer device comprising: A processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, wherein the executable instruction enables the processor to execute an operation corresponding to the database structure synchronization method according to any one of claims 1 to 7.