Database physical script generation method, device and electronic equipment
By acquiring the unit sharding information and database sharding configuration rules of the target environment, the database physical script is automatically generated and sent to the target environment, solving the problem of low efficiency of manual maintenance in the existing technology and realizing efficient automatic script generation.
Patent Information
- Application Number
- CN202211697613.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-28
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2042-12-28
AI Technical Summary
In existing technologies, the generation of database physical scripts requires a large amount of manual maintenance, resulting in low generation efficiency and the inability to automatically generate adaptive scripts based on the current configuration of the environment.
By obtaining the unit sharding information and database sharding configuration rules of the target environment, the database physical script is automatically generated and sent to the database of the target environment according to the mapping relationship, reducing manual maintenance.
It improves the efficiency of database physical script generation, reduces manual maintenance costs, and enables script generation that automatically adapts to the target environment.
Smart Images

Figure CN116126954B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to a method for generating database physical scripts, an apparatus for generating database physical scripts, a computer-readable storage medium, a processor, and an electronic device. Background Technology
[0002] As customer data in distributed banking systems grows increasingly large, database sharding and partitioning have become the optimal solution for improving performance. However, when packaging and releasing database scripts, due to differences in unit information and sharding strategies across environments, resource packages can only provide the corresponding logical library scripts. Currently, before deploying a new version in an environment, a packaging plugin is needed to generate physical scripts based on the target environment's unit information and sharding rules. Then, based on changes to the generated physical scripts, a set of database mapping rules must be manually maintained. The push tool then pushes the corresponding database upgrade content to the database according to the database mapping rules and the resource package. Currently, the generation of database physical scripts requires pre-specifying the corresponding unit information and sharding information; it cannot be generated in real-time based on the current environment configuration. This results in the generated physical library scripts becoming unusable when the current environment's unit information and sharding information change. The database physical script push list needs to be manually maintained. As the number of environments increases, environment maintenance personnel need to maintain a large number of database physical script push lists, and a large amount of mapping data also needs to be verified before each system upgrade.
[0003] Therefore, there is an urgent need for a method to generate database physical scripts that can reduce manual maintenance. Summary of the Invention
[0004] The main objective of this application is to provide a method for generating database physical scripts, a device for generating database physical scripts, a computer-readable storage medium, a processor, and an electronic device, so as to at least solve the problem of low generation efficiency caused by the need for a large amount of manual maintenance of database physical scripts in the prior art.
[0005] To achieve the above objectives, according to one aspect of this application, a method for generating a database physical script is provided, comprising: obtaining an original database script and configuration information, wherein the configuration information includes unit sharding information and database sharding configuration rules for a target environment, the unit sharding information being used to characterize the correspondence between units, databases, and tables; processing the original database script according to the configuration information to obtain a database physical script; and sending the database physical script to the database corresponding to the target environment.
[0006] Optionally, sending the database physical script to the database corresponding to the target environment includes: obtaining a first mapping relationship and a second mapping relationship, wherein the first mapping relationship is a mapping relationship between a resource path and the original database script, and the second mapping relationship is a mapping relationship between the original database script and the database physical script, and the resource path is the address of the database; generating a record table based on the first mapping relationship and the second mapping relationship, wherein the record table includes at least the name of the original database script, the name of the corresponding database physical script, the corresponding resource path, and the name of the record table; and sending the record table to at least the resource path of the database.
[0007] Optionally, sending the record table to at least the resource path of the database includes: sending the record table to the resource path of the database, and determining whether the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database; if the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database, not sending the database physical script; if the name of the record table corresponding to the database physical script is inconsistent with the name of the record table in the database, sending the database physical script to the database corresponding to the target environment.
[0008] Optionally, the record table further includes a database connection string, a username, and a password. Sending the record table to at least the resource path of the database includes: establishing a connection channel between the database physical script and the resource path of the database based on the database connection string, the username, and the password; and sending the record table to at least the resource path of the database through the connection channel.
[0009] Optionally, the original database script is processed according to the configuration information to obtain a database physical script, including: performing unit-sharding, database-sharding, and table-sharding operations on the original database script according to the unit sharding information; and processing the original database script after the unit-sharding, database-sharding, and table-sharding operations according to the database sharding and table-sharding configuration rules to obtain the database physical script.
[0010] Optionally, the database sharding and table partitioning configuration rules shall include at least: the partitioning algorithm, the specific method of the partitioning algorithm, the fields of the partitioned database, the fields of the partitioned table, and the name of the partitioned table.
[0011] Optionally, the table partitioning algorithm includes at least one of the following: noShard algorithm, cust algorithm, date algorithm, and the quart database physical script generation algorithm.
[0012] According to another aspect of this application, a database physical script generation apparatus is provided, comprising an acquisition unit, a processing unit, and a sending unit. The acquisition unit acquires an original database script and configuration information, the configuration information including unit sharding information and database sharding / table partitioning configuration rules for a target environment, the unit sharding information representing the correspondence between units, databases, and tables. The processing unit processes the original database script according to the configuration information to obtain a database physical script. The sending unit sends the database physical script to the database corresponding to the target environment.
[0013] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute any of the database physical script generation methods described above.
[0014] According to another aspect of this application, a processor is provided for running a program, wherein the program executes any of the methods for generating database physical scripts described above.
[0015] According to another aspect of this application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including a method for generating a database physical script according to any of the above.
[0016] Applying the technical solution of this application, the method for generating the database physical script firstly obtains the original database script and configuration information. The configuration information includes unit sharding information and database sharding configuration rules for the target environment. The unit sharding information is used to characterize the correspondence between units, databases, and tables. Then, the original database script is processed according to the configuration information to obtain the database physical script. Finally, the database physical script is sent to the database corresponding to the target environment. This method automatically generates a database physical script adapted to the target environment by obtaining the original database script and configuration information, and sends it to the database corresponding to the target environment, thereby reducing manual maintenance costs, improving the efficiency of database physical script generation, and solving the problem of low generation efficiency caused by the need for extensive manual maintenance of database physical scripts in the prior art. Attached Figure Description
[0017] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0018] Figure 1 A hardware structure block diagram of a computer terminal for executing a database physical script generation method provided in an embodiment of this application is shown.
[0019] Figure 2 A flowchart illustrating a method for generating a database physical script according to an embodiment of this application is shown.
[0020] Figure 3 A logic diagram of a method for generating a database physical script according to an embodiment of this application is shown;
[0021] Figure 4 A schematic diagram of a database physical script generation apparatus provided according to an embodiment of this application is shown.
[0022] The above figures include the following reference numerals:
[0023] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. Detailed Implementation
[0024] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0025] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0027] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0028] Database logic script: Database scripts without database sharding or table partitioning.
[0029] Database physical script: The database script generated based on the unit information, database sharding information, and database logical script of the environment is the script that is finally pushed to the database.
[0030] As described in the background section, existing database physical scripts require extensive manual maintenance, resulting in low generation efficiency. To address this issue, embodiments of this application provide a method for generating database physical scripts, an apparatus for generating database physical scripts, a computer-readable storage medium, a processor, and an electronic device.
[0031] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.
[0032] The methods and embodiments provided in this application can be executed on a computer terminal or similar computing device. Taking running on a computer terminal as an example, Figure 1 This is a hardware structure block diagram of a computer terminal for a database physical script generation method according to an embodiment of the present invention. Figure 1 As shown, a computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0033] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the device information display method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the communication provider of the computer terminal. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0034] This embodiment provides a method for generating a database physical script that runs on a computer terminal or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0035] Figure 2 This is a flowchart of a method for generating database physical scripts according to an embodiment of this application. For example... Figure 2 As shown, the method includes the following steps:
[0036] Step S201: Obtain the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables.
[0037] Specifically, as the amount of customer data in the distributed database of a bank increases, the QPS (Queries Per Second) of database queries also increases, leading to more and more database read and write times. Generally, database sharding and table partitioning are used to improve database performance and enhance availability. In development, testing, and production environments, the required unit strategies, sharding strategies, and database sharding and table partitioning strategies differ from environment to environment. The above configuration information can be used to obtain the unit strategies, sharding strategies, and database sharding and table partitioning strategies for the target environment.
[0038] In practical applications, the aforementioned unit allocation information is primarily stored in the system-level configuration of each system configuration center. The aforementioned database sharding and table partitioning configuration rules, as well as the aforementioned original database scripts, can be obtained from the resource packages provided by the application. The original database scripts contain database table creation statements, sharding data, etc., but do not contain any database sharding or table partitioning information. If the table is neither sharded nor partitioned, then this database script can be directly pushed to the database and stored in the resource file db directory.
[0039] In one optional scheme, the above-mentioned database sharding and table partitioning configuration rules include at least: sharding algorithm, specific sharding algorithm method, sharding database fields, sharding table fields, and sharding table names. The database sharding and table partitioning configuration rules are mainly provided by the business provider and stored in the SDK (Software Development Kit) resource package. Their main function is to provide data access layer database sharding table rules and physical database script generation for service users. The main attributes are shown in Table 1.
[0040] Table 1
[0041]
[0042] Furthermore, the above-mentioned table partitioning algorithms include at least one of the following: noShard algorithm, cust algorithm, date algorithm, and the Quartz database physical script generation algorithm. Based on business needs, the table partitioning algorithms are mainly divided into noShard, cust, date, and Quartz algorithms, as mainly described in Table 2:
[0043] Table 2
[0044]
[0045]
[0046] Step S202: Process the original database script according to the above configuration information to obtain the database physical script;
[0047] Specifically, the database physical script is generated based on the original database script in the resource package, the database sharding and table partitioning configuration rules, and the system's unit sharding information; that is, the script that is actually executed on the database.
[0048] In one alternative approach, the original database script is processed according to the above configuration information to obtain a physical database script, including: performing unit-sharding, database-sharding, and table-sharding operations on the original database script according to the above unit-sharding information; and processing the original database script after the above unit-sharding, database-sharding, and table-sharding operations according to the above database-sharding and table-sharding configuration rules to obtain the physical database script.
[0049] Step S203: Send the above-mentioned database physical script to the database corresponding to the target environment.
[0050] Specifically, in the database script push phase, the main task is to push the generated physical library script to the database of the corresponding environment.
[0051] Since the number of units, database sharding, and table sharding information vary across different environments, the resources required for pushing the database scripts also differ. To push the generated physical database scripts to the database more quickly and accurately, one option involves sending the physical database scripts to the database corresponding to the target environment. This includes: obtaining a first mapping relationship and a second mapping relationship, where the first mapping relationship is a mapping between a resource path and the original database script, and the second mapping relationship is a mapping between the original database script and the physical database script, with the resource path being the address of the database; generating a record table based on the first and second mapping relationships, where the record table includes at least the name of the original database script, the name of the corresponding physical database script, the corresponding resource path, and the name of the record table; and sending the record table to at least the resource path of the database.
[0052] Specifically, the first mapping relationship mainly describes the mapping relationship between resource paths and original database scripts. Although the number of units, database sharding, and table sharding information vary across environments, the resources that each system needs to push are almost the same, unless a new resource directory requires a new mapping relationship. Therefore, we template the database script mapping, and only need to manage and maintain a limited number of database script mapping relationships to adapt to the database script mapping of the environment. The configuration information required for the first mapping relationship is shown in Table 3:
[0053] Table 3
[0054]
[0055] The second mapping relationship mainly describes the mapping relationship between the original database script and the physical database script. The name of the original database script is consistent with the name of the original database script in the first mapping relationship, and the name of the physical database script is consistent with the database key (without prefix) in the configuration center. The information of the second mapping relationship is shown in Table 4:
[0056] Table 4
[0057]
[0058] In one optional embodiment, the record table further includes a database connection string, username, and password. Sending the record table to the resource path of the database includes: establishing a connection channel between the database physical script and the resource path of the database based on the database connection string, username, and password; and sending the record table to the resource path of the database through this connection channel. The connection between the database physical script and the database resource path can be established using the database connection string, username, and password, and can be obtained from the configuration center, containing information such as the database connection string, username, password, and whether encryption is enabled.
[0059] In one specific embodiment, a record table is generated based on the first mapping relationship and the second mapping relationship described above, as shown in Table 5:
[0060] Table 5
[0061]
[0062] In another alternative approach, at least the aforementioned record table is sent to the aforementioned resource path of the aforementioned database, including: sending the aforementioned record table to the aforementioned resource path of the aforementioned database, and determining whether the name of the aforementioned record table corresponding to the aforementioned database physical script is consistent with the name of the aforementioned record table in the aforementioned database; if the name of the aforementioned record table corresponding to the aforementioned database physical script is consistent with the name of the aforementioned record table in the aforementioned database, the aforementioned database physical script is not sent; if the name of the aforementioned record table corresponding to the aforementioned database physical script is inconsistent with the name of the aforementioned record table in the aforementioned database, the aforementioned database physical script is sent to the database corresponding to the aforementioned target environment. Since the original database script provided in the resource file is a full set of database logic scripts, pushing all database script files in the file directory during each upgrade would reduce efficiency and consume a large amount of space. Therefore, the aforementioned record table is sent to the aforementioned resource path of the aforementioned database, and if the name of the aforementioned record table corresponding to the aforementioned database physical script is consistent with the name of the aforementioned record table in the aforementioned database, the aforementioned database physical script is not sent; if the name of the aforementioned record table corresponding to the aforementioned database physical script is inconsistent with the name of the aforementioned record table in the aforementioned database, the aforementioned database physical script is sent to the database corresponding to the aforementioned target environment, thereby achieving the purpose of incremental push.
[0063] Through the above embodiments, this method automatically generates a database physical script adapted to the target environment by obtaining the original database script and configuration information, and sends it to the database corresponding to the target environment, thereby reducing manual maintenance costs and improving the efficiency of database physical script generation. This solves the problem of low generation efficiency caused by the need for a large amount of manual maintenance of database physical scripts in the prior art.
[0064] To enable those skilled in the art to better understand the technical solution of this application, the implementation process of the database physical script generation method of this application will be described in detail below with reference to specific embodiments.
[0065] This embodiment relates to a specific method for generating database physical scripts, such as... Figure 3 As shown, it includes the following steps:
[0066] Step S1: Obtain the original database script and configuration information;
[0067] Step S2: Process the original database script according to the configuration information to obtain the database physical script;
[0068] Step S3: Obtain the first mapping relationship and the second mapping relationship;
[0069] Step S4: Generate a record table based on the first mapping relationship and the second mapping relationship, and at least send the record table to the resource path of the database;
[0070] Step S5: Determine whether the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database;
[0071] Step S6: If the name of the record table corresponding to the database physical script is the same as the name of the record table in the database, do not send the database physical script;
[0072] Step S7: If the name of the record table corresponding to the database physical script is inconsistent with the name of the record table in the database, send the database physical script to the database corresponding to the target environment.
[0073] It should be noted that the steps shown in the flowchart in 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 may be executed in a different order than that shown here.
[0074] This application also provides a database physical script generation apparatus. It should be noted that the database physical script generation apparatus of this application can be used to execute the database physical script generation method provided in this application. This apparatus is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0075] The following describes the database physical script generation apparatus provided in the embodiments of this application.
[0076] Figure 4 This is a schematic diagram of a database physical script generation apparatus according to an embodiment of this application. Figure 4 As shown, the device includes an acquisition unit 10, a processing unit 20, and a transmission unit 30, wherein:
[0077] The aforementioned acquisition unit 10 is used to acquire the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables.
[0078] Specifically, as the amount of customer data in the distributed database of a bank increases, the QPS (Queries Per Second) of database queries also increases, leading to more and more database read and write times. Generally, database sharding and table partitioning are used to improve database performance and enhance availability. In development, testing, and production environments, the required unit strategies, sharding strategies, and database sharding and table partitioning strategies differ from environment to environment. The above configuration information can be used to obtain the unit strategies, sharding strategies, and database sharding and table partitioning strategies for the target environment.
[0079] In practical applications, the aforementioned unit allocation information is primarily stored in the system-level configuration of each system configuration center. The aforementioned database sharding and table partitioning configuration rules, as well as the aforementioned original database scripts, can be obtained from the resource packages provided by the application. The original database scripts contain database table creation statements, sharding data, etc., but do not contain any database sharding or table partitioning information. If the table is neither sharded nor partitioned, then this database script can be directly pushed to the database and stored in the resource file db directory.
[0080] In one optional scheme, the above-mentioned database sharding and table partitioning configuration rules shall at least include: sharding algorithm, specific sharding algorithm method, sharding fields, sharding table fields, and sharding table names. The database sharding and table partitioning configuration rules are mainly provided by the business provider and stored in the SDK (Software Development Kit) resource package. Their main function is to provide data access layer sharding table rules and physical database script generation for service users. The main attributes are shown in Table 6.
[0081] Table 6
[0082]
[0083]
[0084] Furthermore, the above table partitioning algorithms include at least one of the following: noShard algorithm, cust algorithm, date algorithm, and the Quartz database physical script generation algorithm. Based on business needs, table partitioning algorithms are mainly divided into noShard, cust, date, and Quartz algorithms, as mainly described in Table 7:
[0085] Table 7
[0086]
[0087]
[0088] The processing unit 20 is used to process the original database script according to the configuration information to obtain the database physical script;
[0089] Specifically, the database physical script is generated based on the original database script in the resource package, the database sharding and table partitioning configuration rules, and the system's unit sharding information; that is, the script that is actually executed on the database.
[0090] In one optional embodiment, the processing unit includes a first processing module and a second processing module. The first processing module is used to perform unit-sharding, database-sharding, and table-sharding operations on the original database script according to the unit sharding information. The second processing module is used to process the original database script after the unit-sharding, database-sharding, and table-sharding operations according to the database-sharding and table-sharding configuration rules to obtain the physical database script.
[0091] The aforementioned sending unit 30 is used to send the aforementioned database physical script to the database corresponding to the aforementioned target environment.
[0092] Specifically, in the database script push phase, the main task is to push the generated physical library script to the database of the corresponding environment.
[0093] Since the number of units, database sharding, and table sharding information vary in different environments, the resources of the database scripts to be pushed also differ. To push the generated database physical scripts to the database more quickly and accurately, in one optional solution, the sending unit includes an acquisition module, a generation module, and a sending module. The acquisition module acquires a first mapping relationship and a second mapping relationship. The first mapping relationship is the mapping between a resource path and the original database script, and the second mapping relationship is the mapping between the original database script and the database physical script. The resource path is the address of the database. The generation module generates a record table based on the first and second mapping relationships. The record table includes at least the name of the original database script, the name of the corresponding database physical script, the corresponding resource path, and the name of the record table. The sending module sends the record table to at least the resource path of the database.
[0094] Specifically, the first mapping relationship mainly describes the mapping relationship between resource paths and original database scripts. Although the number of units, database sharding, and table sharding information vary across environments, the resources that each system needs to push are almost the same, unless a new resource directory requires a new mapping relationship. Therefore, we template the database script mapping, and only need to manage and maintain a limited number of database script mapping relationships to adapt to the database script mapping of the environment. The configuration information required for the first mapping relationship is shown in Table 8:
[0095] Table 8
[0096]
[0097] The second mapping relationship mainly describes the mapping relationship between the original database script and the physical database script. The name of the original database script is consistent with the name of the original database script in the first mapping relationship, and the name of the physical database script is consistent with the database key (without prefix) in the configuration center. The information of the second mapping relationship is shown in Table 9:
[0098] Table 9
[0099]
[0100] In one optional embodiment, the record table further includes a database connection string, a username, and a password. The sending module includes an establishment submodule and a first sending submodule. The establishment submodule is used to establish a connection channel between the database physical script and the resource path of the database based on the database connection string, the username, and the password. The first sending submodule is used to send the record table to at least the resource path of the database through the connection channel. The connection between the database physical script and the database resource path can be established using the database connection string, username, and password, which can be obtained from the configuration center and includes information such as the database connection string, username, password, and whether encryption is enabled.
[0101] In one specific embodiment, a record table is generated based on the first mapping relationship and the second mapping relationship described above, as shown in Table 10:
[0102] Table 10
[0103]
[0104] In another alternative embodiment, the sending module includes a determining submodule, a second sending submodule, and a third sending submodule. The determining submodule sends the record table to the resource path of the database and determines whether the name of the record table corresponding to the database physical script matches the name of the record table in the database. The second sending submodule does not send the database physical script if the name of the record table corresponding to the database physical script matches the name of the record table in the database. The third sending submodule sends the database physical script to the database corresponding to the target environment if the name of the record table corresponding to the database physical script does not match the name of the record table in the database. Since the original database scripts provided in the resource files are full database logic scripts, pushing all database script files in the file directory during each upgrade would reduce efficiency and consume a lot of space. Therefore, the above record tables are sent to the above resource path of the above database. If the name of the record table corresponding to the above physical script is the same as the name of the record table in the above database, the above physical script is not sent. If the name of the record table corresponding to the above physical script is different from the name of the record table in the above database, the above physical script is sent to the database corresponding to the above target environment. This is done in a sequential manner to achieve the purpose of incremental push.
[0105] Through the above embodiments, the device automatically generates a database physical script adapted to the target environment by acquiring the original database script and configuration information, and sends it to the database corresponding to the target environment, thereby reducing manual maintenance costs and improving the efficiency of database physical script generation. This solves the problem of low generation efficiency caused by the need for a large amount of manual maintenance of database physical scripts in the prior art.
[0106] The aforementioned database physical script generation device includes a processor and a memory. The aforementioned acquisition unit, processing unit, and sending unit are all stored as program units in the memory, and the processor executes the aforementioned program units stored in the memory to achieve the corresponding functions. All of the aforementioned modules are located in the same processor; alternatively, the aforementioned modules may be located in different processors in any combination.
[0107] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the problem of low generation efficiency caused by the need for extensive manual maintenance of database physical scripts in existing technologies.
[0108] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0109] This invention provides a computer-readable storage medium, which includes a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute the method for generating the database physical script.
[0110] Specifically, the methods for generating database physical scripts include:
[0111] Step S201: Obtain the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables.
[0112] Specifically, as the amount of customer data in the distributed database of a bank increases, the QPS (Queries Per Second) of database queries also increases, leading to more and more database read and write times. Generally, database sharding and table partitioning are used to improve database performance and enhance availability. In development, testing, and production environments, the required unit strategies, sharding strategies, and database sharding and table partitioning strategies differ from environment to environment. The above configuration information can be used to obtain the unit strategies, sharding strategies, and database sharding and table partitioning strategies for the target environment.
[0113] Step S202: Process the original database script according to the above configuration information to obtain the database physical script;
[0114] Specifically, the database physical script is generated based on the original database script in the resource package, the database sharding and table partitioning configuration rules, and the system's unit sharding information; that is, the script that is actually executed on the database.
[0115] Step S203: Send the above-mentioned database physical script to the database corresponding to the target environment.
[0116] Specifically, in the database script push phase, the main task is to push the generated physical library script to the database of the corresponding environment.
[0117] Optionally, sending the aforementioned database physical script to the database corresponding to the target environment includes: obtaining a first mapping relationship and a second mapping relationship, wherein the first mapping relationship is a mapping relationship between a resource path and the aforementioned original database script, and the second mapping relationship is a mapping relationship between the aforementioned original database script and the aforementioned database physical script, and the aforementioned resource path is the address of the aforementioned database; generating a record table based on the aforementioned first mapping relationship and the aforementioned second mapping relationship, wherein the record table includes at least the name of the aforementioned original database script, the name of the corresponding aforementioned database physical script, the corresponding aforementioned resource path, and the name of the aforementioned record table; and sending the aforementioned record table to at least the aforementioned resource path of the aforementioned database.
[0118] Optionally, sending the record table to at least the resource path of the database includes: sending the record table to the resource path of the database, and determining whether the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database; if the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database, not sending the database physical script; if the name of the record table corresponding to the database physical script is inconsistent with the name of the record table in the database, sending the database physical script to the database corresponding to the target environment.
[0119] Optionally, the record table further includes a database connection string, a username, and a password. Sending the record table to the resource path of the database includes: establishing a connection channel between the database physical script and the resource path of the database based on the database connection string, the username, and the password; and sending the record table to the resource path of the database through the connection channel.
[0120] Optionally, the original database script is processed according to the above configuration information to obtain the database physical script, including: performing unit-sharding, database-sharding, and table-sharding operations on the original database script according to the above unit-sharding information; and processing the original database script after the above unit-sharding, database-sharding, and table-sharding operations according to the above database-sharding and table-sharding configuration rules to obtain the above database physical script.
[0121] Optionally, the above database sharding and table partitioning configuration rules shall include at least: the partitioning algorithm, the specific method of the partitioning algorithm, the fields of the partitioned database, the fields of the partitioned table, and the name of the partitioned table.
[0122] Optionally, the above table partitioning algorithms include at least one of the following: noShard algorithm, cust algorithm, date algorithm, and the quart database physical script generation algorithm.
[0123] This invention provides a processor for running a program, wherein the program executes the method for generating the database physical script.
[0124] Specifically, the methods for generating database physical scripts include:
[0125] Step S201: Obtain the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables.
[0126] Specifically, as the amount of customer data in the distributed database of a bank increases, the QPS (Queries Per Second) of database queries also increases, leading to more and more database read and write times. Generally, database sharding and table partitioning are used to improve database performance and enhance availability. In development, testing, and production environments, the required unit strategies, sharding strategies, and database sharding and table partitioning strategies differ from environment to environment. The above configuration information can be used to obtain the unit strategies, sharding strategies, and database sharding and table partitioning strategies for the target environment.
[0127] Step S202: Process the original database script according to the above configuration information to obtain the database physical script;
[0128] Specifically, the database physical script is generated based on the original database script in the resource package, the database sharding and table partitioning configuration rules, and the system's unit sharding information; that is, the script that is actually executed on the database.
[0129] Step S203: Send the above-mentioned database physical script to the database corresponding to the target environment.
[0130] Specifically, in the database script push phase, the main task is to push the generated physical library script to the database of the corresponding environment.
[0131] Optionally, sending the aforementioned database physical script to the database corresponding to the target environment includes: obtaining a first mapping relationship and a second mapping relationship, wherein the first mapping relationship is a mapping relationship between a resource path and the aforementioned original database script, and the second mapping relationship is a mapping relationship between the aforementioned original database script and the aforementioned database physical script, and the aforementioned resource path is the address of the aforementioned database; generating a record table based on the aforementioned first mapping relationship and the aforementioned second mapping relationship, wherein the record table includes at least the name of the aforementioned original database script, the name of the corresponding aforementioned database physical script, the corresponding aforementioned resource path, and the name of the aforementioned record table; and sending the aforementioned record table to at least the aforementioned resource path of the aforementioned database.
[0132] Optionally, sending the record table to at least the resource path of the database includes: sending the record table to the resource path of the database, and determining whether the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database; if the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database, not sending the database physical script; if the name of the record table corresponding to the database physical script is inconsistent with the name of the record table in the database, sending the database physical script to the database corresponding to the target environment.
[0133] Optionally, the record table further includes a database connection string, a username, and a password. Sending the record table to the resource path of the database includes: establishing a connection channel between the database physical script and the resource path of the database based on the database connection string, the username, and the password; and sending the record table to the resource path of the database through the connection channel.
[0134] Optionally, the original database script is processed according to the above configuration information to obtain the database physical script, including: performing unit-sharding, database-sharding, and table-sharding operations on the original database script according to the above unit-sharding information; and processing the original database script after the above unit-sharding, database-sharding, and table-sharding operations according to the above database-sharding and table-sharding configuration rules to obtain the above database physical script.
[0135] Optionally, the above database sharding and table partitioning configuration rules shall include at least: the partitioning algorithm, the specific method of the partitioning algorithm, the fields of the partitioned database, the fields of the partitioned table, and the name of the partitioned table.
[0136] Optionally, the above table partitioning algorithms include at least one of the following: noShard algorithm, cust algorithm, date algorithm, and the quart database physical script generation algorithm.
[0137] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0138] Step S201: Obtain the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables.
[0139] Step S202: Process the original database script according to the above configuration information to obtain the database physical script;
[0140] Step S203: Send the above-mentioned database physical script to the database corresponding to the target environment.
[0141] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0142] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0143] Step S201: Obtain the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables.
[0144] Step S202: Process the original database script according to the above configuration information to obtain the database physical script;
[0145] Step S203: Send the above-mentioned database physical script to the database corresponding to the target environment.
[0146] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0147] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0148] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0149] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0150] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0151] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0152] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0153] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0154] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0155] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0156] 1) In the database physical script generation method of this application, firstly, the original database script and configuration information are obtained. The configuration information includes unit sharding information and database sharding configuration rules for the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables. Then, the original database script is processed according to the configuration information to obtain the database physical script. Finally, the database physical script is sent to the database corresponding to the target environment. This method automatically generates a database physical script adapted to the target environment by obtaining the original database script and configuration information, and sends it to the database corresponding to the target environment, thereby reducing manual maintenance costs, improving the efficiency of database physical script generation, and solving the problem of low generation efficiency caused by the need for extensive manual maintenance of database physical scripts in the prior art.
[0157] 2) The database physical script generation apparatus of this application includes an acquisition unit, a processing unit, and a sending unit. The acquisition unit acquires an original database script and configuration information. The configuration information includes unit sharding information and database sharding / table partitioning configuration rules for the target environment. The unit sharding information represents the correspondence between units, databases, and tables. The processing unit processes the original database script according to the configuration information to obtain a database physical script. The sending unit sends the database physical script to the database corresponding to the target environment. This device automatically generates a physical database script adapted to the target environment by acquiring the original database script and configuration information, and sends it to the database corresponding to the target environment. This reduces manual maintenance costs and improves the efficiency of physical database generation, thereby solving the problem of low generation efficiency caused by the need for extensive manual maintenance of physical database scripts in existing technologies.
[0158] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for generating a database physical script, characterized in that, include: Obtain the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables. The original database script is processed according to the configuration information to obtain the database physical script; Send the database physical script to the database corresponding to the target environment; Sending the database physical script to the database corresponding to the target environment includes: Obtain a first mapping relationship and a second mapping relationship. The first mapping relationship is the mapping relationship between the resource path and the original database script. The second mapping relationship is the mapping relationship between the original database script and the database physical script. The resource path is the address of the database. Based on the first mapping relationship and the second mapping relationship, a record table is generated. The record table includes at least the name of the original database script, the name of the corresponding database physical script, the corresponding resource path, and the name of the record table. The record table must be sent to the resource path of the database at least once; The step of sending at least the record table to the resource path of the database includes: Send the record table to the resource path of the database, and determine whether the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database; If the name of the record table corresponding to the database physical script is the same as the name of the record table in the database, the database physical script will not be sent. If the name of the record table corresponding to the database physical script is inconsistent with the name of the record table in the database, the database physical script is sent to the database corresponding to the target environment.
2. The method according to claim 1, characterized in that, The record table also includes a database connection string, username, and password. Sending the record table to the resource path of the database includes at least: Based on the database connection string, the username, and the password, establish a connection channel between the database physical script and the resource path of the database; The record table is sent to the resource path of the database at least through the connection channel.
3. The method according to claim 1, characterized in that, The original database script is processed according to the configuration information to obtain the database physical script, including: Based on the unit sharding information, the original database script is divided into units, databases, and tables. The original database script, after undergoing the unit, database, and table partitioning operations, is processed according to the database partitioning and table partitioning configuration rules to obtain the database physical script.
4. The method according to claim 1, characterized in that, The database sharding and table partitioning configuration rules shall include at least the following: sharding algorithm, specific sharding algorithm method, sharding fields, sharding table fields, and sharding table name.
5. The method according to claim 4, characterized in that, The table partitioning algorithm includes at least one of the following: noShard algorithm, cust algorithm, date algorithm, and the quart database physical script generation algorithm.
6. A database physical script generation apparatus, characterized in that, include: The acquisition unit is used to acquire the original database script and configuration information. The configuration information includes the unit sharding information and database sharding configuration rules of the target environment. The unit sharding information is used to represent the correspondence between units, databases, and tables. The processing unit is used to process the original database script according to the configuration information to obtain the database physical script; The sending unit is used to send the database physical script to the database corresponding to the target environment; The transmitting unit includes: The acquisition module is used to acquire a first mapping relationship and a second mapping relationship. The first mapping relationship is the mapping relationship between the resource path and the original database script, and the second mapping relationship is the mapping relationship between the original database script and the database physical script. The resource path is the address of the database. The generation module is used to generate a record table based on the first mapping relationship and the second mapping relationship. The record table includes at least the name of the original database script, the name of the corresponding database physical script, the corresponding resource path, and the name of the record table. A sending module is configured to send the record table to at least the resource path of the database; The sending module includes: The determination submodule is used to send the record table to the resource path of the database and determine whether the name of the record table corresponding to the database physical script is consistent with the name of the record table in the database; The second sending submodule is configured to not send the database physical script if the name of the record table corresponding to the database physical script is the same as the name of the record table in the database. The third sending submodule is used to send the database physical script to the database corresponding to the target environment when the name of the record table corresponding to the database physical script is inconsistent with the name of the record table in the database.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to execute the database physical script generation method according to any one of claims 1 to 5.
8. A processor, characterized in that, The processor is used to run a program, wherein the program executes the database physical script generation method according to any one of claims 1 to 5 when it runs.
9. An electronic device, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including a method for generating a database physical script according to any one of claims 1 to 5.
Citation Information
Patent Citations
Database script generation method, device, computing device, and storage medium
CN109408528A
Data script generation method and device
CN114168122A