• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Migrations (was: ERXSQLHelper)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Migrations (was: ERXSQLHelper)


  • Subject: Migrations (was: ERXSQLHelper)
  • From: OC <email@hidden>
  • Date: Tue, 13 Jan 2015 00:46:34 +0100

Chuck,

On 13. 1. 2015, at 0:37, Chuck Hill <email@hidden> wrote:

>> Can you please point me to some howto? To be frank, I have absolutely no idea what “migration” is. (Truth is, I must be missing something pretty obvious at the documentation side: whilst I can find my way in WOnder if I know what exactly to search for, so far, I haven't found anything which would help me to find a support for some general functionality, unless 'find wonderdoc | xargs fgrep thedesiredthing' helps, which it very often does not. Consider my current case -- I need to sync tables to model /more details below/, and perhaps I'm just dumb, but "migration" is about the very last word I would search for, to fulfill that need?!? I don't migrate anything to anywhere; all I need is to synchronize the database to the model.)
>
> *cough* JavaDoc
>
> https://github.com/wocommunity/wonder/blob/master/Frameworks/Core/ERExtensions/Sources/er/extensions/migration/package.html

Well meantime I've googled out http://webobjects.mdimension.com/hudson/job/Wonder/javadoc/er/extensions/migration/package-summary.html which looks like the very same doc, just readable :)

But after first going through I am none the smarter and it does not seem to me it would help. Perhaps I am completely missing the point, but seems to me this is intended to a completely different task than the one of mine? Might be wrong, so far, I do not quite get what the migration stuff does, not speaking of the slightest idea how could I exploit it. I do not have versions (unless you simply define „any change in DB makes a new version“, in which case of course I have them, but this does not seem to help), and I neither "upgrade" nor "downgrade" anything.

>> Anyway, my workflow is this
>>
>> (a) I open the database and read from there some dynamic information (works OK)
>> (b) based on this information, I add a number of dynamic EOAttributes to my model (works OK too)
>> (c) at this moment, I need to sync the DB and model, namely
>> - adding columns to the database for EOAttributes which do not have any
>> - removing colums from the database for which there are no EOAttributes
>> - removing and re-adding columns for which there are EOAttributes of an incompatible kind
>>
>> If the migration thing can do this, it would be just great.
>>
> Migrations is only intended to run at a very early place in app startup.

Well... this version of my app _does_ do that at startup only, but future versions definitely should be able to re-read the data -- (a) -- and re-do the synchronization of model -- (b) -- and database -- (c) -- essentially at any time (of course, locking completely out all other instances when it is being done).

Thanks a lot,
OC

> On Jan 12, 2015, at 2:18 PM, OC <email@hidden> wrote:
> P.S. my current environment is
> Groovy 2.3.8 / WebObjects 5.4.3 / ERExtensions 6.1.2-SNAPSHOT / Java 1.7.0_13 / Mac OS X 10.8.5 / FrontBase 7.2
> On 12. 1. 2015, at 22:56, OC <email@hidden> wrote:
> Theodore,
> On 12. 1. 2015, at 19:00, Theodore Petrosky <email@hidden> wrote:
> have you looked at the migrations?
> ERXMigrationTable personTable = database.existingTableNamed("person");
> personTable.existingColumnNamed("Foo").renameTo("Bar”);
> personTable.newStringColumn(name, width, allowsNull)
> well... the API looks OK, but in practice it does not seem quite work. Can you (or anybody knowledgeable) please point out what am I doing wrong? Here's my code (sans error checking etc. for better readability)
> ===
>       EOObjectStoreCoordinator osc=EOObjectStoreCoordinator.defaultCoordinator()
>       EODatabaseContext ctxt=ERXEOAccessUtilities.databaseContextForEntityNamed(osc,'DBAuction')
>       ctxt.lock();
>       try {
>           EOAdaptorChannel ach = ctxt.availableChannel().adaptorChannel();
>           if (!ach.isOpen()) ach.openChannel();
>           def tables=ach.describeTableNames() // looks like Migration API does not read the current state reliably
>           EOModel dbModel=ach.describeModelWithTableNames(tables)
>           ERXMigrationDatabase mdb=nil // created on-demand
>           mdg.models.each { EOModel localModel ->
>               localModel.entities.each { EOEntity localEntity ->
>                   if (localEntity.isAbstractEntity()) return
>                   String tname=localEntity.externalName()
>                   EOEntity dbEntity=dbModel.entityNamed(tname)
>                   ERXMigrationTable mtable=nil // on-demand
>                   localEntity.attributes.each { EOAttribute localAttribute ->
>                       String cname=localAttribute.columnName()
>                       EOAttribute dbAttribute=dbEntity.attributeNamed(cname)
>                       if (!dbAttribute) {
>                           println "  adding column $cname ($localAttribute.name): $localAttribute.externalType (VT: $localAttribute.valueType) ..."
>                           if (!mdb) mdb=ERXMigrationDatabase.database(ach)
>                           if (!mtable) mtable=mdb.existingTableNamed(tname)
>                           switch (localAttribute.externalType) {
> ...
>                               case 'TIMESTAMP':
>                                   mtable.newTimestampColumn(cname,YES)
>                                   break
>                           }
>                           println "  - OK"
>                       }
>                   }
>               }
>           }
>       } finally {
>           ctxt.unlock()
>       }
> ===
> but it crashes, printing out
> ===
> adding column DC_ID (ID): TIMESTAMP (VT: null) ...
> 22:42:09.409 INFO  Executing alter table T_AUCTION null DC_ID TIMESTAMP       //log:er.extensions.jdbc.ERXJDBCUtilities [main]
> ...
> Caused by: java.lang.RuntimeException: Failed to execute 'alter table T_AUCTION null DC_ID TIMESTAMP'.
> Caused by: java.sql.SQLException: Syntax error 179. Illegal ALTER TABLE statement.
> ===
> Well self-evidently it _is_ an illegal statement, it lacks "add column" having "null" instead; but what's the culprit and how to fix the problem?
> (Note: I've tried to bump up log levels to
> log4j.logger.er.extensions.jdbc.ERXJDBCUtilities=TRACE
> log4j.logger.er.extensions.migration.ERXMigrationDatabase=TRACE
> log4j.logger.er.extensions.migration.ERXMigrationTable=TRACE
> log4j.logger.er.extensions.migration.ERXMigrationColumn=TRACE
> but no more logs occurred anyway.)
> Thanks,
> OC
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> This email sent to email@hidden
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> This email sent to email@hidden
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Migrations (was: ERXSQLHelper)
      • From: Paul Hoadley <email@hidden>
References: 
 >ERXSQLHelper (From: OC <email@hidden>)
 >Re: ERXSQLHelper (From: Theodore Petrosky <email@hidden>)
 >Re: ERXSQLHelper (From: OC <email@hidden>)
 >Re: ERXSQLHelper (From: OC <email@hidden>)
 >Re: ERXSQLHelper (From: Timothy Worman <email@hidden>)
 >Re: ERXSQLHelper (From: OC <email@hidden>)
 >Re: ERXSQLHelper (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: ERXSQLHelper
  • Next by Date: Re: Migrations (was: ERXSQLHelper)
  • Previous by thread: Re: ERXSQLHelper
  • Next by thread: Re: Migrations (was: ERXSQLHelper)
  • Index(es):
    • Date
    • Thread