Greetings,
I am now trying to learn and use migrations for the site I'm working on. The site is currently hosted on an Openbase db, and my dev machine has a MySQL db. I've managed to get it working on my MySQL db (and obviously it already works on the Operbase db). So on my dev machine, I have 2 configurations in the EOModel, one points to Openbase, and the other to MySQL. I want to use Migrations so that I can make changes to the datamodel on the production machine to add minor things like lookup tables instead of strings for states, countries, user types, etc. I added the new attributes and Entities to the model, and pointed them to column names that I intend the migrations to create for me (but which don't currently exist).
What I have done so far is generate a base level model using the original EOModel from the version currently running on the production box. This is named "Playhouse0.java" (and the EOModel is Playhouse.eomodeled). I have created a Playhouse1.java which adds columns to the various tables needing foreign keys to the lookup tables. e.g.
ERXMigrationTable userTable = database.existingTableNamed("USER"); userTable.newIntegerColumn("user_type_id", true);
I then create the new tables, e.g.:
ERXMigrationTable UserTypeTable = database.newTableNamed("USER_TYPE"); UserTypeTable.newIntegerColumn("_rowid", false); UserTypeTable.newLargeStringColumn("type_name", true); UserTypeTable.create(); UserTypeTable.setPrimaryKey("_rowid");
Then set the foreign key:
userTable.addForeignKey("user_type_id", "USER_TYPE", "_rowid");
Then I run an SQL script to create and types and try and point the old User.userType column to the appropriate row:
insert into user_type(_rowid,type_name) values(1,'Admin'),(2,'Patron'),(3,'Chef');
and
UPDATE USER SET USER.USER_TYPE_ID = USER_TYPE._rowid FROM USER INNER JOIN USER_TYPE ON USER_TYPE.NAME = USER.USER_TYPE;
etc. I then have another migration Playhouse2.java which was originally set to set the default values and set the columns to not allow null, and added the following lines to my properties file:
# Migrations er.migration.migrateAtStartup=true er.migration.createTablesIfNecessary=true er.migration.modelNames=Playhouse Playhouse.MigrationClassPrefix=playhousecomedy.com.migrations.Playhouse Playhouse.InitialMigrationVersion=1
When I ran it, initially I got an exception:
"Your EOSynchronizationFactory does not support the required 'modify allows null' operation."
So I commented those lines out (i.e. the ones setting to not allow null), which allowed the app to run. However, when I clicked the admin link to go to a D2W component, it crashed, because it could not find the new columns.
Jun 18 09:02:28 PlayhouseComedy[9001] INFO er.transaction.adaptor.Exceptions - Database Exception occured: Unknown column 't0.user_type_Id' in 'field list'at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
I looked at the MySQL db and indeed, no additional columns or tables were created. This is my first attempt with Migrations, and I'm not an SQL guru, so I modeled that code on other code I saw, but it seems straight forward enough. I can only assume this means that I am missing a fundamental step.
Thanks in advance
Andrew |