CN115934682A - Database migration method and system - Google Patents

Database migration method and system Download PDF

Info

Publication number
CN115934682A
CN115934682A CN202211736134.0A CN202211736134A CN115934682A CN 115934682 A CN115934682 A CN 115934682A CN 202211736134 A CN202211736134 A CN 202211736134A CN 115934682 A CN115934682 A CN 115934682A
Authority
CN
China
Prior art keywords
database
migrated
source code
file
conversion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211736134.0A
Other languages
Chinese (zh)
Inventor
肖汉城
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tianyi Cloud Technology Co Ltd
Original Assignee
Tianyi Cloud Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tianyi Cloud Technology Co Ltd filed Critical Tianyi Cloud Technology Co Ltd
Priority to CN202211736134.0A priority Critical patent/CN115934682A/en
Publication of CN115934682A publication Critical patent/CN115934682A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a database migration method, which specifically comprises the following steps: the method comprises the steps of obtaining a source code path of a database to be migrated and a source code path of a migrated database, obtaining a type of the database to be migrated and a type of the migrated database at the same time, scanning and analyzing a source code of the database to be migrated, obtaining a configuration file of the database to be migrated, extracting database dependence, database connection configuration and SQL sentences according to the configuration file, loading a database adapter, inputting the database dependence, the database connection configuration and the SQL sentences into the database adapter for conversion, obtaining a conversion file, and filling the migrated database. The method can scan the source code of the database, extract SQL sentences for analysis, then give SQL adaptation and modification suggestions through the database adapter, finally generate an automatic conversion source code file and automatically perform database migration.

Description

Database migration method and system
Technical Field
The invention belongs to the technical field of database management, and particularly relates to a database migration method and a database migration system.
Background
Since the trade war, the information security is threatened due to the limitation of the development of IT technology in foreign countries, and the core requirements of enterprises are that the information creation is an important component of new infrastructure, the information security is threatened, the domestic software and hardware are vigorously developed, and the realization of the replacement is realized.
The industry of the letter creations is huge, and the domestic substitution of the basic software database is involved, such as: mySQL is migrated to a domestic dreams database and a human big gold warehouse database. For migration of database data, a localization database manufacturer provides a corresponding migration tool. But for the migration of database applications, manual searching is required to modify the corresponding code. The new database and the old database have differences in the aspects of grammar, keywords, functions, character codes, field types and the like, and a large amount of sql sentences in project codes need to be modified when migration is completed, so that the new database and the old database are complex and are easy to change and make mistakes.
Therefore, a database migration method is needed, which can assist or automatically complete the database migration and reduce the human resource occupation and migration risk during the database migration.
Disclosure of Invention
Based on the above disadvantages and shortcomings of the prior art, it is an object of the present invention to at least solve one or more of the above problems in the prior art, or to provide a database migration method and system that satisfies one or more of the above requirements.
In order to achieve the purpose, the invention adopts the following technical scheme:
in a first aspect, the present invention provides a database migration method, which specifically includes the following steps:
acquiring a source code path of a database to be migrated and a source code path of a migrated database, and simultaneously acquiring a type of the database to be migrated and a type of the migrated database;
scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated, and acquiring a configuration file of the database to be migrated;
extracting database dependence, database connection configuration and SQL statements according to the configuration file;
loading a database adapter according to the type of the database to be migrated and the type of the database after migration;
inputting the database dependence, the database connection configuration and the SQL statement into a database adapter for conversion to obtain a conversion file;
and filling the migrated database according to the conversion file and the source code path of the migrated database.
As a preferred embodiment, the method for filling the post-migration database according to the conversion file and the post-migration database source code path specifically includes the following steps:
acquiring an automatically converted source code according to the conversion file;
the post-migration database is populated with the automatically translated source code.
As a preferred embodiment, the method for filling the post-migration database according to the conversion file and the source code path of the post-migration database specifically includes the following steps:
inputting the database dependence, the database connection configuration and the SQL statement into a database adapter for conversion to obtain a conversion file;
and outputting the conversion file to a specified conversion file output path.
As a further preferred embodiment, when inputting database dependence, database connection configuration, and SQL statement into the database adapter for conversion, the SQL statement that cannot be converted is marked and a log file is generated;
and when the conversion file is output to the specified conversion file output path, the log file is also output to the specified conversion file output path.
As a further preferred embodiment, when the source code path of the database to be migrated and the source code path of the database after migration are obtained, the output path of the conversion file is also obtained at the same time.
As a preferred embodiment, the database dependency, the database connection configuration, and the SQL statement are input into the database adapter for conversion, specifically, the matching conversion is performed on the double quotation marks, the single quotation marks, the keywords, and the functions in the database dependency, the database connection configuration, and the SQL statement input.
As a preferred embodiment, scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated, and acquiring the configuration file of the database to be migrated, the method specifically includes the following steps:
and scanning and analyzing the source code of the database to be migrated according to the path of the source code of the database to be migrated and the type of the database to be migrated, and scanning to obtain java, xml, pom, yml and properties files in the source code of the database to be migrated.
In a second aspect, the present invention provides a database migration system, which specifically includes:
the input module is used for acquiring a source code path of the database to be migrated and a source code path of the database after migration, and acquiring a type of the database to be migrated and a type of the database after migration;
the scanning module is used for scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated, and acquiring a configuration file of the database to be migrated; extracting database dependence, database connection configuration and SQL statements according to the configuration file;
the loading module is used for loading the database adapter according to the type of the database to be migrated and the type of the database after migration;
the database adapter is used for inputting the database dependence, the database connection configuration and the SQL statement into the database adapter for conversion to obtain a conversion file;
and the migration module is used for filling the migrated database according to the conversion file and the migrated database source code path.
As a preferred embodiment, the system further comprises:
and the output module is used for outputting the conversion file to the specified conversion file output path.
As a further preferred embodiment, the input module is further configured to obtain a conversion file output path.
In a third aspect, the invention also provides a computer-readable storage medium, in which a computer program is stored, which computer program, when executed by a processor, performs the method of any one of the above.
In a fourth aspect, the present invention also provides a computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the computer program, when executed by the processor, implementing the method as in any one of the above.
Compared with the prior art, the invention has the beneficial effects that:
the method and the system can scan the source code of the database, extract SQL sentences for analysis, then give SQL adaptation and modification suggestions through the database adapter, finally generate an automatic conversion source code file and automatically migrate the database.
Meanwhile, the method and the system can also generate a scanning adaptation report to assist technicians to quickly position and modify unadapted codes for migration, so that human resource occupation and migration risks during database migration are reduced.
Drawings
FIG. 1 is a flow chart of a database migration method of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
In the following description, numerous embodiments of the present application are provided, and different embodiments may be substituted or combined in any combination, and thus the present application is intended to cover all possible combinations of the same and/or different embodiments described. Thus, if one embodiment includes features a, B, C and another embodiment includes features B, D, then this application should also be construed to include embodiments that include all other possible combinations of one or more of a, B, C, D, although such embodiments may not be explicitly recited in the following text.
The following description provides examples, and does not limit the scope, applicability, or examples set forth in the claims. Changes may be made in the function and arrangement of elements described without departing from the scope of the disclosure. Various examples may omit, substitute, or add various procedures or components as appropriate. For example, the described methods may be performed in an order different than the order described, and various steps may be added, omitted, or combined. Furthermore, features described with respect to some examples may be combined into other examples.
The present application provides a database migration method, in an embodiment of the method, a flowchart of which is shown in fig. 1, and specifically includes the following steps:
s1, acquiring a source code path of a database to be migrated and a source code path of a migrated database, and acquiring a type of the database to be migrated and a type of the migrated database.
Specifically, the obtaining may be performed by inputting a source code path of the database to be migrated and a source code path of the migrated database by a user or a manager, and inputting a type of the database to be migrated and a type of the database after migration by the user or the manager.
S2, according to the source code path of the database to be migrated and the type of the database to be migrated, scanning and analyzing the source codes of the database to be migrated, and acquiring a configuration file of the database to be migrated.
In this embodiment, the scanning analysis of the source code is performed according to different file types, and the source code is analyzed by dom4j for an XML file, and the SQL statement in the file is analyzed and extracted for a java file, and then the database dependency and the database connection configuration are obtained by scanning and analyzing the database source code by using the regular matching.
And S3, extracting database dependence, database connection configuration and SQL statements according to the configuration file.
And S4, loading the database adapter according to the type of the database to be migrated and the type of the database after migration.
And S5, inputting the database dependence, the database connection configuration and the SQL statement into a database adapter for conversion to obtain a conversion file.
And S6, filling the migrated database according to the conversion file and the migrated database source code path.
Specifically, in the step S2, the source code of the database to be migrated is scanned and analyzed according to the source code path of the database to be migrated and the type of the database to be migrated, so as to obtain the configuration file of the database to be migrated, which specifically includes the following steps:
and scanning and analyzing the source code of the database to be migrated according to the path of the source code of the database to be migrated and the type of the database to be migrated, and scanning to obtain java, xml, pom, yml and properties files in the source code of the database to be migrated.
Specifically, in step S5, the above embodiment performs conversion on the database dependency, the database connection configuration, and the SQL statement input into the database adapter, specifically, performs matching conversion on the double quotation marks, the single quotation marks, the keywords, and the functions in the database dependency, the database connection configuration, and the SQL statement input.
Taking an application scenario of migrating the MySQL database to the dream database as an example, a specific implementation of step S5 in this embodiment is given:
s51, the database applies the pom file dependence such as MySQL-connector-java, and the adaptation engine directly completes dependence replacement through str.
S52, configuring a driver class com.mysql.jdbc.driver for the database application, matching the location of the configuration file of the database application by the adaptation engine through a regular str.matches ("= (=) (\ S) =) com.mysql (. Cj)
S53, the MySQL statement includes an inverse quotation mark (") indicating a field name or a table name, and the adaptation engine replaces the sql.
S54, including a double reference (") in the MySQL statement represents a constant, the dreams database represents a constant by a single reference ('), the adaptation engine completes the double reference constant replacement in the SELECT statement by a regular replacement statement sql.displaceall (" (? +) (? [ =? >, < >), (?) (?, (.
And S55, setting the field and the table name in the MySQL sentence as the key words of the dream-reaching database, such as user.
The adaptation engine converts the USER to "USER" by canonical replacement sql. Displaceall ("(FROM | FROM) \ \ s + (" is) ("+ key. Tolowercase () +" "|" + key. Toppercase () + ") (" is? "\\", "" s + | \\"", "" FROM \ "" + key. Toppercase () + "), and is distinguished FROM the keyword.
S56, functions in MySQL sentences such as DATE ('time') do not exist in the dreaming database, and the adaptation engine converts the functions into function trunc ('time') through the configuration classes so as to adapt the dreaming database.
In another embodiment of the present application, in order to solve the problem that the partial SQL statement cannot be automatically converted, step S5 of this embodiment further includes the following steps:
when the database dependence, the database connection configuration and the SQL statements are input into a database adapter for conversion, the SQL statements which cannot be converted are marked and a log file is generated;
and when the conversion file is output to the specified conversion file output path, the log file is also output to the specified conversion file output path.
Specifically, step S57 is included after step S56, and a system variable such as @ @ version does not exist in the dreams database in the MySQL statement. The adaptation engine searches SQL which cannot be converted through regular matching SQL ("[ \ \ S \ S ] \ \ S + (((.
In another embodiment of the present application, the method for filling the post-migration database according to the conversion file and the post-migration database source code path specifically includes the following steps:
acquiring an automatically converted source code according to the conversion file;
the post-migration database is populated with the automatically translated source code.
In addition, as a more specific method for converting a file, in another embodiment of the present application, the method for populating the post-migration database according to the converted file and the source code path of the post-migration database specifically includes the following steps:
inputting the database dependence, the database connection configuration and the SQL statement into a database adapter for conversion to obtain a conversion file;
and outputting the conversion file to a specified conversion file output path.
As a further supplement to the improvement in the foregoing embodiment, in a further embodiment, when the step S1 is executed, and the source code path of the database to be migrated and the source code path of the database after migration are obtained, the output path of the conversion file is also obtained at the same time.
In another embodiment of the present application, a database migration system is further provided, configured to execute the database migration method in each of the foregoing embodiments, where the system specifically includes:
the input module is used for acquiring a source code path of the database to be migrated and a source code path of the database after migration, and acquiring a type of the database to be migrated and a type of the database after migration;
the scanning module is used for scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated, and acquiring a configuration file of the database to be migrated; extracting database dependence, database connection configuration and SQL statements according to the configuration file;
the loading module is used for loading the database adapter according to the type of the database to be migrated and the type of the database after migration;
the database adapter is used for inputting the database dependence, the database connection configuration and the SQL statement into the database adapter for conversion to obtain a conversion file;
and the migration module is used for filling the migrated database according to the conversion file and the migrated database source code path.
As an embodiment corresponding to the above method including outputting the conversion file to the designated conversion file output path, in an embodiment of the present application, the system further includes: and the output module is used for outputting the conversion file to the specified conversion file output path.
In order to provide the output module with the output path of the converted file, in a further embodiment, the input module is further configured to obtain the output path of the converted file.
The present application also provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the steps of the database migration method in the various embodiments described above. The computer-readable storage medium can include, but is not limited to, any type of disk including floppy disks, optical disks, DVD, CD, -R micro-O type M drives, and magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic or optical cards, nanosystems (including molecular memory ICs), or any type of media or device suitable for storing instructions and/or data.
The present application also provides an electronic device comprising at least one processor, at least one memory, and a computer program stored on the memory and executable on the processor.
The processor may include one or more processing cores, among others. The processor, using the various interfaces and lines to connect the various parts throughout the electronic device, performs various functions and processes data by executing or executing instructions, programs, code sets, or instruction sets stored in memory, and calling data stored in memory. Optionally, the processor may be implemented in at least one hardware form of DSP, FPGA, and PLA. The processor may integrate one or a combination of several of a CPU, GPU, modem, and the like. The CPU mainly processes an operating system, a user interface, an application program and the like; the GPU is used for rendering and drawing the content required to be displayed by the display screen.
The memory may include a RAM or a ROM. Optionally, the memory includes a non-transitory computer readable medium. The memory may be used to store an instruction, a program, code, a set of codes, or a set of instructions. The memory may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the various method embodiments described above, and the like; the storage data area may store data and the like referred to in the above respective method embodiments. The memory may alternatively be at least one memory device located remotely from the aforementioned processor. The memory, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and an application program of the above-described database migration method.
It should be noted that for simplicity of description, the above-mentioned embodiments of the method are described as a series of acts, but those skilled in the art should understand that the present application is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present application. Further, those skilled in the art will recognize that the embodiments described in this specification are preferred embodiments and that acts or modules referred to are not necessarily required for this application.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
The above description is only an exemplary embodiment of the present disclosure, and the scope of the present disclosure should not be limited thereby. That is, all equivalent changes and modifications made in accordance with the teachings of the present disclosure are intended to be included within the scope of the present disclosure. Embodiments of the present disclosure will be readily apparent to those skilled in the art from consideration of the specification and practice of the disclosure herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.

Claims (12)

1. A database migration method is characterized by specifically comprising the following steps:
acquiring a source code path of a database to be migrated and a source code path of a migrated database, and simultaneously acquiring a type of the database to be migrated and a type of the migrated database;
scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated, and acquiring a configuration file of the database to be migrated;
extracting database dependence, database connection configuration and SQL statements according to the configuration file;
loading the database adapter according to the type of the database to be migrated and the type of the database after migration;
inputting the database dependence, the database connection configuration and the SQL statement into the database adapter for conversion to obtain a conversion file;
and filling the migrated database according to the conversion file and the migrated database source code path.
2. The method for migrating a database according to claim 1, wherein the filling of the migrated database according to the conversion file and the source code path of the migrated database includes the following steps: acquiring an automatically converted source code according to the conversion file;
and filling the migrated database with the automatically converted source codes.
3. The method for migrating a database according to claim 1, wherein the filling of the migrated database according to the conversion file and the source code path of the migrated database includes the following steps: inputting the database dependence, the database connection configuration and the SQL statement into the database adapter for conversion to obtain a conversion file;
and outputting the conversion file to a specified conversion file output path.
4. The database migration method according to claim 3, wherein when inputting the database dependencies, the database connection configurations, and the SQL statements into the database adapter for conversion, the SQL statements that cannot be converted are marked and a log file is generated;
and when the conversion file is output to the specified conversion file output path, the log file is also output to the specified conversion file output path.
5. The database migration method according to claim 3, wherein when the source code path of the database to be migrated and the source code path of the database after migration are obtained, the output path of the conversion file is also obtained.
6. The method for migrating the database according to claim 1, wherein the database dependency, the database connection configuration, and the SQL statement are input into the database adapter for conversion, specifically, the database dependency, the database connection configuration, and the SQL statement input are subjected to matching conversion by using a double quotation mark, a single quotation mark, a keyword, and a function.
7. The method for migrating the database according to claim 1, wherein the step of scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated to obtain the configuration file of the database to be migrated includes the following steps:
and scanning and analyzing the source code of the database to be migrated according to the path of the source code of the database to be migrated and the type of the database to be migrated, and scanning to obtain java, xml, pom, yml and properties files in the source code of the database to be migrated.
8. A database migration system, specifically comprising:
the input module is used for acquiring a source code path of the database to be migrated and a source code path of the database after migration, and acquiring a type of the database to be migrated and a type of the database after migration;
the scanning module is used for scanning and analyzing the source code of the database to be migrated according to the source code path of the database to be migrated and the type of the database to be migrated, and acquiring a configuration file of the database to be migrated; extracting database dependence, database connection configuration and SQL statements according to the configuration file;
the loading module is used for loading the database adapter according to the type of the database to be migrated and the type of the database after migration;
the database adapter is used for inputting the database dependence, the database connection configuration and the SQL statement into the database adapter for conversion to obtain a conversion file;
and the migration module is used for filling the migrated database according to the conversion file and the migrated database source code path.
9. The database migration method according to claim 8, further comprising:
and the output module is used for outputting the conversion file to a specified conversion file output path.
10. The database migration method according to claim 9, wherein said input module is further configured to obtain said output path of the converted file.
11. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, implements the method of any one of claims 1 to 7.
12. A computer device, characterized in that the computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, which computer program, when executed by the processor, implements the method according to any of claims 1 to 7.
CN202211736134.0A 2022-12-30 2022-12-30 Database migration method and system Pending CN115934682A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211736134.0A CN115934682A (en) 2022-12-30 2022-12-30 Database migration method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211736134.0A CN115934682A (en) 2022-12-30 2022-12-30 Database migration method and system

Publications (1)

Publication Number Publication Date
CN115934682A true CN115934682A (en) 2023-04-07

Family

ID=86552466

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211736134.0A Pending CN115934682A (en) 2022-12-30 2022-12-30 Database migration method and system

Country Status (1)

Country Link
CN (1) CN115934682A (en)

Similar Documents

Publication Publication Date Title
US9405532B1 (en) Integrated cloud platform translation system
CN108762743B (en) Data table operation code generation method and device
US10592220B2 (en) Metadata-driven binding of converted source code to original source code
CN106951305B (en) Method for generating midCore script from QVT-R language based on model conversion
US11301643B2 (en) String extraction and translation service
KR101770292B1 (en) Computer-executable model reverse engineering method and apparatus performing the same
CN113468204A (en) Data query method, device, equipment and medium
US20090055421A1 (en) Migration and transformation of data structures
CN111488155A (en) Coloring language translation method
Rinner et al. Creating ISO/EN 13606 archetypes based on clinical information needs
CN114489950A (en) Component adapting method and device, electronic equipment and storage medium
CN113934786A (en) Implementation method for constructing unified ETL
CN113297251A (en) Multi-source data retrieval method, device, equipment and storage medium
CN108694172B (en) Information output method and device
CN111008011A (en) System builder for power platform application development
US10540157B2 (en) Systems to remove object relational mappings from a software project
CN113821496B (en) Database migration method, system, device and computer readable storage medium
CN116303359A (en) Method for realizing multi-type document export of database structure
CN116955393A (en) Data processing method and device, electronic equipment and storage medium
CN115934682A (en) Database migration method and system
CN113051262B (en) Data quality inspection method, device, equipment and storage medium
CN115469881A (en) Configuration publishing and calling method and system for low-code platform service function
CN110515653B (en) Document generation method and device, electronic equipment and computer readable storage medium
US20220147568A1 (en) Mapping expression generator
CN115618887B (en) Dynamic long text internationalization method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination