MySQL has a lovely feature with foreign keys. In particular one can have a foreign key reference a table in a DIFFERENT database. Apparently liquibase PUKES on this. consider the following simple schema:
/*!40101 SET NAMES utf8 */;
/!40101 SET SQL_MODE=’’/;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=‘NO_AUTO_VALUE_ON_ZERO’ */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /!32312 IF NOT EXISTS/MyDB
/*!40100 DEFAULT CHARACTER SET utf8 */;
USE MyDB
;
DROP TABLE IF EXISTS Users
;
CREATE TABLE Users
(
id
INT(11) NOT NULL AUTO_INCREMENT,
Accounts_id
INT(11) DEFAULT NULL ,
PRIMARY KEY (id
),
KEY fk_Users_Accounts_idx
(Accounts_id
),
CONSTRAINT fk_Staffs_Accounts
FOREIGN KEY (Accounts_id
) REFERENCES AnotherDB
.Accounts
(id
) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8 ;
If you run liquibase generateChangeLog on this schema, then it will die with the following message:
Unexpected error running Liquibase: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Obviously my schema is much more complicated than that. But I have reduced it to this simple problem.
Curiously on my REAL schema, I can make subtle changes to certain other aspects of the schema (e.g. rename a column in some unrelated table). And the generateChangeLog will work! Sort of.
Alas if you look at the output changelog file, you will discover all the tables are created with no column definitions added. It does do other things in the resultant XML - like generated indices…But of course if you try to do something like :changeLogSync - it barfs with a bunch of errors - specifically because the columns are all null.
Any comments/suggestions from others on this bug?
Jim