Application program SQL script processing method and device, processor and electronic equipment
By executing initialization and upgrade SQL scripts when the application starts, the database deployment process is separated, and SQL script versions are managed using configuration files. This solves the problem of maintaining SQL scripts across multiple subsystems and versions, and improves the efficiency of developers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-12
- Publication Date
- 2026-04-07
AI Technical Summary
During application software development, multiple subsystems and different versions of applications generate a large number of database upgrade SQL scripts, making it difficult for developers to maintain application-related upgrade SQL scripts and resulting in low work efficiency.
By executing the initialization SQL script after the application starts, obtaining the configuration file, recording the upgrade SQL script version information at each startup, and executing the upgrade SQL script according to the configuration file, the initialization and upgrade processes are separated, and the configuration file is used to maintain the SQL scripts of the developers.
It reduces the maintenance cost for developers to maintain SQL scripts for multiple subsystems, improves work efficiency, and enables flexible SQL script management.
Smart Images

Figure CN116049207B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer software technology, and more specifically, to an application SQL script processing method, apparatus, processor, and electronic device. Background Technology
[0002] Currently, when using SQL scripts written in database management languages, Flyway software is often used to maintain the SQL scripts for applications. However, when an application has multiple subsystems and versions, each subsystem version generates a large number of SQL scripts. This causes the workload for developers maintaining the application's SQL scripts using Flyway software to increase linearly, consuming significant time and effort and resulting in low efficiency. Furthermore, because Flyway software automatically updates database table structures and data through incremental SQL scripts, different SQL scripts may contain SQL scripts from different application versions. This means developers may need to traverse all SQL scripts to maintain the application's SQL scripts, further reducing their efficiency. Additionally, when multiple developers collaborate on an application, the same SQL script is typically used for development and modification to ensure compatibility. However, Flyway software cannot repeatedly execute modified SQL scripts, failing to meet developers' needs and further reducing their efficiency.
[0003] There is currently no effective solution to the problem that a large number of database upgrade SQL scripts containing different subsystems or different versions of applications are generated during the application software development process, making it difficult for developers to maintain application-related upgrade SQL scripts. Summary of the Invention
[0004] The main objective of this application is to provide an application SQL script processing method, apparatus, processor, and electronic device to solve the problem in the related art where a large number of database upgrade SQL scripts containing different subsystems or different versions of applications are generated during the application software development process, making it difficult for developers to maintain application-related upgrade SQL scripts.
[0005] To achieve the above objectives, according to one aspect of this application, an application SQL script processing method is provided. The method includes: after the application starts, executing an initialization SQL script on the application to obtain a configuration file of the application, wherein the configuration file is used to record version information of an upgrade SQL script executed each time the application starts; executing the upgrade SQL script on the application according to the configuration file and obtaining version information of the upgrade SQL script; obtaining an updated configuration file based on the version information of the upgrade SQL script; and upon detecting the next startup of the application, executing the upgrade SQL script corresponding to the application according to the updated configuration file.
[0006] Furthermore, after the application starts, executing an initialization SQL script on the application to obtain the application's configuration file includes: determining whether the configuration file exists; if the configuration file does not exist, executing the initialization SQL script on at least one subsystem of the application to obtain the configuration file; if the configuration file exists, obtaining the existing configuration file.
[0007] Furthermore, before executing the initialization SQL script on the application and obtaining the application's configuration file after the application starts, the method further includes: configuring a first file location and a second file location for the application, wherein the first file location is used to store the initialization SQL script for at least one subsystem of the application, and the second file location is used to store the upgrade SQL script for the application; configuring the application's current version information and development version information, wherein the current version information includes the application version information that has been released and launched, and the development version information is the development version information of the application in the development code stage.
[0008] Further, if the configuration file does not exist, executing the initialization SQL script on at least one subsystem of the application to obtain the configuration file includes: searching for the initialization SQL script of at least one subsystem at the first file location using the class loader; executing the initialization SQL script at the first file location to obtain the current version information of the initialization SQL script; and obtaining the configuration file based on the current version information.
[0009] Further, executing the upgrade SQL script on the application according to the configuration file and obtaining the version information of the upgrade SQL script includes: determining whether a target SQL script exists according to the configuration file, wherein the target SQL script refers to the upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file; if the target SQL script exists in the second file location, then executing the target SQL script on the application and obtaining the version information of the upgrade SQL script according to the latest version information of the target SQL script; if the target SQL script does not exist in the second file location, then executing the target SQL script on the application according to the configuration file and the development version information.
[0010] Further, if the target SQL script does not exist in the second file location, executing the target SQL script on the application based on the configuration file and the development version information includes: if the target SQL script does not exist in the second file location, determining whether the development version information is empty; if the development version information is not empty, continuing to execute the upgrade SQL script corresponding to the highest version in the configuration file on the application; if the development version information is empty, no longer executing the SQL script on the application.
[0011] Furthermore, after obtaining the updated configuration file based on the version information of the upgrade SQL script, the method further includes: if a new version of the application is detected to have been released, obtaining the new version of the upgrade SQL script from the second file location; updating the new version of the upgrade SQL script to the initialization SQL script of the corresponding subsystem in the first file location, and setting the development version information to empty.
[0012] To achieve the above objectives, according to another aspect of this application, an application SQL script processing apparatus is provided. The apparatus includes: a first acquisition unit, configured to execute an initialization SQL script on the application after the application starts, and acquire a configuration file of the application, wherein the configuration file is used to record version information of an upgrade SQL script executed each time the application starts; a second acquisition unit, configured to execute the upgrade SQL script on the application according to the configuration file, and acquire version information of the upgrade SQL script; a third acquisition unit, configured to obtain an updated configuration file according to the version information of the upgrade SQL script; and an execution unit, configured to execute the upgrade SQL script corresponding to the application according to the updated configuration file when the application is detected to start again.
[0013] Further, the first acquisition unit includes: a first judgment subunit, used to determine whether the configuration file exists; a first acquisition subunit, used to execute the initialization SQL script on at least one subsystem of the application to obtain the configuration file if the configuration file does not exist; and a second acquisition subunit, used to acquire the existing configuration file if the configuration file exists.
[0014] Furthermore, the device further includes: a first configuration unit, configured to configure a first file location and a second file location of the application before executing an initialization SQL script on the application and obtaining the application's configuration file after the application starts, wherein the first file location is used to store the initialization SQL script of at least one subsystem of the application, and the second file location is used to store the upgrade SQL script of the application; and a second configuration unit, configured to configure the current version information and development version information of the application, wherein the current version information includes application version information that has been released and launched, and the development version information is the development version information of the application in the development code stage.
[0015] Further, the first acquisition subunit includes: a query module, used to search for the initialization SQL script of at least one subsystem at the first file location through a class loader; a first acquisition module, used to execute the initialization SQL script at the first file location and acquire the current version information of the initialization SQL script; and a second acquisition module, used to acquire the configuration file based on the current version information.
[0016] Further, the second acquisition unit includes: a second judgment subunit, configured to determine whether a target SQL script exists based on the configuration file, wherein the target SQL script refers to an upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file; a third acquisition subunit, configured to execute the target SQL script on the application if the target SQL script exists in the second file location, and obtain the version information of the upgrade SQL script based on the latest version information of the target SQL script; and an execution subunit, configured to execute the target SQL script on the application based on the configuration file and the development version information if the target SQL script does not exist in the second file location.
[0017] Furthermore, the execution subunit further includes: a first judgment module, configured to determine whether the development version information is empty if the target SQL script does not exist in the second file location; an execution module, configured to continue executing the upgrade SQL script corresponding to the highest version in the configuration file on the application if the development version information is not empty; and a second judgment module, configured to stop executing the SQL script on the application if the development version information is empty.
[0018] Furthermore, the device further includes: a fourth acquisition unit, configured to, after obtaining the updated configuration file based on the version information of the upgrade SQL script, if a new version of the application is detected to have been released, acquire the new version of the upgrade SQL script from the second file location; and an update unit, configured to update the new version of the upgrade SQL script into the initialization SQL script of the corresponding subsystem at the first file location, and set the development version information to empty.
[0019] To achieve the above objectives, according to one aspect of this application, a processor is provided for running a program, wherein the program executes the application SQL script processing method described in any of the above-described methods during runtime.
[0020] To achieve the above objectives, according to one aspect of this application, an electronic device is provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement any of the above-described application SQL script processing methods.
[0021] This application employs the following steps: after the application starts, an initialization SQL script is executed on the application to obtain the application's configuration file, wherein the configuration file records the version information of the upgrade SQL script executed each time the application starts; based on the configuration file, the upgrade SQL script is executed on the application, and the version information of the upgrade SQL script is obtained; based on the version information of the upgrade SQL script, an updated configuration file is obtained; upon detecting the next startup of the application, the upgrade SQL script corresponding to the application is executed based on the updated configuration file. This solves the problem in related technologies where, during application software development, a large number of database upgrade SQL scripts containing different subsystems or different versions of the application are generated, making it difficult for developers to maintain application-related upgrade SQL scripts. By separating the process of deploying the application database into the process of initializing the application and the process of upgrading the application, and maintaining the SQL scripts written by developers based on the configuration file, the maintenance cost for developers to maintain multiple SQL scripts corresponding to multiple subsystems of the application is reduced, further improving the efficiency of developers' work. Attached Figure Description
[0022] 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:
[0023] Figure 1 This is a flowchart of an application SQL script processing method provided according to an embodiment of this application;
[0024] Figure 2 This is an illustration of an optional application SQL script processing method provided according to an embodiment of this application. Figure 1 ;
[0025] Figure 3 This is an illustration of an optional application SQL script processing method provided according to an embodiment of this application. Figure 2 ;
[0026] Figure 4 This is an illustration of an optional application SQL script processing method provided according to an embodiment of this application. Figure 3 ;
[0027] Figure 5 This is an illustration of an optional application SQL script processing method provided according to an embodiment of this application. Figure 4 ;
[0028] Figure 6 This is an illustration of an optional application SQL script processing method provided according to an embodiment of this application. Figure 5 ;
[0029] Figure 7 This is an illustration of an optional application SQL script processing method provided according to an embodiment of this application. Figure 6 ;
[0030] Figure 8 This is a schematic diagram of an application SQL script processing device provided according to an embodiment of this application. Detailed Implementation
[0031] 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.
[0032] 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.
[0033] 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.
[0034] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0035] Database Migration: As customers raise different requirements for the application, developers need to continuously develop and improve the code that controls the application's operation. During the continuous development and improvement of an application, each modification made by the developers results in an iteration. When more functionality is needed, the next iteration is performed on the current version of the application. During application iterations, developers make corresponding modifications to the database's data structure, such as adding data tables, adding fields to data tables, modifying data tables, and modifying fields within data tables. Each change to the database is called a database migration.
[0036] Class Loader: A class loader is a loader that loads Java classes into the Java Virtual Machine (JVM). Unlike ordinary programs, Java programs (files with the ".class" extension) are not native executable programs. When a Java program is run, the JVM (Java Virtual Machine) is run first, and then Java classes are loaded into the JVM for execution. The code responsible for loading Java classes is called the class loader.
[0037] Flyway Software: Flyway is an open-source database version control software. It can manage and track database changes independently of the application. Furthermore, Flyway can automatically upgrade database versions without complex configuration. Additionally, database migrations can be written as SQL scripts, which can be run through Flyway to perform the migration.
[0038] Example 1
[0039] The present invention will now be described in conjunction with preferred implementation steps. Figure 1 This is a flowchart of the application SQL script processing method provided in the embodiments of this application, such as... Figure 1 As shown, the method includes the following steps:
[0040] Step S101: After the application starts, execute the initialization SQL script on the application and obtain the application's configuration file. The configuration file is used to record the version information of the upgrade SQL script executed each time the application starts.
[0041] When developers create an application, they need to continuously improve it as clients raise different requirements. During the application iteration process, developers need to use SQL scripts to modify the database's data structure and data multiple times, generating a large number of SQL scripts that modify the database. At the same time, the application may contain multiple subsystems, further increasing the number of SQL script files related to the application.
[0042] For example, SQL scripts generated during development, such as Figure 2 The above, Figure 2 The document contains three boxes, representing the SQL scripts generated after an application upgrade, from left to right: The leftmost box represents the first deployed application, containing SQL scripts for three subsystems corresponding to three application versions: V1.1_module1.sql, V1.2_module2.sql, and V1.3_module3.sql. V1.1_module1.sql represents the SQL script for subsystem 1 (module 1) of the V1.1 version application, V1.2_module2.sql represents the SQL script for subsystem 2 (module 2) of the V1.2 version application, and V1.3_module3.sql represents the SQL script for subsystem 3 (module 3) of the V1.3 version application. After one upgrade, the application corresponding to these three SQL scripts generates six SQL scripts; after two upgrades, it generates nine SQL scripts. These nine SQL scripts contain SQL scripts for different versions and modules. If developers need to query the SQL script for subsystem 3, they need to traverse all three files, resulting in inefficient querying.
[0043] In order to facilitate developers in maintaining application-related SQL scripts while switching the database to the version corresponding to the application, in this embodiment, when the application is first launched on an electronic device, the process of configuring the application database is divided into two processes: an initialization process and an upgrade process. The initialization process is responsible for switching the database to a stable online version, while the upgrade process is responsible for processing the database that has executed the initialization SQL script according to the actual situation to obtain the database required by the developers.
[0044] In this embodiment, to enable developers to maintain the SQL scripts of multiple subsystems of the application more flexibly and conveniently, the application needs to be initialized, that is, the initialization SQL scripts corresponding to multiple subsystems are executed on the application. After executing the initialization SQL scripts, configuration files are obtained from the initialization SQL scripts to facilitate subsequent upgrades to the database corresponding to the application.
[0045] Step S102: Based on the configuration file, execute the upgrade SQL script on the application and obtain the version information of the upgrade SQL script.
[0046] In this embodiment, in order to configure the corresponding database for the application and upgrade the database to the version required by the developers, it is necessary to continue to execute the upgrade SQL script on the application after initializing the application and obtain the version information of the upgrade SQL script.
[0047] Step S103: Obtain the updated configuration file based on the version information of the upgrade SQL script.
[0048] Step S104: When the application is detected to be launching again, execute the upgrade SQL script corresponding to the application based on the updated configuration file.
[0049] After upgrading the database to the version required by the developers, the configuration file needs to be modified in a timely manner so that when the application is restarted, the correct SQL scripts can be executed to process the database based on the updated configuration file.
[0050] In summary, the application SQL script processing method provided in this application embodiment, after the application starts, executes an initialization SQL script on the application to obtain the application's configuration file. The configuration file records the version information of the upgrade SQL script executed each time the application starts. Based on the configuration file, the application executes the upgrade SQL script and obtains its version information. An updated configuration file is obtained based on the upgrade SQL script's version information. When the application is detected to start again, the corresponding upgrade SQL script is executed based on the updated configuration file. This solves the problem in related technologies where a large number of database upgrade SQL scripts containing different subsystems or different versions of the application are generated during application software development, making it difficult for developers to maintain application-related upgrade SQL scripts. By separating the application database deployment process into an application initialization process and an application upgrade process, and maintaining the SQL scripts written by developers based on the configuration file, the maintenance cost for developers to maintain SQL scripts corresponding to multiple subsystems of the application is reduced, further improving developer efficiency.
[0051] Optionally, in the application SQL script processing method provided in this application embodiment, after the application starts, executing an initialization SQL script on the application to obtain the application's configuration file includes: determining whether the configuration file exists; if the configuration file does not exist, executing an initialization SQL script on at least one subsystem of the application to obtain the configuration file; if the configuration file exists, obtaining the existing configuration file.
[0052] In this embodiment, in order to enable developers to clearly understand the initialization SQL scripts of at least one subsystem included in the application while switching the database to the version corresponding to the application, it is necessary to first switch the database to a stable, online version: First, it is determined whether the application has a configuration file; if the application does not have a configuration file, it is determined that the application has not yet completed the initialization process, and the database required to ensure the normal operation of the application does not exist. The application needs to be initialized, that is, the corresponding initialization SQL script is executed for at least one subsystem of the application, and the version information of the executed initialization SQL script is written into the configuration file to complete the application initialization process; if the application has a configuration file, it is determined that the application has completed the initialization process, and the existing configuration file is obtained so that the application upgrade process can be executed subsequently.
[0053] By executing multiple initialization SQL scripts to initialize at least one subsystem of the application, updating the current database to the database corresponding to the online version of the application, and obtaining configuration files based on the initialization SQL scripts, developers can clearly understand the database structure and specific data of multiple subsystems of the application, thereby reducing the maintenance cost for developers to maintain the SQL scripts corresponding to multiple subsystems of the application.
[0054] Optionally, in the application SQL script processing method provided in this application embodiment, before executing the initialization SQL script on the application and obtaining the application's configuration file after the application starts, the method further includes: configuring a first file location and a second file location of the application, wherein the first file location is used to store the initialization SQL script of at least one subsystem of the application, and the second file location is used to store the upgrade SQL script of the application; configuring the current version information and development version information of the application, wherein the current version information includes the application version information that has been released and launched, and the development version information is the development version information of the application in the development code stage.
[0055] To facilitate subsequent application initialization and upgrades, it is necessary to configure a first file location (i.e., the first file location) to store SQL scripts corresponding to at least one subsystem included in the application, a second file location (i.e., the second file location) to store SQL scripts corresponding to different versions of the application, and configuration information for the current and development versions of the application before initialization. For example, the file structures of the first and second file locations are as follows: Figure 3 As shown, the folder path for the first file location is resources / db / init, and the folder path for the second file location is resources / db / migration.
[0056] By configuring the first and second file locations of the application, as well as the current and development version information, it is beneficial to process the application subsequently. Based on the judgment results, the application can be initialized and upgraded, thereby reducing the maintenance cost of related SQL scripts for developers to maintain and develop the application, and thus improving the efficiency of developers in maintaining and developing the application.
[0057] Optionally, in the application SQL script processing method provided in this application embodiment, if the configuration file does not exist, the initialization SQL script is executed on at least one subsystem of the application to obtain the configuration file, which includes: searching for the initialization SQL script of at least one subsystem at the first file location through the class loader; executing the initialization SQL script at the first file location to obtain the current version information of the initialization SQL script; and obtaining the configuration file based on the current version information.
[0058] In the existing technology, when developing applications composed of multiple subsystems, incremental updates of SQL scripts are often used to maintain the SQL scripts generated during the development process. Furthermore, as the number of application iterations and the number of subsystems gradually increase, the number of SQL scripts related to the application will increase exponentially. At the same time, a single incremental update SQL script may contain SQL scripts from multiple iterations or multiple subsystems, making it difficult for developers to maintain the SQL scripts related to the application.
[0059] In this embodiment, to enable developers to conveniently maintain or develop SQL scripts for multiple subsystems related to the application, it is necessary to initialize and upgrade the database corresponding to the application. The initialization process for the database corresponding to the application is as follows: First, the class loader searches for at least one initialization SQL script corresponding to a subsystem in the first file location; then, the initialization SQL script corresponding to the at least one subsystem found in the first file location is executed to obtain the current version information of the initialization SQL script; then, based on the current version information, the configuration file is obtained. The contents of the configuration file are shown in Table 1, which contains version 0003 information corresponding to the initialization SQL script.
[0060] Table 1: Configuration files generated after application initialization
[0061] id version file md5 1 0003
[0062] By initializing an application containing multiple subsystems, and storing the application-related initialization SQL scripts in different files according to the subsystem corresponding to the initialization SQL script, developers can easily maintain or develop SQL scripts for multiple subsystems related to the application. This reduces the maintenance cost for developers to maintain and develop the application-related SQL scripts, thereby improving their work efficiency.
[0063] Optionally, in the application SQL script processing method provided in this application embodiment, executing an upgrade SQL script on the application according to the configuration file and obtaining the version information of the upgrade SQL script includes: determining whether a target SQL script exists according to the configuration file, wherein the target SQL script refers to an upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file; if a target SQL script exists in the second file location, then the target SQL script is executed on the application, and the version information of the upgrade SQL script is obtained according to the latest version information of the target SQL script. The version information obtained according to the upgrade SQL script is shown in Table 2. Table 2 contains the 0003 version information corresponding to the initialization SQL script and the 0004 version information corresponding to the upgrade SQL script. "U00045.4.0.sql" is the file name of the upgrade SQL script file, and "abcd5" is the MD5 checksum used to verify the file; if the target SQL script does not exist in the second file location, then the target SQL script is executed on the application according to the configuration file and the development version information.
[0064] Table 2: Version information corresponding to the upgrade SQL script
[0065] id version file md5 1 0003 2 0004 U0004_5.4.0.sql abcd5
[0066] In this embodiment, to facilitate developers in maintaining or developing SQL scripts for multiple subsystems related to the application, after initializing the database corresponding to the application, the database needs to undergo upgrade processing: First, it is determined whether a target SQL script exists in the second file location, and the version information of the target SQL script is higher than the latest version information recorded in the configuration file; if the target SQL script exists, it is determined that the current version of the database corresponding to the application is not the latest version required by the developers, and the target SQL script is executed on the database to obtain the version information of the upgrade SQL script; if the target SQL script does not exist, it is determined that the current version of the database corresponding to the application is already the latest version developed by the developers, and the application is processed according to the configuration file and development version information.
[0067] By reading the configuration file, it determines whether the target SQL script exists in the second file location. Based on the determination result, different processing is performed on the application, which achieves the effect of separating the application's initialization SQL script and upgrade SQL script. Furthermore, it can flexibly execute SQL scripts for the application according to the actual situation of the application, thereby improving the efficiency of developers in maintaining and developing application-related SQL scripts.
[0068] Optionally, in the application SQL script processing method provided in this application embodiment, if the target SQL script does not exist in the second file location, executing the target SQL script on the application based on the configuration file and development version information includes: if the target SQL script does not exist in the second file location, determining whether the development version information is empty; if the development version information is not empty, continuing to execute the upgrade SQL script corresponding to the highest version in the configuration file on the application; if the development version information is empty, no longer executing the SQL script on the application.
[0069] During the development phase, multiple developers may collaborate on modifying the database corresponding to the application. In this embodiment, to support multiple developers modifying SQL scripts during development and ensure that the modified SQL scripts are repeatedly executed each time the program starts, allowing for repeated testing or modification of the application's code, it's necessary to determine whether the application is in the development phase based on the configured development version information. If the development version information is not empty, the application is confirmed to be in the development phase, and the upgrade SQL script corresponding to the highest version in the configuration file is executed. If the development version information is empty, the application is confirmed not to be in the development phase, meaning the upgrade SQL script corresponding to the highest version in the configuration file has already been executed, so the SQL script is not executed again.
[0070] For example, a diagram illustrating the development of application version V4 by multiple developers is shown below. Figure 4 As shown, four developers are each responsible for the SQL update statements of a functional module. When the application is restarted during development, the V4.SQL script file will be executed repeatedly.
[0071] By setting a development mode for the application, it is possible to adaptively control whether to repeatedly execute the upgrade SQL script when the application starts, based on the specific development status of the developers, thereby improving the efficiency of the developers.
[0072] Optionally, in the application SQL script processing method provided in this application embodiment, after obtaining the updated configuration file based on the version information of the upgrade SQL script, the method further includes: if a new version of the application is detected to have been released, obtaining the new version of the upgrade SQL script in the second file location; updating the new version of the upgrade SQL script in the initialization SQL script of the corresponding subsystem in the first file location, and setting the development version information to empty.
[0073] To facilitate developers' management of upgrade SQL scripts for multiple subsystems and versions, after a new version of the application is released, the newly added upgrade SQL scripts for multiple subsystems in the new version need to be obtained first from the second file location. Then, these new upgrade SQL scripts are added to the corresponding initialization SQL scripts for each subsystem in the first file location, and the development version information is set to empty. For example, after releasing a new version 00005 and restarting the application, the updated configuration file is shown in Table 3. Restarting the application after releasing version 00005 will write the version information corresponding to version 00005 into the configuration file.
[0074] Table 3: Configuration file obtained after restarting the application in the new version.
[0075] id version file md5 1 0003 2 0004 U0004_5.4.0.sql abcd5 3 00005 U0005_5.5.0.sql abcd6
[0076] By adding the new upgrade SQL scripts for multiple subsystems in the new version of the application to the initialization SQL scripts for the corresponding subsystems in the first file location, developers can more clearly and intuitively manage the upgrade SQL scripts for multiple subsystems and versions. At the same time, by setting the development version information to empty after the application releases a new version, the upgrade SQL scripts are avoided from being repeatedly executed when the application is restarted after the new version is released. This reduces the cost for developers to maintain upgrade SQL scripts for multiple subsystems and versions of the application, and improves the efficiency of developers.
[0077] Optionally, in this embodiment, the existing process of maintaining incremental SQL scripts using Flyway software can be as follows: Figure 5 , Figure 6 and Figure 7 As shown, for example, the current version of the application has three SQL script files, such as... Figure 5 As shown, these are V1.sql, V2.sql, and V3.sql, respectively; then as follows... Figure 6 As shown, the Flyway software executes three SQL scripts, V1.sql, V2.sql, and V3.sql, sequentially after determining their execution status. After execution, it records the executed SQL scripts, their filenames, and their corresponding MD5 hashes in the data table. When a new version of the application is released, upgrading the SQL script to V4.sql, the Flyway software checks the latest version of the database. If the latest database version is V3, it will not execute the upgrade SQL script with a version lower than or equal to V3; instead, it will execute V4.sql and update the version information of V4.sql in the data table. Figure 7 As shown.
[0078] 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.
[0079] Example 2
[0080] This application also provides an application SQL script processing device. It should be noted that the application SQL script processing device of this application can be used to execute the application SQL script processing method provided in Embodiment 1 of this application. The application SQL script processing device provided in this application is described below.
[0081] Figure 8 This is a schematic diagram of an application SQL script processing apparatus according to an embodiment of this application. Figure 8 As shown, the device includes: a first acquisition unit 801, a second acquisition unit 802, a third acquisition unit 803, and an execution unit 804.
[0082] The first acquisition unit 801 is used to execute an initialization SQL script on the application after the application starts, and to obtain the application's configuration file. The configuration file is used to record the version information of the upgrade SQL script executed each time the application starts.
[0083] When developers create an application, they need to continuously improve it as customers make different demands. During application iterations, developers need to use SQL scripts to modify the database's data structure and data multiple times, generating a large number of SQL scripts that modify the database. Furthermore, the application may contain multiple subsystems, further increasing the number of application-related SQL script files. To facilitate the maintenance of application-related SQL scripts while switching the database to the application's version, this embodiment divides the application database configuration process into two steps when the application is first launched on an electronic device: an initialization process and an upgrade process. The initialization process switches the database to a stable, online version, while the upgrade process processes the database that has executed the initialization SQL scripts according to the actual situation to obtain the database required by the developers.
[0084] In this embodiment, to enable developers to maintain the SQL scripts of multiple subsystems of the application more flexibly and conveniently, the application needs to be initialized, that is, the initialization SQL scripts corresponding to multiple subsystems are executed on the application. After the initialization SQL scripts are executed, the configuration file is obtained from the initialization SQL scripts through the first acquisition unit 801, so as to facilitate subsequent upgrades to the database corresponding to the application.
[0085] The second acquisition unit 802 is used to execute an upgrade SQL script on the application according to the configuration file and obtain the version information of the upgrade SQL script.
[0086] In this embodiment, in order to configure the corresponding database for the application and upgrade the database to the database version required by the developers, it is necessary to continue to execute the upgrade SQL script on the application after initializing the application, and use the second acquisition unit 802 to obtain the version information of the upgrade SQL script.
[0087] The third acquisition unit 803 is used to obtain the updated configuration file based on the version information of the upgrade SQL script.
[0088] Execution unit 804 is used to execute the upgrade SQL script corresponding to the application based on the updated configuration file when the application is detected to be starting up again.
[0089] After upgrading the database to the version required by the developers, the modified configuration file needs to be obtained promptly using the third acquisition unit 803. This allows the correct SQL script to be executed by the execution unit 804 to process the database when the application is restarted, based on the updated configuration file.
[0090] In summary, the application SQL script processing apparatus provided in this application embodiment, through a first acquisition unit 801, is used to execute an initialization SQL script on the application after the application starts, and obtain the application's configuration file, wherein the configuration file is used to record the version information of the upgrade SQL script executed each time the application starts; a second acquisition unit 802 is used to execute the upgrade SQL script on the application according to the configuration file, and obtain the version information of the upgrade SQL script; a third acquisition unit 803 is used to obtain an updated configuration file according to the version information of the upgrade SQL script; and an execution unit 804 is used to execute the upgrade SQL script corresponding to the application according to the updated configuration file when the application is detected to start again. This solves the problem in related technologies where a large number of database upgrade SQL scripts containing different subsystems or different versions of the application are generated during the application software development process, making it difficult for developers to maintain upgrade SQL scripts related to the application. By separating the process of deploying the application database into the process of initializing the application and the process of upgrading the application, and maintaining the SQL scripts written by developers according to the configuration file, the maintenance cost for developers to maintain SQL scripts corresponding to multiple subsystems of the application is reduced, further improving the efficiency of developers.
[0091] Optionally, in the application SQL script processing device provided in the embodiments of this application, the first acquisition unit 801 includes: a first judgment subunit, used to determine whether a configuration file exists; a first acquisition subunit, used to execute an initialization SQL script on at least one subsystem of the application to obtain the configuration file if the configuration file does not exist; and a second acquisition subunit, used to acquire the existing configuration file if the configuration file exists.
[0092] In this embodiment, in order to enable developers to clearly understand the initialization SQL scripts of at least one subsystem included in the application while switching the database to the version corresponding to the application, it is necessary to first switch the database to a stable online version: First, the first judgment subunit determines whether the application has a configuration file; if the application does not have a configuration file, it is determined that the application has not completed the initialization process and the database required to ensure the normal operation of the application does not exist. The application needs to be initialized, that is, the corresponding initialization SQL script is executed for at least one subsystem of the application, and the version information of the executed initialization SQL script is written into the configuration file. The configuration file is obtained through the first acquisition subunit, and the application initialization process is completed; if the application has a configuration file, it is determined that the application has completed the initialization process. The second acquisition subunit is used to obtain the existing configuration file so that the application upgrade process can be executed later.
[0093] By executing multiple initialization SQL scripts to initialize at least one subsystem of the application, updating the current database to the database corresponding to the online version of the application, and obtaining configuration files based on the initialization SQL scripts, developers can clearly understand the database structure and specific data of multiple subsystems of the application, thereby reducing the maintenance cost for developers to maintain the SQL scripts corresponding to multiple subsystems of the application.
[0094] Optionally, in the application SQL script processing apparatus provided in the embodiments of this application, the apparatus further includes: a first configuration unit, configured to configure a first file location and a second file location of the application before executing an initialization SQL script on the application and obtaining the application's configuration file after the application starts, wherein the first file location is used to store the initialization SQL script of at least one subsystem of the application, and the second file location is used to store the upgrade SQL script of the application; and a second configuration unit, configured to configure the current version information and development version information of the application, wherein the current version information includes the application version information that has been released and launched, and the development version information is the development version information of the application in the development code stage.
[0095] To facilitate subsequent application initialization and upgrade processes, before initializing the application, the first configuration unit needs to be used to configure the SQL scripts corresponding to at least one subsystem contained in the application (i.e., the first file location), the SQL scripts corresponding to different versions of the application (i.e., the second file location), and the current version information and development version information of the application need to be configured.
[0096] By configuring the first and second file locations of the application, as well as the current and development version information, it is beneficial to process the application subsequently. Based on the judgment results, the application can be initialized and upgraded, thereby reducing the maintenance cost of related SQL scripts for developers to maintain and develop the application, and thus improving the efficiency of developers in maintaining and developing the application.
[0097] Optionally, in the application SQL script processing device provided in this application embodiment, the first acquisition subunit includes: a query module, used to search for the initialization SQL script of at least one subsystem at the first file location through a class loader; a first acquisition module, used to execute the initialization SQL script at the first file location and acquire the current version information of the initialization SQL script; and a second acquisition module, used to acquire the configuration file based on the current version information.
[0098] In the existing technology, when developing applications composed of multiple subsystems, incremental updates of SQL scripts are often used to maintain the SQL scripts generated during the development process. Furthermore, as the number of application iterations and the number of subsystems gradually increase, the number of SQL scripts related to the application will increase exponentially. At the same time, a single incremental update SQL script may contain SQL scripts from multiple iterations or multiple subsystems, making it difficult for developers to maintain the SQL scripts related to the application.
[0099] In this embodiment, to enable developers to conveniently maintain or develop SQL scripts for multiple subsystems related to the application, it is necessary to initialize and upgrade the database corresponding to the application. The initialization process for the database corresponding to the application is as follows: First, the query module uses the class loader to search for at least one initialization SQL script corresponding to a subsystem in the first file location; then, the initialization SQL script corresponding to the at least one subsystem found in the first file location is executed, and the current version information of the initialization SQL script is obtained through the first acquisition module; then, based on the current version information, the configuration file is obtained using the second acquisition module.
[0100] By initializing an application containing multiple subsystems, and storing the application-related initialization SQL scripts in different files according to the subsystem corresponding to the initialization SQL script, developers can easily maintain or develop SQL scripts for multiple subsystems related to the application. This reduces the maintenance cost for developers to maintain and develop the application-related SQL scripts, thereby improving their work efficiency.
[0101] Optionally, in the application SQL script processing apparatus provided in this application embodiment, the second acquisition unit 802 includes: a second determination subunit, used to determine whether a target SQL script exists based on a configuration file, wherein the target SQL script refers to an upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file; a third acquisition subunit, used to execute the target SQL script on the application if the target SQL script exists in the second file location, and obtain the version information of the upgrade SQL script based on the latest version information of the target SQL script; and an execution subunit, used to execute the target SQL script on the application based on the configuration file and development version information if the target SQL script does not exist in the second file location.
[0102] In this embodiment, to facilitate developers in maintaining or developing SQL scripts for multiple subsystems related to the application, after initializing the database corresponding to the application, the database needs to undergo upgrade processing: First, the second judgment subunit determines whether a target SQL script exists in the second file location, and the version information of the target SQL script is higher than the latest version information recorded in the configuration file; if the target SQL script exists, it is determined that the current version of the database corresponding to the application is not the latest version required by the developers, and the target SQL script continues to be executed on the database, while the third acquisition subunit obtains the version information of the upgrade SQL script; if the target SQL script does not exist, it is determined that the current version of the database corresponding to the application is already the latest version developed by the developers, and the application continues to be processed according to the configuration file and development version information through the execution subunit.
[0103] By reading the configuration file, it determines whether the target SQL script exists in the second file location. Based on the determination result, different processing is performed on the application, which achieves the effect of separating the application's initialization SQL script and upgrade SQL script. Furthermore, it can flexibly execute SQL scripts for the application according to the actual situation of the application, thereby improving the efficiency of developers in maintaining and developing application-related SQL scripts.
[0104] Optionally, in the application SQL script processing device provided in this application embodiment, the above-mentioned execution subunit further includes: a first judgment module, used to determine whether the development version information is empty if the target SQL script does not exist in the second file location; an execution module, used to continue executing the upgrade SQL script corresponding to the highest version in the configuration file for the application if the development version information is not empty; and a second judgment module, used to stop executing the SQL script for the application if the development version information is empty.
[0105] During the development phase, multiple developers may collaborate on modifying the database corresponding to the application. In this embodiment, to support multiple developers modifying SQL scripts during development and ensure that the modified SQL scripts are repeatedly executed each time the program starts, allowing for repeated testing or modification of the application's code, a first judgment module is used to determine whether the application is in the development phase based on the configured development version information. If the development version information is not empty, the application is confirmed to be in the development phase, and the execution module continues to execute the upgrade SQL script corresponding to the highest version in the configuration file. If the development version information is empty, a second judgment module confirms that the application is not in the development phase, meaning the upgrade SQL script corresponding to the highest version in the configuration file has already been executed, so no further SQL script execution is performed on the application.
[0106] By setting a development mode for the application, it is possible to adaptively control whether to repeatedly execute the upgrade SQL script when the application starts, based on the specific development status of the developers, thereby improving the efficiency of the developers.
[0107] Optionally, in the application SQL script processing apparatus provided in this application embodiment, the apparatus further includes: a fourth acquisition unit, configured to, after obtaining the updated configuration file based on the version information of the upgrade SQL script, if a new version of the application is detected to have been released, acquire the new version of the upgrade SQL script in the second file location; and an update unit, configured to update the new version of the upgrade SQL script into the initialization SQL script of the corresponding subsystem in the first file location, and set the development version information to empty.
[0108] To facilitate developers in managing upgrade SQL scripts for multiple subsystems and multiple versions, after a new version of the application is released, the upgrade SQL scripts added to the multiple subsystems in the new version need to be obtained first in the second file location through the fourth acquisition unit; then, through the update unit, the upgrade SQL scripts added to the multiple subsystems in the new version are added to the initialization SQL scripts corresponding to the multiple subsystems in the first file location, and the development version information is set to empty.
[0109] By adding the new upgrade SQL scripts for multiple subsystems in the new version of the application to the initialization SQL scripts for the corresponding subsystems in the first file location, developers can more clearly and intuitively manage the upgrade SQL scripts for multiple subsystems and versions. At the same time, by setting the development version information to empty after the application releases a new version, the upgrade SQL scripts are avoided from being repeatedly executed when the application is restarted after the new version is released. This reduces the cost for developers to maintain upgrade SQL scripts for multiple subsystems and versions of the application, and improves the efficiency of developers.
[0110] The application SQL script processing device includes a processor and a memory. The first acquisition unit 801, the second acquisition unit 802, the third acquisition unit 803, and the execution unit 804 are all stored in the memory as program units. The processor executes the program units stored in the memory to realize the corresponding functions.
[0111] 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 in related technologies where developers struggle to maintain application-related upgrade SQL scripts.
[0112] 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.
[0113] This invention provides a computer-readable storage medium storing a program that, when executed by a processor, implements the application's SQL script processing method.
[0114] This invention provides a processor for running a program, wherein the program executes the application's SQL script processing method during runtime.
[0115] This invention provides an electronic device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: after the application starts, it executes an initialization SQL script on the application to obtain the application's configuration file, wherein the configuration file is used to record the version information of the upgrade SQL script executed each time the application starts; according to the configuration file, it executes the upgrade SQL script on the application and obtains the version information of the upgrade SQL script; based on the version information of the upgrade SQL script, it obtains an updated configuration file; when the application is detected to start again, it executes the upgrade SQL script corresponding to the application according to the updated configuration file.
[0116] When the processor executes the program, it also performs the following steps: after the application starts, it executes an initialization SQL script on the application and obtains the application's configuration file, including: determining whether the configuration file exists; if the configuration file does not exist, it executes an initialization SQL script on at least one subsystem of the application to obtain the configuration file; if the configuration file exists, it obtains the existing configuration file.
[0117] When the processor executes the program, it also performs the following steps: After the application starts, before executing the initialization SQL script for the application and obtaining the application's configuration file, the above method further includes: configuring the application's first file location and second file location, wherein the first file location is used to store the initialization SQL script of at least one subsystem of the application, and the second file location is used to store the application's upgrade SQL script; configuring the application's current version information and development version information, wherein the current version information includes the application version information that has been released and launched, and the development version information is the development version information of the application that is in the development code stage.
[0118] When the processor executes the program, it also performs the following steps: if the configuration file does not exist, it executes an initialization SQL script for at least one subsystem of the application to obtain the configuration file, including: searching for the initialization SQL script of at least one subsystem in the first file location through the class loader; executing the initialization SQL script in the first file location to obtain the current version information of the initialization SQL script; and obtaining the configuration file based on the current version information.
[0119] When the processor executes the program, it also performs the following steps: Based on the configuration file, it executes the upgrade SQL script on the application and obtains the version information of the upgrade SQL script, including: based on the configuration file, determining whether a target SQL script exists, wherein the target SQL script refers to the upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file; if the target SQL script exists in the second file location, it executes the target SQL script on the application and obtains the version information of the upgrade SQL script based on the latest version information of the target SQL script; if the target SQL script does not exist in the second file location, it executes the target SQL script on the application based on the configuration file and the development version information.
[0120] When the processor executes the program, it also performs the following steps: If the target SQL script does not exist in the second file location, the target SQL script is executed on the application based on the configuration file and development version information, including: if the target SQL script does not exist in the second file location, it is determined whether the development version information is empty; if the development version information is not empty, the upgrade SQL script corresponding to the highest version in the configuration file is executed on the application; if the development version information is empty, the SQL script is no longer executed on the application.
[0121] When the processor executes the program, it also performs the following steps: After obtaining the updated configuration file based on the version information of the upgrade SQL script, the above method further includes: if a new version of the application is detected to have been released, the new version of the upgrade SQL script is obtained from the second file location; the new version of the upgrade SQL script is updated to the initialization SQL script of the corresponding subsystem in the first file location, and the development version information is set to empty.
[0122] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0123] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: after the application starts, executing an initialization SQL script on the application to obtain the application's configuration file, wherein the configuration file is used to record the version information of the upgrade SQL script executed each time the application starts; according to the configuration file, executing the upgrade SQL script on the application and obtaining the version information of the upgrade SQL script; obtaining the updated configuration file based on the version information of the upgrade SQL script; and upon detecting the next startup of the application, executing the upgrade SQL script corresponding to the application according to the updated configuration file.
[0124] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: after the application starts, execute an initialization SQL script on the application to obtain the application's configuration file, including: determining whether the configuration file exists; if the configuration file does not exist, execute an initialization SQL script on at least one subsystem of the application to obtain the configuration file; if the configuration file exists, obtain the existing configuration file.
[0125] When executed on a data processing device, it is also suitable to execute an initialization program with the following method steps: after the application starts, before executing the initialization SQL script for the application and obtaining the application's configuration file, the above method further includes: configuring a first file location and a second file location for the application, wherein the first file location is used to store the initialization SQL script for at least one subsystem of the application, and the second file location is used to store the upgrade SQL script for the application; configuring the current version information and development version information of the application, wherein the current version information includes the application version information that has been released and launched, and the development version information is the development version information of the application in the development code stage.
[0126] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: if the configuration file does not exist, execute an initialization SQL script for at least one subsystem of the application to obtain the configuration file, including: searching for the initialization SQL script of at least one subsystem at the first file location using the class loader; executing the initialization SQL script at the first file location to obtain the current version information of the initialization SQL script; and obtaining the configuration file based on the current version information.
[0127] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: Based on the configuration file, execute an upgrade SQL script on the application and obtain the version information of the upgrade SQL script, including: based on the configuration file, determining whether a target SQL script exists, wherein the target SQL script refers to an upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file; if the target SQL script exists in the second file location, execute the target SQL script on the application and obtain the version information of the upgrade SQL script based on the latest version information of the target SQL script; if the target SQL script does not exist in the second file location, execute the target SQL script on the application based on the configuration file and development version information.
[0128] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: If the target SQL script does not exist in the second file location, the target SQL script is executed on the application based on the configuration file and development version information, including: if the target SQL script does not exist in the second file location, it is determined whether the development version information is empty; if the development version information is not empty, the upgrade SQL script corresponding to the highest version in the configuration file is executed on the application; if the development version information is empty, the SQL script is no longer executed on the application.
[0129] When executed on a data processing device, it is also suitable to execute an initialization program with the following steps: after obtaining the updated configuration file based on the version information of the upgrade SQL script, the above method further includes: if a new version of the application is detected to have been released, obtaining the new version of the upgrade SQL script in the second file location; updating the new version of the upgrade SQL script in the initialization SQL script of the corresponding subsystem in the first file location, and setting the development version information to empty.
[0130] 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.
[0131] 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.
[0132] 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.
[0133] 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.
[0134] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0135] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0136] 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 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.
[0137] 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.
[0138] 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.
[0139] The above are merely embodiments of this application and are not intended to limit the scope of 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 scope of the claims of this application.
Claims
1. A method for processing SQL scripts in an application, characterized in that, include: After the application starts, an initialization SQL script is executed on the application to obtain the application's configuration file, wherein the configuration file is used to record the version information of the upgrade SQL script executed each time the application starts; Based on the configuration file, the upgrade SQL script is executed on the application, and the version information of the upgrade SQL script is obtained; Based on the version information of the upgrade SQL script, the updated configuration file is obtained; When the application is detected to be launching again, the upgrade SQL script corresponding to the application is executed according to the updated configuration file. According to the configuration file, executing the upgrade SQL script on the application and obtaining the version information of the upgrade SQL script includes: Based on the configuration file, it is determined whether a target SQL script exists. The target SQL script refers to the upgrade SQL script in the second file location whose version information is higher than the latest version information in the configuration file. The second file location is used to store the upgrade SQL script of the application. If the target SQL script exists in the second file location, the application executes the target SQL script, and the version information of the upgrade SQL script is obtained based on the latest version information of the target SQL script. If the target SQL script does not exist in the second file location, the target SQL script is executed on the application according to the configuration file and development version information, wherein the development version information is the development version information of the application in the development code stage; If the target SQL script does not exist in the second file location, then executing the target SQL script on the application based on the configuration file and the development version information includes: If the target SQL script does not exist in the second file location, then determine whether the development version information is empty; If the development version information is not empty, then continue to execute the upgrade SQL script corresponding to the highest version in the configuration file on the application; If the development version information is empty, the SQL script will no longer be executed on the application.
2. The method according to claim 1, characterized in that, After the application starts, an initialization SQL script is executed on the application to obtain the application's configuration file, including: Determine if the configuration file exists; If the configuration file does not exist, the initialization SQL script is executed on at least one subsystem of the application to obtain the configuration file; If the configuration file exists, then retrieve the existing configuration file.
3. The method according to claim 2, characterized in that, Before executing the initialization SQL script on the application after it starts and before obtaining the application's configuration file, the method further includes: Configure a first file location and a second file location for the application, wherein the first file location is used to store the initialization SQL script of at least one subsystem of the application; Configure the current version information and development version information of the application, wherein the current version information includes the application version information that has been released and launched.
4. The method according to claim 3, characterized in that, If the configuration file does not exist, the initialization SQL script is executed on at least one subsystem of the application to obtain the configuration file, which includes: The class loader locates the initialization SQL script of at least one subsystem at the first file location; Execute the initialization SQL script located in the first file location, and obtain the current version information of the initialization SQL script; Based on the current version information, obtain the configuration file.
5. The method according to claim 3, characterized in that, After obtaining the updated configuration file based on the version information of the upgrade SQL script, the method further includes: If a new version of the application is detected, the upgrade SQL script for the new version is obtained from the second file location; Update the new version of the upgrade SQL script to the initialization SQL script of the corresponding subsystem in the first file location, and set the development version information to empty.
6. An application SQL script processing device, characterized in that, include: The first acquisition unit is used to execute an initialization SQL script on the application after the application starts, and acquire the configuration file of the application, wherein the configuration file is used to record the version information of the upgrade SQL script executed each time the application starts; The second acquisition unit is used to execute the upgrade SQL script on the application according to the configuration file, and to acquire the version information of the upgrade SQL script; The third acquisition unit is used to obtain the updated configuration file based on the version information of the upgrade SQL script; An execution unit is configured to execute the upgrade SQL script corresponding to the application based on the updated configuration file when the application is detected to be launching again. The second acquisition unit includes: a second judgment subunit, used to determine whether a target SQL script exists based on a configuration file, wherein the target SQL script refers to an upgrade SQL script in a second file location whose version information is higher than the latest version information in the configuration file, and the second file location is used to store the upgrade SQL script of the application; a third acquisition subunit, used to execute the target SQL script on the application if the target SQL script exists in the second file location, and obtain the version information of the upgrade SQL script based on the latest version information of the target SQL script; and an execution subunit, used to execute the target SQL script on the application based on the configuration file and development version information if the target SQL script does not exist in the second file location, wherein the development version information is the development version information of the application in the development code stage. The execution subunit further includes: a first judgment module, used to determine whether the development version information is empty if the target SQL script does not exist in the second file location; an execution module, used to continue executing the upgrade SQL script corresponding to the highest version in the configuration file on the application if the development version information is not empty; and a second judgment module, used to stop executing the SQL script on the application if the development version information is empty.
7. A processor, characterized in that, The processor is used to run a program, wherein the program executes the application SQL script processing method according to any one of claims 1 to 5 when it runs.
8. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the application SQL script processing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method and system for upgrading widget system
CN101945135A
Database upgrading method based on data link
CN112068881A