Some embodiments relate to database systems. In particular, some embodiments are associated with hybrid database version upgrade migrations.
New database versions may occasionally be provided. For example, a new database version may add another column to a table or fix a problem that was detected with respect to the database. In some cases, conflicting database versions may cause updates to fail. Manually coordinating the migration of new database versions can be a time consuming and error-prone task, especially when a substantial number of versions are involved. For example, new versions may be provided on a daily basis in a development or testing environment. As a result, systems and methods to automatically and accurately migrate database version may be desired.
Note that various elements of database services 170 may occasionally need to be upgraded to newer versions. For example, a patch may fix an existing problem or a new release may add a new feature. To facilitate movement to the newer versions, a database migration tool 180 may be provided. By way of example only, the FLYWAY database migration tool from GOOGLE® may be used, although embodiments may be associated with other database migration tools or platforms.
Note that when upgrading a cloud solution, both the solution binary files and the application database itself may need to be updated. For example, a database upgrade may include both pure a Structured Query Language (“SQL”) update and data migration (resulting in a “hybrid” database migration). Note that an SQL update may typically be represented with an ordered set of SQL files and data migration may be manipulated by code (e.g., by migrating data with Java code).
The database migration tool 180 may facilitate such a database migration. For example,
A simple sequential execution of the upgrade migrations 310, 320, 330 may cause several problems. For example, execution of the “Create Table T_1” SQL portion will place the database into a first state. Execution of the DataContentMigrateForTableT_1” data portion will place the database into a second state, and execution of the AlterTableT_1_Add(C_3) will add a third column to the database placing it into a third state. Generally, in an advanced cloud solution, a logic layer may use a framework (e.g., IBatis, Hibrate, Spring, etc.) to query the database instead of using Java Database Connectivity (“JDBC”) directly. As a result, Java code and application database schema may always need to be consistent. For example, the binary associated with the third database state requires column C_3 to exist in the database. When the version migrations 310, 320, 330 are executed in order, execution of DataContentMigrateForTableT_1 may fail. For example, when querying T_1 from the database the database framework may generate an SQL such as “SELECT C_1, C_2, C_3 FROM T_1,” in which case a runtime exception will be thrown because column C_3 does not yet exist in T_1. That is, column C_3 won't be added to table T_1 until the V1_01_002 migration is performed. This kind of error can be difficult to find until a real migration is actually run. Moreover, when a substantial number of versions are available, it can be impractical to test for these kinds of upgrade scenario combinations.
An additional problem with sequential execution of upgrade migrations 310, 320, 330 may arise when a migration fails in during a multi-tenant database migration. Note that some cloud solutions may let all tenants share a database and manage tenant level security in Java code. In order to achieve higher security, Data Service On Demand (“DSOD”) may store application data of each tenant to a standalone schema, which might be located in different database servers. For a single schema migration, a transaction manager may provide a sufficient rollback mechanism. However, a transaction manager may not be able to manage rollbacks that cross multiple schemas, databases, and/or servers. Consider, for example, a scenario with tenant_1, tenant_2, and tenant_3. Each of these tenants has a standalone schema with the same name. Possible migration code may be as follows:
In this case, if the migration of tenant_2 fails, the tenant_1 schema may be in the up-to-date version while tenant_2 and tenant_3 schema remain in a prior version, which may require a difficult manual fix to make all tenant schemas consistent again.
At S410, it may be determined that a plurality of hybrid database version upgrade migrations are to be performed, each upgrade migration including a schema change portion (e.g., an SQL portion) and a data change portion (e.g., a Java code portion). Note that hybrid database version upgrade migration might be associated with, for example, a development environment, a test environment, a production environment, an initial database version, a patch, a new release, and/or a new database feature. Moreover, embodiments may be associated with a cloud environment and/or a transaction manager that provide multi-tenant functionality for the hybrid database version upgrade migration. Note that the determination at S410 might be associated with, for example, a startup process, an administrator, a developer, a periodic process, and/or an arrival of a new hybrid database version upgrade migration.
At S420, a first database migration tool instance may be automatically run to perform the upgrade migration schema change portions. Similarly, at S430, a second database migration tool instance may be automatically run to perform the upgrade migration data change portions, wherein the second instance is not run until the first instance is complete. Note that the first and second instances may use independent metadata schema tables to track migrated versions. Moreover, each schema change portion and data change portion may be associated with a version number, and the first instance may perform the schema change portions in order based on the version number, beginning with the first version number that is not in the metadata schema table associated with the schema change portions. Likewise, the second instance may perform the data change portions in order based on the version number, beginning with the first version number that is not in the metadata schema table associated with the data change portions.
According to some embodiments, prior to running the instances at S420 and S430, the system may establish a schema change file repository to store schema change migration code, a data change file repository to store data change migration code, and an SQL file repository to store statements to be executed by the database migration tool. In some cases, the schema and/or data change file repositories may further store migration rollback code. If so, upon an exception associated with one of hybrid database version upgrade migrations, the migration rollback code may be executed such that all tenants in a multi-tenant implementation are associated with the same database version.
In this way, embodiments described herein may provide a relatively straightforward way to upgrade a database from any lower version (or from scratch) to any higher version.
For example, two migration tool instances 510, 530 may be run as illustrated by the example 500 of
Note that the two instances 510, 530 may use two independent tables:
Consider, as an example, updating a database from scratch to version V1_01_002. That is, both SCHEMA_VERSION_SQL_MIGRATE 520 and SCHEMA_VERSION_CODE_MIGRATE 540 are initially empty. In this case, a first database migration tool instance may then be run to process SQL_Migration_DIR 610. The java files may be executed sequentially, starting with the first java file not listed in the SCHEMA_VERSION_SQL_MIGRATE 520. For example, “V1_01_001_CreateTableT_1.java” may place the database in the first database state described with respect to
After the first database migration tool instance completes, a second instance may be run to process Java_Migration_DIR. The java files may again be executed sequentially, starting with the first java file not listed in the SCHEMA_VERSION_CODE_MIGRATE 540. For example, “V1_01_001_DataConentMigrateForTableT_1.java” may place the database in the second database state described with respect to
According to some embodiments, developers may provide a rollback SQL file associated with each SQL migration part. For example, V1_01_002_AddColC_3ToT_1.sql and V1_0_01_002_AddColC_3ToT_1_rollback.sql might both exist in SQL_DIR 630. As another example, if an upgrade SQL has “ALTER TABLE T_1 ADD(C_1 . . . );”, the rollback SQL might have “ALTER TABLE T_1 DROP (C_1);”.
In a java class extending the database migration tool, the following logic might be provided to support version rollbacks:
When a column or a table is deleted which is used by the java code of an earlier version of SCHEMA_VERSION_CODE MIGRATE 540, a Java compiler may capture this incompatible and a developer can address the situation in implementation stage. Such an approach may be substantially less than dealing with an exception thrown after the database is deployed. Similarly, developers may be instructed that a column can only be altered from a smaller volume to a bigger one (e.g., from varchar(100) to varchar(1000)) to avoid migration process problems.
The apparatus 700 includes a processor 710 operatively coupled to a communication device 720, a data storage device 730, one or more input devices 740, one or more output devices 750 and a memory 760. The communication device 720 may facilitate communication with external devices, such as a remote client or database device. The input device(s) 740 may comprise, for example, a keyboard, a keypad, a computer mouse or other pointing device, a microphone, an infra-red (IR) port, a docking station, and/or a touch screen. The input device(s) 740 may be used, for example, to enter information about upgrade migrations into apparatus 700. The output device(s) 750 may comprise, for example, a display (e.g., a display screen) a speaker, and/or a printer and may be used to generate logs, reports, etc.
The data storage device 730 may comprise any appropriate persistent storage device, including combinations of magnetic storage devices (e.g., magnetic tape, hard disk drives and flash memory), optical storage devices, Read Only Memory (“ROM”) devices, etc., while memory 760 may comprise Random Access Memory (“RAM”).
Program code of a migration engine 732 may be executed by the processor 710 to cause the apparatus 700 to perform any one or more of the processes described herein. Embodiments are not limited to execution of these processes by a single apparatus. The data storage device 730 may also store data and other program code for providing additional functionality and/or which are necessary for operation thereof, such as device drivers, operating system files, etc. For example, the processor 710 may determine that a plurality of hybrid database version upgrade migrations are to be performed, each upgrade migration including a schema change portion and a data change portion. The processor 710 may then run a first database migration tool instance to perform the upgrade migration schema change portions. The processor 710 may also run a second database migration tool instance to perform the upgrade migration data change portions, wherein the second instance is not run until the first instance is complete.
Note that the data storage device 730 may further store SQL_Migration_DIR 770, Java_Migration_DIR 780, and SQL_DIR 790.
Referring to
The version identifier 802 may be, for example, a unique alphanumeric code identifying an upgrade. The version identifier 802 may be used, for example, to select which updates will be applied to a database. The description 804 may described the update and the type 806 might indicate, for example, if the update is associated with the database scheme or data. The script 808 might be an SQL statement and the installed date 810 might indicate when the SQL statement was executed. The success indication 812 might indicate that the upgrade was successfully applied or that a problem occurred in connection with the migration.
The foregoing diagrams represent logical architectures for describing processes according to some embodiments, and actual implementations may include more or different components arranged in other manners. Other topologies may be used in conjunction with other embodiments. Moreover, each system described herein may be implemented by any number of devices in communication via any number of other public and/or private networks. Two or more of such computing devices may be located remote from one another and may communicate with one another via any known manner of network(s) and/or a dedicated connection. Each device may comprise any number of hardware and/or software elements suitable to provide the functions described herein as well as any other functions. For example, any computing device used in an implementation of the system 100 may include a processor to execute program code such that the computing device operates as described herein.
All systems and processes discussed herein may be embodied in program code stored on one or more computer-readable media. Such media may include, for example, a floppy disk, a CD-ROM, a DVD-ROM, a Flash drive, magnetic tape, and solid state Random Access Memory (RAM) or Read Only Memory (ROM) storage units. Embodiments are therefore not limited to any specific combination of hardware and software.
Elements described herein as communicating with one another are directly or indirectly capable of communicating over any number of different systems for transferring data, including but not limited to shared memory communication, a local area network, a wide area network, a telephone network, a cellular network, a fiber-optic network, a satellite network, an infrared network, a radio frequency network, and any other type of network that may be used to transmit information between devices. Moreover, communication between systems may proceed over any one or more transmission protocols that are or become known, such as Asynchronous Transfer Mode (“ATM”), Internet Protocol (“IP”), Hypertext Transfer Protocol (“HTTP”) and Wireless Application Protocol (“WAP”).
Embodiments described herein are solely for the purpose of illustration. Those in the art will recognize other embodiments may be practiced with modifications and alterations to that described above.
Number | Name | Date | Kind |
---|---|---|---|
6119130 | Nguyen | Sep 2000 | A |
6460052 | Thomas | Oct 2002 | B1 |
7792800 | Carson, Jr. | Sep 2010 | B1 |
8571882 | Teitelbaum | Oct 2013 | B1 |
20140189677 | Curzi | Jul 2014 | A1 |
20140337282 | Mesika | Nov 2014 | A1 |
Number | Date | Country | |
---|---|---|---|
20150363452 A1 | Dec 2015 | US |