Database sequence synchronization method, device, electronic device and readable storage medium
By matching and synchronizing the sequences of the source database and the target database during the database synchronization process, the problem of database sequence synchronization is solved, and data consistency and operation and maintenance simplification after database switching is achieved.
Patent Information
- Application Number
- CN202111619575.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-12-27
AI Technical Summary
Existing database synchronization technology cannot synchronize database sequences, resulting in inconsistent sequence objects attributes of the source database and the target database, and even the target database does not have corresponding sequence objects, resulting in data conflicts.
By obtaining the corresponding target table in the source database in the target database, the source field of the sequence used in the source table, and the source sequence associated with the source field, we can determine whether there are target fields and target sequences of the same name in the target table, and if there is, synchronous matching is performed. If the target sequence does not exist in the target table, a synchronous match is automatically created and synchronously matched.
Automatic synchronization matching between source database and target database sequence is realized, ensuring that no data conflicts occur due to sequence attribute differences after database switching, and simplifying database operation and maintenance.
Smart Images

Figure CN114443762B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of database synchronization, and in particular to a method, device, electronic device and readable storage medium for synchronizing a database sequence. Background Art
[0002] Oracle, PostgreSQL and other databases have sequences. Although MySQL does not have sequences, it can use the AUTO_INCREMENT keyword to generate auto-increment primary keys to achieve a sequence-like effect. A sequence is a database object that can generate a series of values that increase (or decrease) according to certain rules. It is often used to generate primary key values for a table. A sequence object contains attributes such as name, start value, and increment value.
[0003] The data synchronization component of the database has the functions of incremental synchronization and full synchronization, but currently only synchronizes the data in the table and cannot synchronize the database sequence, resulting in inconsistent sequence object properties between the source database and the target database, or even the target database does not have the corresponding sequence object. At this time, if you switch from the source database to the target database, data conflicts will occur due to differences in sequence object properties. Therefore, the database sequence synchronization problem has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a method, device, electronic device and readable storage medium for synchronizing database sequences to solve the problem that the sequences of a source database and a target database are difficult to synchronize.
[0005] According to a first aspect, an embodiment of the present invention provides a method for synchronizing a database sequence, comprising: obtaining a target table in a source database corresponding to a source table in a source database, a source field using a sequence in the source table, and a source sequence associated with the source field; determining whether there is a target field with the same name as the source field in the target table; when there is a target field with the same name as the source field in the target table, determining whether there is a target sequence associated with the target field in the target table; when there is a target sequence associated with the target field in the target table, synchronizing and matching the source sequence with the target sequence.
[0006] The method for synchronizing a database sequence provided by an embodiment of the present invention obtains the target table corresponding to the source table in the source database in the target database, the source field using the sequence in the source table, and the source sequence associated with the source field, and determines whether there is a target field with the same name as the source field in the target table. When there is a target field with the same name as the source field in the target table, it further determines whether there is a target sequence associated with the target field in the target table. When there is a target sequence associated with the target field in the target table, the source sequence is synchronized and matched with the target sequence. The method determines the corresponding relationship between the source sequence and the target sequence through the corresponding relationship between the source table and the target table and the fields with the same name, solves the problem that the sequences of the source database and the target database are difficult to synchronize, and realizes automatic synchronization and matching of the source sequence and the target sequence.
[0007] In combination with the first aspect, in a first implementation of the first aspect, the synchronously matching the source sequence with the target sequence includes: obtaining the types of the source database and the target database, a first attribute value corresponding to the source sequence, and a second attribute value corresponding to the target sequence; and matching the first attribute value with the second attribute value based on the types of the source database and the target database.
[0008] The database sequence synchronization method provided in an embodiment of the present invention obtains the types of the source database and the target database, and matches the first attribute value corresponding to the source sequence and the second attribute value corresponding to the target sequence based on the types of the source database and the target database, so as to keep the sequence attributes of both ends of the source database and the target database consistent, so that no data conflict will occur due to the difference in sequence attributes after the database is switched.
[0009] In combination with the first implementation manner of the first aspect, in the second implementation manner of the first aspect, the matching of the first attribute value with the second attribute value based on the types of the source database and the target database includes: determining whether the source database and the target database are isomorphic based on the types of the source database and the target database; when the source database and the target database are isomorphic, matching the first attribute value with the second attribute value.
[0010] In combination with the second implementation of the first aspect, in the third implementation of the first aspect, the method also includes: when the source database and the target database are heterogeneous, obtaining a conversion method between the source database and the target database; converting the first attribute value based on the conversion method, and updating the second attribute value with the converted first attribute value.
[0011] The database sequence synchronization method provided by the embodiment of the present invention determines whether the source database and the target database are isomorphic. When the source database and the target database are isomorphic, the first attribute value is matched with the second attribute value; when the source database and the target database are heterogeneous, the conversion method between the source database and the target database is obtained, the first attribute value is converted based on the conversion method, and the converted first attribute value is synchronously updated to the target sequence, thereby ensuring the sequence consistency in the source database and the target database, and avoiding data conflicts caused by sequence differences after switching databases.
[0012] In combination with the first implementation of the first aspect, in the fourth implementation of the first aspect, the method also includes: determining a sequence in which the first attribute value and the second attribute value are inconsistent based on the first attribute value and the second attribute value; and synchronizing attribute values of the sequence in which the first attribute value and the second attribute value are inconsistent.
[0013] The database sequence synchronization method provided in the embodiment of the present invention determines the sequence whose first attribute value is inconsistent with the second attribute value by comparing the first attribute value with the second attribute value, and synchronizes the attribute values of the sequence whose first attribute value is inconsistent with the second attribute value, so as to facilitate the user to perform database operation and maintenance.
[0014] In combination with the first aspect, in the fifth implementation of the first aspect, the method also includes: when there is no target sequence associated with the target field in the target table, creating a sequence associated with the target field; and synchronously matching the source sequence with the created sequence associated with the target field.
[0015] The database sequence synchronization method provided by the embodiment of the present invention can automatically create a sequence associated with the target field when the target sequence associated with the target field does not exist in the target table, without manual configuration and creation, and synchronize the source sequence with the sequence associated with the created target field, so that the source database and the target database can perform sequence matching, further realizing sequence synchronization between the source database and the target database.
[0016] In combination with the first aspect, in a sixth implementation of the first aspect, obtaining the target table in the target database corresponding to the source table in the source database includes: obtaining a mapping relationship between the source database and the target database; and determining the target table corresponding to the source table based on the mapping relationship.
[0017] The database sequence synchronization method provided by the embodiment of the present invention obtains the mapping relationship between the source database and the target database, and determines the target table corresponding to the source table based on the mapping relationship. The method queries the target table corresponding to the source table from the target database through the mapping relationship between the source table and the target table, further ensuring the accurate matching of the source table and the target table.
[0018] According to a second aspect, an embodiment of the present invention provides a synchronization device for a database sequence, comprising: an acquisition module, used to acquire a target table in a source database corresponding to a source table in a source database, a source field using a sequence in the source table, and a source sequence associated with the source field; a first judgment module, used to judge whether there is a target field with the same name as the source field in the target table; a second judgment module, used to judge whether there is a target sequence associated with the target field in the target table when there is a target field with the same name as the source field in the target table; and a synchronization module, used to synchronize and match the source sequence with the target sequence when there is a target sequence associated with the target field in the target table.
[0019] According to the third aspect, an embodiment of the present invention provides an electronic device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the database sequence synchronization method described in the first aspect or any embodiment of the first aspect by executing the computer instructions.
[0020] According to a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the database sequence synchronization method described in the first aspect or any embodiment of the first aspect.
[0021] It should be noted that, for the corresponding beneficial effects of the database sequence synchronization device, electronic device and computer-readable storage medium provided in the embodiments of the present invention, please refer to the description of the corresponding contents in the database sequence synchronization method, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 is a flowchart of a method for synchronizing a database sequence according to an embodiment of the present invention;
[0024] Figure 2 is another flow chart of a method for synchronizing a database sequence according to an embodiment of the present invention;
[0025] Figure 3 is another flow chart of a method for synchronizing a database sequence according to an embodiment of the present invention;
[0026] Figure 4 The overall architecture diagram of the data synchronization system in an embodiment of the present invention is shown;
[0027] Figure 5 is a structural block diagram of a synchronization device for a database sequence according to an embodiment of the present invention;
[0028] Figure 6 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0030] According to an embodiment of the present invention, an embodiment of a method for synchronizing a database sequence is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0031] This embodiment provides a data synchronization system, which includes: a source database, a target database, a management node cluster, a synchronization node cluster, and a coordinator cluster. Figure 4 As shown in the figure, the source database can support MySQL database, Oracle database, PostgreSQL database, etc.; the target database can support relational database, distributed file system and unstructured database, etc.; the management node cluster is used for data synchronization configuration, and pushes the data synchronization configuration to the synchronization node cluster, and receives the data synchronization status, progress and other information fed back by the synchronization node cluster; the synchronization node cluster is used to execute the specific data synchronization process; the coordinator cluster is used to coordinate data synchronization.
[0032] In this embodiment, a method for synchronizing a database sequence is provided, which can be used for electronic devices equipped with a data synchronization system, such as a server, a computer, etc. Figure 1 is a flowchart of a method for synchronizing a database sequence according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0033] S11, obtaining a target table in the target database corresponding to a source table in the source database, a source field using a sequence in the source table, and a source sequence associated with the source field.
[0034] The source database is the source database, the source table is the data table in the source database used to store data, the target database is the target database corresponding to the source database, and the target table is the data table in the target database corresponding to the source table. The source field is the field in the source table that uses the sequence, and the source sequence is the database sequence generated by the source database using the sequence object.
[0035] The electronic device may query the source table information in the source database to determine the source field using the sequence in the source table information, and query the source sequence associated with the source field in the source table.
[0036] S12, determining whether there is a target field in the target table with the same name as the source field.
[0037] The target field is a field with the same name as the source field. The target table is queried according to the field name corresponding to the source field to determine whether there is a target field with the same name as the source field in the target table. For example, if the name of the source field is s_column, the target field with the same name as s_column is queried in the target table, and the target field is marked as t_column to distinguish whether the field is in the source table or the target table. When there is a target field with the same name as the source field in the target table, step S13 is executed, otherwise the data synchronization operation is not executed.
[0038] S13, determining whether there is a target sequence associated with the target field in the target table.
[0039] The target sequence is a database sequence generated by using a sequence object contained in the target table. When there is a target field with the same name as the source field in the target table, the target sequence corresponding to the target field is further queried in the target table. For example, when there is a target field t_column in the target table, the sequence generated by using the sequence object for the target field t_column is further queried in the target table, and the sequence is the target sequence t_seq associated with the target field. When there is a target sequence associated with the target field in the target table, step S14 is executed, otherwise other operations are executed.
[0040] Among them, the other operation may be to create a sequence to match the created sequence with the source sequence and synchronize the data; the other operation may also be to perform a secondary search to determine whether the target sequence exists in the target table to ensure the query accuracy of the target sequence. Of course, the other operation may also be a processing flow of other modes, which is not specifically limited here, and those skilled in the art may determine it according to actual needs.
[0041] S14, synchronously matching the source sequence with the target sequence.
[0042] When there is a target sequence associated with the target field in the target table, a mapping relationship between the source sequence and the target sequence can be established to match the source sequence and the target sequence into corresponding sequences, and synchronize the data of the source sequence and the target sequence.
[0043] The database sequence synchronization method provided in this embodiment determines the correspondence between the source sequence and the target sequence through the correspondence between the source table and the target table and the fields with the same name, thereby solving the problem that the sequences of the source database and the target database are difficult to synchronize, and realizing automatic synchronization matching of the source sequence and the target sequence.
[0044] In this embodiment, a method for synchronizing a database sequence is provided, which can be used for electronic devices equipped with a data synchronization system, such as a server, a computer, etc. Figure 2 is a flowchart of a method for synchronizing a database sequence according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0045] S21, obtaining the target table corresponding to the source table in the source database in the target database, the source field using the sequence in the source table, and the source sequence associated with the source field. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0046] S22, determine whether there is a target field with the same name as the source field in the target table. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0047] S23, when there is a target field with the same name as the source field in the target table, it is determined whether there is a target sequence associated with the target field in the target table. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0048] S24, when there is a target sequence associated with the target field in the target table, the source sequence is synchronously matched with the target sequence.
[0049] Specifically, the above step S24 may include:
[0050] S241, obtaining the types of the source database and the target database, the first attribute value corresponding to the source sequence, and the second attribute value corresponding to the target sequence.
[0051] The source database is a relational database, which may be MySQL, Oracle, PostgreSQL, etc., and the target database may be a relational database. The electronic device may determine the types of the source database and the target database by identifying the database schema definition language (DDL) statement corresponding to the source table.
[0052] The first attribute value is used to characterize the attribute of the sequence object generating the source sequence, and the second attribute value is used to characterize the attribute of the sequence object generating the target sequence. The electronic device can read the source sequence and the target sequence, and determine the first attribute value corresponding to the source sequence and the second attribute value corresponding to the target sequence according to the reading results of the source sequence and the target sequence. The first attribute value may include the initial value, incremental value, minimum value, maximum value, current value, etc. of the source sequence, and the second attribute value may include the initial value, incremental value, minimum value, maximum value, current value, etc. of the target sequence.
[0053] S242: Match the first attribute value with the second attribute value based on the types of the source database and the target database.
[0054] The electronic device can compare the types of the source database and the target database to determine whether the types of the source database and the target database are the same, and match the first attribute value and the second attribute value based on the types of the two to achieve synchronization of the first attribute value and the second attribute value.
[0055] Specifically, the above step S242 may include:
[0056] (1) Based on the types of the source database and the target database, determine whether the source database and the target database are isomorphic.
[0057] If the source database and the target database are of the same type, it means that the source database and the target database are isomorphic. If the source database and the target database are of different types, it means that the source database and the target database are heterogeneous. The electronic device can determine whether the source database and the target database are isomorphic by identifying the types of the source database and the target database. When the source database and the target database are isomorphic, step (2) is executed; otherwise, steps (3) and (4) are executed.
[0058] (2) Match the first attribute value with the second attribute value.
[0059] When the source database and the target database are isomorphic, it means that the sequence attributes supported by the source database and the target database are consistent. In this case, the first attribute value and the second attribute value can be directly synchronized and matched.
[0060] (3) Obtain the conversion method between the source database and the target database.
[0061] The conversion method is used to characterize the conversion syntax between the source database and the target database so that the first attribute value and the second attribute value can be matched. When the source database and the target database are heterogeneous, it means that the sequence attributes supported by the source database and the target database are different. For example, for some sequence attributes of the source database that are not supported by the target database, these attributes need to be discarded when matching the attribute values. For the case where the source database and the target database are heterogeneous, the electronic device can obtain the conversion syntax between the source database and the target database.
[0062] (4) The first attribute value is converted based on the conversion method, and the second attribute value is updated with the converted first attribute value.
[0063] The electronic device converts the first attribute value according to the conversion method to obtain a DDL statement applicable to the target database to ensure that the attributes contained in the first attribute value and the second attribute value are consistent. When the conversion from the first attribute value to the second attribute value is completed, the second attribute value of the target sequence is updated with the converted first attribute value.
[0064] S243: Based on the first attribute value and the second attribute value, determine a sequence in which the first attribute value and the second attribute value are inconsistent.
[0065] After completing the matching of the source sequence and the target sequence, the electronic device can read the first attribute value and the second attribute value that match each other respectively, and compare the first attribute value and the second attribute value to determine all sequences in the target table whose first attribute value and second attribute value are inconsistent.
[0066] S244: synchronize the attribute values of the sequence whose first attribute value is inconsistent with the second attribute value.
[0067] For a sequence with different first attribute values and second attribute values, the electronic device can execute a data repair process to update the second attribute value with the first attribute value to synchronize the first attribute value with the second attribute value and ensure the attribute consistency between the source sequence and the target sequence.
[0068] The database sequence synchronization method provided in this embodiment obtains the types of the source database and the target database, determines whether the source database and the target database are isomorphic based on the types of the source database and the target database, and matches the first attribute value with the second attribute value when the source database and the target database are isomorphic; when the source database and the target database are heterogeneous, obtains the conversion method between the source database and the target database, converts the first attribute value based on the conversion method, and synchronously updates the converted first attribute value to the target sequence, thereby ensuring the sequence consistency in the source database and the target database, avoiding data conflicts caused by sequence differences after switching databases. By comparing the first attribute value and the second attribute value, the sequence in which the first attribute value and the second attribute value are inconsistent is determined, and the attribute value of the sequence in which the first attribute value and the second attribute value are inconsistent is synchronized, so as to facilitate users to perform database operation and maintenance.
[0069] In this embodiment, a method for synchronizing a database sequence is provided, which can be used for electronic devices equipped with a data synchronization system, such as servers, computers, etc. Figure 3 is a flowchart of a method for synchronizing a database sequence according to an embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0070] S31, obtaining a target table in the target database corresponding to a source table in the source database, a source field using a sequence in the source table, and a source sequence associated with the source field.
[0071] Specifically, the above step S31 may include:
[0072] S311, obtaining a mapping relationship between a source database and a target database.
[0073] The mapping relationship is a pre-configured correspondence between the source database and the target database, and the correspondence is stored in the synchronization component of the electronic device. When performing synchronization from the source sequence to the target sequence, the electronic device can determine the mapping relationship between the source database and the target database by accessing the synchronization component.
[0074] S312: Determine a target table corresponding to the source table based on the mapping relationship.
[0075] When the source table to be synchronized is determined from the source database, the target database corresponding to the source database can be determined according to the mapping relationship, and then the target database is queried to determine the target table corresponding to the source table from the target database.
[0076] S313, obtaining the source field of the source table using the sequence and the source sequence associated with the source field. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0077] S32, determine whether there is a target field with the same name as the source field in the target table. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0078] S33, when there is a target field with the same name as the source field in the target table, it is determined whether there is a target sequence associated with the target field in the target table. If there is a target sequence associated with the target field in the target table, step S34 is executed. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here. Otherwise, step S35 is executed.
[0079] S34, when there is a target sequence associated with the target field in the target table, the source sequence is synchronously matched with the target sequence. For detailed description, please refer to the relevant description of the above embodiment, which will not be repeated here.
[0080] S35: When the target sequence associated with the target field does not exist in the target table, create a sequence associated with the target field.
[0081] When there is no target sequence associated with the target field in the target table, the electronic device may create a sequence in the target table according to the initial value, incremental value and other properties of the source sequence, and determine the sequence as the sequence associated with the target field.
[0082] S36, synchronously matching the source sequence with the sequence associated with the created target field.
[0083] A mapping relationship is established between the sequence associated with the created target field and the source sequence, and the source sequence is matched with the sequence associated with the created target field as a corresponding sequence, and then data synchronization is performed on the source sequence and the sequence associated with the created target field.
[0084] The database sequence synchronization method provided in this embodiment obtains the mapping relationship between the source database and the target database, and determines the target table corresponding to the source table based on the mapping relationship. The method queries the target table corresponding to the source table from the target database through the mapping relationship between the source table and the target table, further ensuring the accurate matching of the source table and the target table. When there is no target sequence associated with the target field in the target table, the sequence associated with the target field can be automatically created without manual configuration and creation, and the source sequence is synchronously matched with the sequence associated with the created target field, so that the source database and the target database can perform sequence matching, further realizing the sequence synchronization of the source database and the target database.
[0085] This embodiment takes the sequence synchronization from the source database MySQL to the target database PostgreSQL as an example to illustrate the synchronization method of the above database sequence. The DDL of the MySQL source table is as follows:
[0086] CREATE TABLE `oper_log`(
[0087] `log_id`bigint(20)NOT NULL AUTO_INCREMENT,
[0088] `oper_result`tinyint(4)DEFAULT NULL,
[0089] `created_time`datetime NOT NULL,
[0090] PRIMARY KEY(`log_id`)
[0091] ).
[0092] The DDL of the PostgreSQL target table is as follows:
[0093] CREATE TABLE "oper_log"(
[0094] "log_id"BIGINT NOT NULL UNIQUE DEFAULT nextval('"oper_log_id_seq"'),
[0095] "oper_result"SMALLINT,
[0096] "created_time"TIMESTAMP NOT NULL,
[0097] PRIMARY KEY("log_id")
[0098] ).
[0099] First, match the source sequence of the source table with the target sequence of the target database. Specifically, the electronic device recognizes the auto_increment keyword in the source table DDL and knows that the log_id field uses an auto-increment sequence. At this time, the sequence used by the log_id field in the target table can be found, and the statement is as follows:
[0100] SELECT column_default FROM information_schema.COLUMNS WHERE"table_name"='oper_log'AND"column_name"='log_id'AND column_default ILIKE'nextval(%';
[0101] According to the statement return result, the target sequence associated with the log_id field is oper_log_id_seq. If oper_log_id_seq does not exist, create a sequence corresponding to the log_id field. Since the default starting value and increment value of the MySQL auto-increment sequence are both 1, the starting value and increment value are also set to 1 when creating the sequence corresponding to the log_id field. The creation statement is as follows:
[0102] CREATE SEQUENCE IF NOT EXISTS"oper_log_id_seq"START WITH 1INCREMENTBY 1;
[0103] Set the auto-increment sequence of the source table and the oper_log_id_seq of the target table to correspond.
[0104] Secondly, the attribute values of the source sequence and the target sequence are synchronized. Specifically, taking the current value of the source sequence and the target sequence as an example, the electronic device can read the current value of the source sequence corresponding to the source table. The reading statement of the current value is as follows:
[0105] select auto_increment from information_schema.`TABLES`where TABLE_NAME='oper_log';
[0106] If the current value of the source sequence read out is 100, the current value of oper_log_id_seq is updated to 100. The update statement is: SELECT setval('oper_log_id_seq',100,false).
[0107] Again, check the attribute values of the source sequence and the target sequence. Specifically, the method of reading the current value of the source sequence is the same as the previous step. The statement for reading the current value of the target sequence oper_log_id_seq is as follows:
[0108] select last_value from'oper_log_id_seq';
[0109] Compare the current values of the two to see if they are consistent. When the current values of the two are inconsistent, the electronic device can perform data repair to update the current value of the target sequence with the current value of the source sequence to ensure the consistency of the attributes of the source sequence and the target sequence.
[0110] In this embodiment, a synchronization device for a database sequence is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0111] This embodiment provides a synchronization device for a database sequence, such as Figure 5 As shown, including:
[0112] The acquisition module 41 is used to acquire the target table corresponding to the source table in the source database in the target database, the source field using the sequence in the source table, and the source sequence associated with the source field. For detailed description, please refer to the relevant description corresponding to the above method embodiment, which will not be repeated here.
[0113] The first judgment module 42 is used to judge whether there is a target field with the same name as the source field in the target table. For detailed description, please refer to the relevant description corresponding to the above method embodiment, which will not be repeated here.
[0114] The second judgment module 43 is used to judge whether there is a target sequence associated with the target field in the target table when there is a target field with the same name as the source field in the target table. Detailed descriptions refer to the relevant descriptions corresponding to the above method embodiments, which will not be repeated here.
[0115] The synchronization module 44 is used to synchronize and match the source sequence with the target sequence when there is a target sequence associated with the target field in the target table. For detailed description, please refer to the relevant description corresponding to the above method embodiment, which will not be repeated here.
[0116] The database sequence synchronization device provided in this embodiment determines the correspondence between the source sequence and the target sequence through the correspondence between the source table and the target table and the fields with the same name, thereby solving the problem that the sequences of the source database and the target database are difficult to synchronize, and realizing automatic synchronization matching of the source sequence and the target sequence.
[0117] The synchronization device of the database sequence in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC circuit, a processor and a memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0118] The further functional description of each of the above modules is the same as that of the above corresponding embodiments and will not be repeated here.
[0119] The embodiment of the present invention also provides an electronic device having the above Figure 5 Synchronization means for the database sequence shown.
[0120] See also Figure 6 , Figure 6 is a schematic diagram of the structure of an electronic device provided by an optional embodiment of the present invention, such as Figure 6 As shown, the electronic device may include: at least one processor 501, such as a CPU (Central Processing Unit), at least one communication interface 503, a memory 504, and at least one communication bus 502. The communication bus 502 is used to realize the connection and communication between these components. The communication interface 503 may include a display screen (Display), a keyboard (Keyboard), and the optional communication interface 503 may also include a standard wired interface and a wireless interface. The memory 504 may be a high-speed RAM memory (Random Access Memory) or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 504 may optionally be at least one storage device located away from the aforementioned processor 501. The processor 501 may be combined with Figure 5 In the described device, the memory 504 stores an application program, and the processor 501 calls the program code stored in the memory 504 to execute any of the above method steps.
[0121] The communication bus 502 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 502 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0122] Among them, the memory 504 may include a volatile memory (English: volatile memory), such as a random access memory (English: random-access memory, abbreviated: RAM); the memory may also include a non-volatile memory (English: non-volatile memory), such as a flash memory (English: flash memory), a hard disk drive (English: hard disk drive, abbreviated: HDD) or a solid-state drive (English: solid-state drive, abbreviated: SSD); the memory 504 may also include a combination of the above types of memory.
[0123] The processor 501 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and a NP.
[0124] The processor 501 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0125] Optionally, the memory 504 is also used to store program instructions. The processor 501 can call the program instructions to implement the present application Figures 1 to 3 The database sequence synchronization method shown in the embodiment.
[0126] The embodiment of the present invention also provides a non-transitory computer storage medium, which stores computer executable instructions, and the computer executable instructions can execute the processing method of the database sequence synchronization method in any of the above method embodiments. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.
[0127] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for synchronizing a database sequence, characterized in that: include: Obtain a target table in a target database corresponding to a source table in a source database, a source field in the source table that uses a sequence, and a source sequence associated with the source field; Determine whether there is a target field with the same name as the source field in the target table; When there is a target field in the target table with the same name as the source field, determining whether there is a target sequence associated with the target field in the target table; When there is a target sequence associated with the target field in the target table, synchronously matching the source sequence with the target sequence includes: acquiring the types of the source database and the target database, a first attribute value corresponding to the source sequence, and a second attribute value corresponding to the target sequence; Based on the types of the source database and the target database, determine whether the source database and the target database are isomorphic; when the source database and the target database are isomorphic, match the first attribute value with the second attribute value; when the source database and the target database are heterogeneous, obtain a conversion method between the source database and the target database; convert the first attribute value based on the conversion method, and update the second attribute value with the converted first attribute value.
2. The method according to claim 1, characterized in that: Also includes: Based on the first attribute value and the second attribute value, determining a sequence in which the first attribute value and the second attribute value are inconsistent; Attribute value synchronization is performed on a sequence in which the first attribute value and the second attribute value are inconsistent.
3. The method according to claim 1, characterized in that Also includes: When the target sequence associated with the target field does not exist in the target table, create a sequence associated with the target field; The source sequence is synchronously matched with the sequence associated with the created target field.
4. The method according to claim 1, characterized in that: The step of obtaining a target table in the target database corresponding to a source table in the source database includes: Acquire a mapping relationship between the source database and the target database; Based on the mapping relationship, the target table corresponding to the source table is determined.
5. A synchronization device for a database sequence, characterized in that: include: An acquisition module, used for acquiring a target table in a target database corresponding to a source table in a source database, a source field using a sequence in the source table, and a source sequence associated with the source field; A first judgment module is used to judge whether there is a target field with the same name as the source field in the target table; A second judgment module is used to judge whether there is a target sequence associated with the target field in the target table when there is a target field with the same name as the source field in the target table; a synchronization module, configured to synchronize and match the source sequence with the target sequence when there is a target sequence associated with the target field in the target table, including: obtaining the types of the source database and the target database, a first attribute value corresponding to the source sequence, and a second attribute value corresponding to the target sequence; Based on the types of the source database and the target database, determine whether the source database and the target database are isomorphic; when the source database and the target database are isomorphic, match the first attribute value with the second attribute value; when the source database and the target database are heterogeneous, obtain a conversion method between the source database and the target database; convert the first attribute value based on the conversion method, and update the second attribute value with the converted first attribute value.
6. An electronic device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the database sequence synchronization method according to any one of claims 1 to 4 by executing the computer instructions.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the database sequence synchronization method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Restoration of UI state in transactional systems
CN107924411A
Data synchronizing method and device of distributed heterogeneous databases
CN108664659A