Data migration method and device, server and storage medium

By using the tag annotation algorithm to obtain table names and field names in the business system, and an automated data migration SQL script is generated, the data omissions and errors during the permission migration process are solved, and migration efficiency and system stability are improved.

CN119003491APending Publication Date: 2024-11-22PING AN BANK CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411257495.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-09
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

The existing permission migration plan is prone to data omissions, data errors, and incorrect formats during the migration of the business system, which affects the production environment and system stability.

Method used

Obtain migration information through the data migration page of the business system, use the pre-determined marking and annotation algorithm to annotate the database table, obtain the table name and table field name, and generate data migration SQL scripts based on this information to automatically realize data migration.

Benefits of technology

It improves the efficiency of permission migration, reduces errors and omissions in data migration, and enhances the stability of the business system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003491A_ABST
    Figure CN119003491A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of data processing, and provides a data migration method which comprises the following steps: acquiring data migration information through a data migration page of a service system; acquiring a plurality of information tables corresponding to the data migration information from a to-be-migrated database of the service system, and annotating and marking each information table based on a predetermined marking and annotating algorithm to obtain a corresponding table name and a table field name; generating a data migration SQL script corresponding to the data migration information based on the table name and the table field name according to a predetermined data migration SQL script generation algorithm; and running the data migration SQL script in a to-be-migrated database of the service system to realize data migration. According to the data migration method, the efficiency of role resource permission migration and the stability of a service system are improved, and mistakes and omissions of data migration are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a data migration method, device, server and storage medium. Background Art

[0002] Usually, in a multi-user business system, there is a user-role-resource permission control system, which aims to perform permission control such as system registration and login, menu function restrictions, and interface call authentication through this system, so as to maintain and ensure the security of the system and prevent the system data from being illegally queried, modified, or deleted. During the development and iteration process of the business system, the corresponding user role resource permissions will be configured in the test environment before the business system goes online to provide business services. After the permission configuration test is passed, the permission data configuration of the test environment needs to be migrated to the production environment for use.

[0003] The existing permission migration solution is to manually write data migration SQL scripts based on the permission configuration table in the test environment database, and then execute the data migration SQL scripts in the production environment database to migrate permissions. However, when there are a large number of users and system resources in the business system, the manually written permission migration SQL scripts are prone to data omissions, data errors, incorrect formats, etc., which affects the production and testing efficiency of the production environment and the stability of the system. Summary of the invention

[0004] The present invention provides a data migration method, device, server and storage medium, the main purpose of which is to provide a method for automatically writing data migration SQL scripts based on user input information.

[0005] To achieve the above object, the present invention provides a data migration method, the method comprising:

[0006] Obtain data migration information through the data migration page of the business system;

[0007] Acquire multiple information tables corresponding to the data migration information from the database to be migrated out of the business system, and annotate each information table based on a predetermined marking and annotation algorithm to obtain corresponding table names and table field names;

[0008] Based on the table name and the table field name, and according to a predetermined data migration SQL script generation algorithm, generate a data migration SQL script corresponding to the data migration information;

[0009] The data migration SQL script is executed in the database to be migrated of the business system to realize data migration.

[0010] Optionally, the step of annotating each information table based on a predetermined marking and annotation algorithm to obtain a corresponding table name and table field name includes:

[0011] Define the Java class corresponding to the entity object of each information table, and define the column names in the information table as attributes of the corresponding Java class;

[0012] Annotate the table name and table field name of each information table through a predetermined annotation framework;

[0013] The table name marked with annotations corresponding to the Java class and the table field name marked with annotations corresponding to the attributes of the Java class are obtained through the Java reflection mechanism.

[0014] Optionally, the step of annotating and marking the table name and table field name of each information table by using a predetermined annotation framework includes:

[0015] Get the table name of each information table and the table field name corresponding to each column in the table;

[0016] Annotating and marking the table name by a table name annotation command in a predetermined annotation framework;

[0017] The table field name is annotated and marked by a table field name annotation command in a predetermined annotation framework.

[0018] Optionally, the obtaining, through a Java reflection mechanism, the table name marked with an annotation corresponding to the Java class and the table field name marked with an annotation corresponding to the attribute of the Java class includes:

[0019] Obtain the corresponding entity object through the Java class, and obtain the table name of the annotation mark corresponding to the entity object;

[0020] The table field names marked with annotations corresponding to all the attributes of the Java class are obtained through the field value acquisition method of the entity object.

[0021] Optionally, the generating a data migration SQL script corresponding to the data migration information based on the table name and the table field name and according to a predetermined data migration SQL script generation algorithm includes:

[0022] Traverse the table names and table field names marked with annotations to obtain the table names and table field names corresponding to the data migration information;

[0023] Generate a data migration SQL text for each information table corresponding to the data migration information according to the table name and table field name corresponding to the data migration information;

[0024] The data migration SQL texts of multiple information tables are concatenated to obtain a data migration SQL script corresponding to the data migration information.

[0025] Optionally, generating the data migration SQL text for each information table corresponding to the data migration information according to the table name and table field name corresponding to the data migration information includes:

[0026] Obtain a corresponding data migration SQL statement template according to the table name corresponding to the data migration information;

[0027] The field value of the table name and the field value of the table field name corresponding to the data migration information are filled into the data migration SQL statement template to obtain the data migration SQL text of each information table corresponding to the data migration information.

[0028] Optionally, the step of concatenating the data migration SQL texts of the multiple information tables to obtain a data migration SQL script corresponding to the data migration information includes:

[0029] Merge the data migration SQL texts corresponding to each information table by string concatenation to obtain the data migration SQL script;

[0030] The data migration SQL script is converted into a bit stream and exported to an Http response, so that the database to be migrated in the business system can download and use the data migration SQL script.

[0031] In order to solve the above problem, the present invention further provides a data migration device, the data migration device comprising:

[0032] The data acquisition module is used to obtain data migration information through the data migration page of the business system;

[0033] An annotation module, used for obtaining multiple information tables corresponding to the data migration information from the database to be migrated from the business system, and annotating each information table based on a predetermined marking algorithm to obtain a corresponding table name and table field name;

[0034] A script generation module, configured to generate a data migration SQL script corresponding to the data migration information based on the table name and the table field name and according to a predetermined data migration SQL script generation algorithm;

[0035] The data migration module is used to execute the data migration SQL script in the database to be migrated in the business system to realize data migration.

[0036] In order to solve the above problem, the present invention further provides a server, the server comprising:

[0037] at least one processor; and,

[0038] a memory communicatively connected to the at least one processor; wherein,

[0039] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor so that the at least one processor can perform the data migration method as described above.

[0040] In order to solve the above problem, the present invention further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the above-mentioned data migration method is implemented.

[0041] The present invention defines data table entity objects and defines corresponding table names and table field names with annotation identifiers, so as to facilitate SQL statements to obtain and call data objects, generate SQL migration statements through the JAVA reflection mechanism and form SQL scripts, thereby improving the efficiency of role resource permission migration, reducing errors and omissions in data migration, and improving the stability of the business system. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 A flow chart of an embodiment of a data migration method of the present invention;

[0043] Figure 2 A schematic diagram of an embodiment of a server of the present invention;

[0044] Figure 3 It is a structural schematic diagram of an embodiment of a data migration device of the present invention.

[0045] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solution and advantages of the present invention more clear, the principle and spirit of the present invention will be described below with reference to several specific embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention and are not used to limit the present invention.

[0047] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention. In addition, the technical solutions between the various embodiments can be combined with each other, but it must be based on the ability of ordinary technicians in this field to implement. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0048] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.

[0049] The phrases such as "one embodiment" or "some embodiments" described in the present application mean that the specific features, structures or characteristics described in the embodiment are included in one or more embodiments of the present application. Therefore, the phrases such as "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments" that appear in the differences in the present application do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. In addition, the terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0050] like Figure 1 FIG. 1 is a flow chart of an embodiment of a data migration method of the present invention. The data migration method includes steps S1 to S4.

[0051] S1. Obtain data migration information through the data migration page of the business system.

[0052] In one embodiment, the business system includes a database to be migrated out and a database to be migrated in. The database to be migrated out and the database to be migrated in can be data storage spaces located in different system terminals or servers of the business system, or can be two data storage spaces located in the same system terminal or server of the business system; when the business system is a distributed storage system, the database to be migrated out and the database to be migrated in can also be data storage spaces of different nodes in the business system.

[0053] In one embodiment, the data migration information includes a role code and a top-level resource ID, and the data migration method further includes: establishing a data migration page on the front-end page corresponding to the business system, the data migration page including a role code input box, a top-level resource ID input box and an export button. The role code input box is used to obtain one or more role codes input by the user, the top-level resource ID input box is used to obtain one or more top-level resource IDs input by the user, and the export button is used to export the bit stream converted from the data migration SQL script generated according to the user input content to the Http response of the data migration page, so that the database to be migrated in the business system can download and use the data migration SQL script.

[0054] In one embodiment, the role code is a user authority type, such as a super administrator, a user administrator, and a role administrator. The top-level resource ID is the parent node ID at the top of the resource tree. For example, a page, a button, or an interface can all be defined as resources, and there is a superior-subordinate relationship between resources, such as a page can have multiple buttons, and a button can correspond to multiple interfaces. By defining a unique identification ID for each resource and defining the parent node ID according to the superior-subordinate relationship, a resource tree is obtained by defining the relationship in the form of a tree structure based on all resource IDs and the corresponding parent node IDs.

[0055] In one embodiment, obtaining data migration information through the data migration page of the business system includes: obtaining a role code list input by a user through a role code input box on the data migration page; and obtaining a top-level resource ID input by a user through a top-level resource ID input box on the data migration page.

[0056] In one embodiment, obtaining the role code list input by the user through the role code input box on the data migration page includes: obtaining multiple role codes separated by English commas input by the user in the role code input box on the data migration page through the role code input box on the data migration page, and constructing a role code list based on the above multiple role codes.

[0057] In one embodiment, after obtaining the top-level resource ID input by the user through the top-level resource ID input box of the data migration page, the method further includes: obtaining a top-level resource information table corresponding to the top-level resource ID and a sub-resource information table belonging to the top-level resource.

[0058] S2. Acquire multiple information tables corresponding to the data migration information from the database to be migrated out of the business system, and annotate each information table based on a predetermined marking and annotation algorithm to obtain corresponding table names and table field names.

[0059] In one embodiment, the method of annotating each information table based on a predetermined marking and annotation algorithm to obtain the corresponding table name and table field name includes: defining the Java class corresponding to the entity object of each information table, and defining the column name in the information table as the attribute of the corresponding Java class; annotating the table name and table field name of each information table through a predetermined annotation framework; and obtaining the annotated table name corresponding to the Java class and the annotated table field name corresponding to the attribute of the Java class through a Java reflection mechanism.

[0060] In one embodiment, the plurality of information tables include a user information table, a role information table, a role-user information association table, a resource information table, and a role-resource information association table. For example:

[0061] user_info (user information table)

[0062]

[0063] role_info (role information table)

[0064]

[0065] role_user_relate_info (role user information association table)

[0066]

[0067]

[0068] resource_info (resource information table)

[0069]

[0070] role_resource_relate_info (role resource information association table)

[0071]

[0072] In one embodiment, the annotating and marking the table name and table field name of each information table through a predetermined annotation framework includes: obtaining the table name of each information table and the table field names corresponding to each column in the table; annotating and marking the table name through a table name annotation command in a predetermined annotation framework; annotating and marking the table field name through a table field name annotation command in a predetermined annotation framework.

[0073] In one embodiment, the predetermined annotation framework is a MyBatis framework, and the table name annotation command in the predetermined annotation framework is to mark the table name through the @TableName annotation tag to specify the mapping relationship between the Java entity class defined by the information table and the corresponding database information table; the table field name annotation command in the predetermined annotation framework is to mark the table field name through the @TableField annotation to specify the mapping relationship between the Java class attributes defined by the information table column name and the corresponding information table column name.

[0074] For example: the role_info (role information table) of the business system is as follows

[0075]

[0076] As an entity object, the role information table contains the following field attributes: roleNo attribute, roleName attribute, and roleStatus attribute. The table name of the entity object is marked as role_info through the @TableName annotation, the role_no field corresponding to the roleNo attribute is marked through the @TableField annotation, the role_name field corresponding to the roleName attribute is marked through the @TableField annotation, and the role_status field corresponding to the roleStatus attribute is marked through the @TableField annotation. The code is as follows:

[0077]

[0078]

[0079] The user_info (user information table) of the business system is as follows:

[0080]

[0081] As an entity object, the user information table contains the following field attributes: user_id attribute, user_name attribute, and user_status attribute. The table name of the entity object is marked as user_info through the @TableName annotation, the user_id field corresponding to the user_id attribute is marked through the @TableField annotation, the user_name field corresponding to the user_name attribute is marked through the @TableField annotation, and the user_status field corresponding to the user_status attribute is marked through the @TableField annotation.

[0082] The role_user_relate_info (role user information association table) of the business system is as follows:

[0083]

[0084] The role user information association table is an entity object and contains the following field attributes: relate_id attribute, role_no attribute, and user_id attribute. The table name of the entity object is marked as role_user_relate_info through the @TableName annotation, the relate_id field corresponding to the relate_id attribute is marked through the @TableField annotation, and the role_no field corresponding to the role_no attribute is marked through the @TableField annotation.

[0085] The @TableField annotation marks the user_id field corresponding to the user_id attribute.

[0086] The resource_info (resource information table) of the business system is as follows:

[0087]

[0088] As an entity object, the resource information table contains the following field attributes: resource_id attribute, parent_id attribute, resource_name attribute, resource_type attribute, and resource_url attribute.

[0089] The @TableName annotation marks the table name resource_info of the entity object, the resource_id field corresponding to the resource_id attribute is marked through the @TableField annotation, the parent_id field corresponding to the parent_id attribute is marked through the @TableField annotation, the resource_name field corresponding to the resource_name attribute is marked through the @TableField annotation, the resource_type field corresponding to the resource_type attribute is marked through the @TableField annotation, and the resource_url field corresponding to the resource_url attribute is marked through the @TableField annotation.

[0090] The role_resource_relate_info (role resource information association table) of the business system is as follows:

[0091]

[0092]

[0093] As an entity object, the role resource information association table contains the following field attributes: relate_id attribute, role_no attribute, and resource_id attribute. The table name of the entity object is marked as role_resource_relate_info through the @TableName annotation, the relate_id field corresponding to the relate_id attribute is marked through the @TableField annotation, the role_no field corresponding to the role_no attribute is marked through the @TableField annotation, and the resource_id field corresponding to the resource_id attribute is marked through the @TableField annotation.

[0094] The @TableName annotation is used to specify the mapping relationship between the entity class and the database table. When the name of the entity class is inconsistent with the name of the database table, this annotation can be used to specify the correct table name. When MyBatis Plus is used for database operations, the correct table name can be referenced when the name of the entity class is inconsistent with the name of the database table. This facilitates the use of the Java reflection mechanism in the MyBatis framework to reference the entity class or call methods and properties for table name reference.

[0095] The @TableField annotation is an annotation provided by MyBatis-Plus, which is used to identify the mapping relationship between entity class fields and database table fields. Through the @TableField annotation, you can specify the name of the field, whether it is a database field, whether it is a primary key, whether it is a logically deleted field, and other properties, thereby achieving more flexible database operations.

[0096] The @TableField annotation provides multiple attributes, the commonly used attributes include:

[0097] value: specifies the name of the database table field.

[0098] exist: specifies whether the field is a database table field. The default value is true.

[0099] fill: specifies the field filling strategy, such as automatic filling during insertion and automatic filling during update.

[0100] select: specifies whether the field is involved in the query. The default value is true.

[0101] update: specifies whether the field is updated or not. The default value is true.

[0102] condition: specifies the matching method of the field in the query condition, such as LIKE, EQUAL, etc.

[0103] In this embodiment, the attribute marked with the @TableField annotation is the value attribute, which is the name of the database table field (table field name). In actual development, the naming convention of the database table field may be inconsistent with the naming convention of the entity class field. For example, the database table field uses the underscore naming method (such as user_name), while the entity class field uses the camel case naming method (such as userName). Through the value attribute of the @TableField annotation, the name of the database table field can be specified to achieve field name mapping.

[0104] The @TableField annotation is a very important annotation provided by MyBatis-Plus, which is used to define the mapping relationship between entity class fields and database table fields. Through the @TableField annotation, you can implement functions such as field name mapping, non-database field identification, field filling strategy, field query strategy, logical deletion of field identification, etc., thereby simplifying database operations and improving development efficiency. In actual development, the @TableField annotation should be used reasonably according to specific needs to achieve flexible and efficient database operations.

[0105] In this embodiment, the MyBatis framework supports customized SQL, stored procedures, and advanced mapping. The MyBatis framework avoids almost all JDBC codes and manual parameter settings and result set acquisition. Simple XML or annotations can be used to configure and map native information, mapping interfaces and Java POJOs (Plain Ordinary Java Objects) into records in the database.

[0106] In this embodiment, the @TableName annotation is used to define the mapping relationship between the Java entity class and the database table, which is particularly useful when the table name is inconsistent with the entity class name or does not conform to the naming convention. The @TableField annotation is used to define the mapping relationship between the Java entity class field and the database table field. This annotation is usually used together with an object-relational mapping (ORM) framework, such as MyBatis or Hibernate, to help users manage the corresponding relationship between the entity class and the database table. By adding the @TableName annotation to the entity class and specifying the table name, the ORM framework can map the class to the specified database table. The benefit of using @TableName and @TableField for annotation identification is that it can improve the readability and maintainability of the code, because by directly defining the table name and table field on the class, it is possible to clearly understand which database table the Java class corresponds to, and which database table field the Java class attribute corresponds to, avoiding the scattered table name strings and table field strings in the code, thereby improving the readability and maintainability of the code.

[0107] In one embodiment, the method of obtaining the annotation-marked table name corresponding to the Java class and the annotation-marked table field name corresponding to the attribute of the Java class through the Java reflection mechanism includes: obtaining the corresponding entity object through the Java class, and obtaining the annotation-marked table name corresponding to the entity object; obtaining the annotation-marked table field name corresponding to all attributes of the Java class through the field value acquisition method of the entity object.

[0108] In this embodiment, the Java reflection mechanism is in the running state. For any entity class, all properties and methods of this class can be known; for any object, any of its methods and properties can be called; this function of dynamically obtaining information and dynamically calling object methods is called Java's reflection mechanism.

[0109] Among them, the three ways of obtaining Class objects by Java reflection mechanism include:

[0110] 1. Through the .class syntax of the class. For example:

[0111] Class clazz = String.class;

[0112] 2. Through the object's getClass() method. For example:

[0113] String s = "Hello";

[0114] Class clazz = s.getClass();

[0115] 3. Get the Class object by the full class name, for example:

[0116] Class clazz=Class.forName("java.lang.String");

[0117] Java reflection mechanism uses reflection mechanism to obtain the constructor, method and property code of the class as follows:

[0118] Get the constructor:

[0119] Constructor[]constructors=clazz.getConstructors();

[0120] How to obtain:

[0121] Method[]methods=clazz.getMethods();

[0122] Get properties:

[0123] Field[]fields=clazz.getFields();

[0124] Java reflection mechanism uses reflection mechanism to create objects, call methods and attributes. The code is as follows:

[0125] Create the object:

[0126] Constructor constructor=clazz.getConstructor(String.class);

[0127] String str=(String)constructor.newInstance("Hello");

[0128] Calling method:

[0129] Method method=clazz.getMethod("charAt",int.class);

[0130] Object result=method.invoke(str,1);

[0131] Setting and getting properties:

[0132] Field field=clazz.getDeclaredField("value");

[0133] field.setAccessible(true);

[0134] char[]value=(char[])field.get(str);

[0135] For example, the table name annotated with @TableName in the Java class object can be obtained through the Java reflection mechanism, and the table name annotated with @TableName in the Java class object can be obtained directly through XXXXX.class.getAnnotation(TableName.class).value();

[0136] Get the properties of the Java class through the Java reflection mechanism. Use the table field name marked with the @TableField annotation. You can use getObjectAllField(XXXXX.class)..stream().filter(field->

[0137] field.getAnnotation(TableField.class)!=null).collect(Collectors.toList()); Filter and obtain the table field names marked with @TableField annotation for the properties of the Java class.

[0138] For a bytecode file .class, although we know nothing about it on the surface, the file itself records a lot of information. When Java loads the .class bytecode file, the JVM will generate a java.lang.Class object to represent the .class bytecode file. From the Class object, you can get a lot of basic information about the class. This is the reflection mechanism. So in order to complete the reflection operation, you must first know the Class class.

[0139] The classes required for the reflection mechanism mainly include the Class class in the java.lang package and the Constructor class, Field class, Method class, and Parameter class in the java.lang.reflect package. The Class class is a special class that is the basis of the reflection mechanism. The object of the Class class represents the class or interface in the running Java program, that is, when any class is loaded, the .class file (bytecode file) of the class is read into the memory, and a java.lang.Class object is automatically created for it. The Class class has no public constructor. Its object is created by the JVM by calling the defineClass() method in the class loader when loading the class, so a Class object cannot be created explicitly. Only through this Class object can other information about the object be obtained.

[0140] After each class is loaded, the system will generate a corresponding Class object for the class. Through the Class object, you can access the information of the class in the JVM. Once a class is loaded into the JVM, the same class will not be loaded again. The class loaded into the JVM has a unique identifier, which is the full name of the class, including the package name and class name. There are three ways for a program to obtain a Class object in Java.

[0141] (1) Use the static method forName(String className) of the Class class, where the parameter className represents the full name of the required class. For example, "Class cObj = Class.forName

[0142] ("java.lang.String");". In addition, the forName() method declares that it throws a ClassNotFoundException, so you must catch or throw this exception when calling this method.

[0143] (2) Use the class name to call the class attribute of the class to obtain the Class object corresponding to the class, that is, "class name.class". For example, the statement "ClasscObj = Cylinder.class;" will return the Class object corresponding to the Cylinder class and assign it to the cObj variable.

[0144] (3) Call the getClass() method with the object to obtain the Class object corresponding to the class, that is, "object.getClass()". This method is a method in the Object class, so all objects can call this method to return the Class object corresponding to the class to which they belong. For example, for the statement "Person per = new Person(\"Zhang San\");" the Class object of this class can be returned through the following statement: Class cObj = per.getClass();

[0145] Obtaining the Class object corresponding to the class through the class's class attribute makes the code safer and the program performance better. Therefore, in most cases, it is recommended to use the second method. However, if only a string is obtained, for example, obtaining the Class object corresponding to the String class, the String.class method cannot be used, but Class.forName("java.lang.String") should be used. If you want to obtain the Class object of a primitive data type, you can use the corresponding wrapper class plus.TYPE. For example, Integer.TYPE can obtain the Class object of int, but to obtain the Class object of Integer.class, you must use Integer.class. After obtaining the Class object, the basic information of the Class object can be obtained.

[0146] The Java reflection mechanism allows a program to dynamically obtain information such as the attributes and methods of an object at runtime and generate and execute SQL statements accordingly. This makes database operations more flexible, and queries, updates, inserts, deletes, etc. can be dynamically constructed and executed according to actual needs. The Java reflection mechanism reduces the coupling degree between the code and the database structure. When the database structure changes, only the code related to reflection needs to be modified, without having to modify a large amount of business logic code. This greatly reduces the code maintenance cost and improves the scalability of the system. Through the Java reflection mechanism, developers can operate the database more conveniently without having to manually write a large number of SQL statements. At the same time, the reflection mechanism can also be used in combination with ORM frameworks to further improve development efficiency. The Java reflection mechanism supports dynamic type judgment and can determine the actual type of an object at runtime, thus supporting polymorphic operations. This makes database operations more flexible and different types of data can be handled more easily.

[0147] S3. Based on the table name and table field names, and according to a pre-determined data migration SQL script generation algorithm, generate the data migration SQL script corresponding to the data migration information.

[0148] In one embodiment, the generating of the data migration SQL script corresponding to the data migration information based on the table name and the table field name and according to a predetermined data migration SQL script generating algorithm includes: traversing the annotated table names and the annotated table field names to obtain the table names and the table field names corresponding to the data migration information; generating the data migration SQL text for each information table corresponding to the data migration information according to the table names and the table field names corresponding to the data migration information; and splicing the data migration SQL texts of multiple information tables to obtain the data migration SQL script corresponding to the data migration information.

[0149] In one embodiment, the table name and table field name marked with annotations are traversed through the Java reflection mechanism to obtain the table name and table field name corresponding to the data migration information, and the data migration SQL text of each information table corresponding to the data migration information is generated according to the table name and table field name corresponding to the data migration information. The specific code is as follows:

[0150]

[0151]

[0152]

[0153] In one embodiment, generating the data migration SQL text for each information table corresponding to the data migration information according to the table name and table field name corresponding to the data migration information includes: obtaining the corresponding data migration SQL statement template according to the table name corresponding to the data migration information; filling the field value of the table name and the field value of the table field name corresponding to the data migration information into the data migration SQL statement template to obtain the data migration SQL text for each information table corresponding to the data migration information.

[0154] For example, the data migration SQL statement template is:

[0155] INSERT INTO table name (table column name 1, table column name 2, ... table column name N) VALUES (table field name 1, table field name 2, ... table field name N)

[0156] The field value of the table name obtained according to the data migration information is resource_info; the table column names in the information table resource_info include: resource_id, parent_id, resource_name, resource_type and resource_url; the field values ​​of the table field names corresponding to the columns obtained according to the data migration information are 1, 0, user management page, page and user / manage / page. The field values ​​of the table name corresponding to the data migration information and the field values ​​of the table field names are filled into the data migration SQL statement template to obtain the data migration SQL text for each information table corresponding to the data migration information as follows:

[0157] INSERT INTO resource_info(resource_id,parent_id,resource_name,resource_type,resource_url)VALUES('1','0','User management page','page',

[0158] 'user / manage / page')

[0159] In one embodiment, the data migration SQL texts of multiple information tables are spliced ​​to obtain a data migration SQL script corresponding to the data migration information, including: merging the data migration SQL texts corresponding to each information table by string splicing to obtain a data migration SQL script; converting the data migration SQL script into a bit stream and exporting it to an Http response, so that the database to be migrated of the business system can download and use the data migration SQL script.

[0160] For example, the SQL text for merging data migration by string concatenation is as follows:

[0161]

[0162]

[0163] The generated data migration SQL script is as follows:

[0164] INSERT INTO role_info(role_no,role_name,role_status)VALUES('user_admin','User Administrator',0);

[0165] INSERT INTO role_info(role_no,role_name,role_status)VALUES('role_admin','Role Administrator',0);

[0166] INSERT INTO role_resource_relate_info(relate_id,role_no,resource_id)VALUES('1','user_admin','1');

[0167] INSERT INTO role_resource_relate_info(relate_id,role_no,resource_id)VALUES('2','role_admin','2');

[0168] INSERT INTO resource_info(resource_id,parent_id,resource_name,resource_type,resource_url)VALUES('1','0','User Management Page','Page',

[0169] 'user / manage / page');

[0170] INSERT INTO resource_info(resource_id,parent_id,resource_name,resource_type,resource_url)VALUES('2','0','Role Management Page','Page',

[0171] 'role / manage / page');

[0172] INSERT INTO role_user_relate_info(relate_id,role_no,user_id)VALUES('2','user_admin','XIAOGANG333');

[0173] INSERT INTO role_user_relate_info(relate_id,role_no,user_id)VALUES('3','role_admin','XIAOGANG333');

[0174] S4. Run the data migration SQL script in the database to be migrated in the business system to achieve data migration.

[0175] In one embodiment, the data migration is realized by running the data migration SQL script in the database to be migrated into the business system, including: judging whether the data communication link between the database to be migrated into the business system and the database to be migrated out of the business system is normal; if the data communication link is normal, running the data migration SQL script to migrate the data of the database to be migrated out of the business system to the database to be migrated into of the business system; if the data communication link is abnormal, notifying the management terminal corresponding to the database to be migrated into to repair the data communication link, and running the data migration SQL script after the data communication link is restored to normal, so as to migrate the data of the database to be migrated out of the business system to the database to be migrated into of the business system.

[0176] It can be seen from the above embodiments that the embodiments of the present invention define data table entity objects and define corresponding table names and table field names with annotations, so as to facilitate SQL statements to obtain and call data objects, generate SQL migration statements through the JAVA reflection mechanism and form SQL scripts, thereby improving the efficiency of role resource permission migration, reducing errors in data migration, and improving the stability of the business system.

[0177] like Figure 2 FIG. 1 is a schematic diagram of an embodiment of a server of the present invention. Server 1 is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. The server 1 can be a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers, wherein cloud computing is a type of distributed computing, a super virtual computer composed of a group of loosely coupled computer sets.

[0178] In this embodiment, the server 1 includes, but is not limited to, a memory 11 , a processor 12 , and a network interface 13 that can be interconnected and communicated via a system bus. The memory 11 stores a data migration program 10 , and the data migration program 10 can be executed by the processor 12 . Figure 2 Only the server 1 having components 11-13 and the data migration program 10 is shown. It can be understood by those skilled in the art that Figure 2 The structure shown does not constitute a limitation on the server 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.

[0179] The memory 11 includes a memory and at least one type of readable storage medium. The memory provides a cache for the operation of the server 1; the readable storage medium can be volatile or non-volatile. Specifically, the readable storage medium can be a storage medium such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the readable storage medium can be an internal storage unit of the server 1, such as a hard disk of the server 1; in other embodiments, the storage medium can also be an external storage device of the server 1, such as a plug-in hard disk equipped on the server 1, a smart memory card (SmartMediaCard, SMC), a secure digital (SecureDigital, SD) card, a flash card (FlashCard), etc. In this embodiment, the readable storage medium of the memory 11 mainly includes a program storage area and a data storage area, wherein the program storage area is generally used to store an operating system and various application software installed on the server 1, such as storing the code of the data migration program 10 in one embodiment of the present invention; the data storage area can store data created according to the use of the blockchain node, such as various types of data that have been output or are to be output.

[0180] The processor 12 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 12 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect the various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (for example, executing resource dynamic scheduling programs, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data. The processor 12 is generally used to control the overall operation of the server 1, such as executing control and processing related to data interaction or communication with other devices. In this embodiment, the processor 12 is used to run the program code stored in the memory 11 or process data, such as running the data migration program 10, etc.

[0181] The network interface 13 may include a wireless network interface or a wired network interface.

[0182] Optionally, the server 1 may further include a user interface, which may include a display, an input unit such as a keyboard, and an optional user interface may further include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an organic light-emitting diode (OLED) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the server 1 and to display a visual user interface.

[0183] In one embodiment of the present invention, when the data migration program 10 is executed by the processor 12, the following data migration method is implemented, including steps S1-S4:

[0184] S1. Obtain resource migration information through the resource migration page of the business system;

[0185] S2. Acquire multiple information tables corresponding to the data migration information from the database to be migrated out of the business system, and annotate each information table based on a predetermined marking and annotation algorithm to obtain corresponding table names and table field names;

[0186] S3. Based on the table name and table field name, and according to a predetermined data migration SQL script generation algorithm, generate a data migration SQL script corresponding to the data migration information;

[0187] S4. Run the data migration SQL script in the database to be migrated in the business system to achieve data migration.

[0188] The specific operation steps implemented by the above steps S1-S4 are substantially the same as the steps S1-S4 of the first embodiment of the data migration method of the present invention, and will not be repeated here.

[0189] In other embodiments, the data migration program 10 may also be divided into one or more modules, one or more modules are stored in the memory 11, and are executed by one or more processors (processor 12 in this embodiment) to complete the present invention. The module referred to in the present invention refers to a series of computer program instruction segments that can perform specific functions, and is used to describe the execution process of the data migration program 10 in the server 1.

[0190] like Figure 3 FIG. 1 is a schematic diagram of the structure of a data migration device provided by an embodiment of the present invention.

[0191] In the first embodiment of the present invention, the data migration device 100 includes a data acquisition module 110, an annotation marking module 120, a script generation module 130 and a data migration module 140. Exemplarily:

[0192] The data acquisition module 110 is used to acquire resource migration information through the resource migration page of the business system;

[0193] The annotation module 120 is used to obtain multiple information tables corresponding to the data migration information from the database to be migrated of the business system, and annotate each information table based on a predetermined marking algorithm to obtain a corresponding table name and table field name;

[0194] The script generation module 130 is used to generate a data migration SQL script corresponding to the data migration information based on the table name and the table field name and according to a predetermined data migration SQL script generation algorithm;

[0195] The data migration module 140 is used to execute the data migration SQL script in the database to be migrated in the business system to realize data migration.

[0196] The specific operation steps implemented when the data acquisition module 110, the annotation marking module 120, the script generation module 130 and the data migration module 140 are executed are substantially the same as those in the above embodiment and will not be repeated here.

[0197] In addition, the embodiment of the present invention further proposes a computer-readable storage medium, which may be volatile or non-volatile. Specifically, the computer-readable storage medium may be any one or any combination of a hard disk, a multimedia card, an SD card, a flash memory card, an SMC, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, etc. The computer-readable storage medium stores a data migration program.

[0198] The specific software function implementation of the computer-readable storage medium of the present invention is substantially the same as the specific software implementation in the above-mentioned server 1, and will not be described in detail here.

[0199] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0200] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.

[0201] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0202] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A data migration method, characterized in that: The method comprises: Obtain data migration information through the data migration page of the business system; Acquire multiple information tables corresponding to the data migration information from the database to be migrated out of the business system, and annotate each information table based on a predetermined marking and annotation algorithm to obtain corresponding table names and table field names; Based on the table name and the table field name, and according to a predetermined data migration SQL script generation algorithm, generate a data migration SQL script corresponding to the data migration information; The data migration SQL script is executed in the database to be migrated of the business system to realize data migration.

2. The data migration method according to claim 1, characterized in that: The method of annotating each information table based on a predetermined marking and annotation algorithm to obtain a corresponding table name and table field name includes: Define the Java class corresponding to the entity object of each information table, and define the column names in the information table as attributes of the corresponding Java class; Annotate the table name and table field name of each information table through a predetermined annotation framework; The table name marked with annotations corresponding to the Java class and the table field name marked with annotations corresponding to the attributes of the Java class are obtained through the Java reflection mechanism.

3. The data migration method according to claim 2, characterized in that: The method of annotating and marking the table name and table field name of each information table by a predetermined annotation framework includes: Get the table name of each information table and the table field name corresponding to each column in the table; Annotating and marking the table name by a table name annotation command in a predetermined annotation framework; The table field name is annotated and marked by a table field name annotation command in a predetermined annotation framework.

4. The data migration method according to claim 2, characterized in that: The obtaining, through the Java reflection mechanism, the table name of the annotation mark corresponding to the Java class and the table field name of the annotation mark corresponding to the attribute of the Java class includes: Obtain the corresponding entity object through the Java class, and obtain the table name of the annotation mark corresponding to the entity object; The table field names marked with annotations corresponding to all the attributes of the Java class are obtained through the field value acquisition method of the entity object.

5. The data migration method according to claim 1, characterized in that: The step of generating a data migration SQL script corresponding to the data migration information based on the table name and the table field name and according to a predetermined data migration SQL script generation algorithm includes: Traverse the table names and table field names marked with annotations to obtain the table names and table field names corresponding to the data migration information; Generate a data migration SQL text for each information table corresponding to the data migration information according to the table name and table field name corresponding to the data migration information; The data migration SQL texts of multiple information tables are concatenated to obtain a data migration SQL script corresponding to the data migration information.

6. The data migration method according to claim 5, characterized in that: The step of generating the data migration SQL text for each information table corresponding to the data migration information according to the table name and table field name corresponding to the data migration information includes: Obtain a corresponding data migration SQL statement template according to the table name corresponding to the data migration information; The field value of the table name and the field value of the table field name corresponding to the data migration information are filled into the data migration SQL statement template to obtain the data migration SQL text of each information table corresponding to the data migration information.

7. The data migration method according to claim 5, characterized in that: The step of concatenating the data migration SQL texts of the multiple information tables to obtain a data migration SQL script corresponding to the data migration information includes: Merge the data migration SQL texts corresponding to each information table by string concatenation to obtain the data migration SQL script; The data migration SQL script is converted into a bit stream and exported to an Http response, so that the database to be migrated in the business system can download and use the data migration SQL script.

8. A data migration device, characterized in that: The data migration device comprises: The data acquisition module is used to obtain data migration information through the data migration page of the business system; An annotation module, used for obtaining multiple information tables corresponding to the data migration information from the database to be migrated from the business system, and annotating each information table based on a predetermined marking algorithm to obtain a corresponding table name and table field name; A script generation module, configured to generate a data migration SQL script corresponding to the data migration information based on the table name and the table field name and according to a predetermined data migration SQL script generation algorithm; The data migration module is used to execute the data migration SQL script in the database to be migrated in the business system to realize data migration.

9. A server, characterized in that: The server comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data migration method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data migration method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Data migration method and device, computer equipment and storage medium

    CN110297813A

  • Custom metadata and persistent instance mapping method

    CN113721891A

  • Script-based data batch transplantation method and system

    CN114546395A