Re: Migrations not executed at startup problem (SOLVED)
Re: Migrations not executed at startup problem (SOLVED)
- Subject: Re: Migrations not executed at startup problem (SOLVED)
- From: Chuck Hill <email@hidden>
- Date: Wed, 06 Apr 2011 14:46:16 -0700
Another good reason to choose #1!
On Apr 6, 2011, at 2:41 PM, Jon Nolan wrote:
> This is a bit of an aside probably not relevant to most but be warned that ApplicationDidFinishLaunchingNotification does not fire under servlet deployment.
>
> On 4/6/11 3:37 PM, Amedeo Mantica wrote:
>> Hi Miguel,
>>
>> you are having the same trouble I had some time ago.
>> i solved using an NSNotification "ApplicationDidFinishLaunchingNotification" as Chuck is suggesting you.
>>
>> take a look at ERXSelectorUtilities.notificationSelector that is more easier to use then NSSelector.
>>
>> Regards
>> Amedeo
>>
>> You have the trouble in a framework or in the app ?
>>
>>
>> On 06/apr/2011, at 23.03, Miguel Angel Torres Avila wrote:
>>
>>> Thanks Chuck,
>>>
>>> I will search for more info to learn how useful can be the notifications.
>>>
>>> This is new to me.
>>>
>>>
>>>
>>> On Apr 6, 2011, at 2:34 PM, Chuck Hill wrote:
>>>
>>>> Time to learn! :-)
>>>>
>>>> Add this to your app:
>>>>
>>>> public final void didFinishInitialization(NSNotification n) {
>>>> // Your code here!
>>>> }
>>>>
>>>> And in your constructor add:
>>>> NSNotificationCenter.defaultCenter().addObserver(this, new NSSelector("didFinishInitialization", ERXConstant.NotificationClassArray), ApplicationDidFinishInitializationNotification, null);
>>>>
>>>>
>>>> Chuck
>>>>
>>>>
>>>> On Apr 6, 2011, at 12:30 PM, Miguel Angel Torres Avila wrote:
>>>>
>>>>> Thanks
>>>>>
>>>>> I changed to option 2 because I am not sure how option 1 works :P.
>>>>>
>>>>>
>>>>>
>>>>> On Apr 6, 2011, at 2:21 PM, Mike Schrag wrote:
>>>>>
>>>>>> I highly recommend option 1 or 2 ... The exact timing of migrations was chosen with some care. Moving it around is probably a path to sadness.
>>>>>>
>>>>>> On Apr 6, 2011, at 3:10 PM, John Huss wrote:
>>>>>>
>>>>>>> But when didFinishLaunching happens the app is already accepting requests (if concurrent handling is turned on), isn't it? I thought so; if so, that's not a good place to do something that your app requires to run correctly.
>>>>>>>
>>>>>>> John
>>>>>>>
>>>>>>> On Wed, Apr 6, 2011 at 2:02 PM, Miguel Angel Torres Avila <email@hidden <mailto:email@hidden>> wrote:
>>>>>>>
>>>>>>> Thanks Chuck, I implemented the third option and worked like a charm!
>>>>>>>
>>>>>>>
>>>>>>> On Apr 6, 2011, at 1:46 PM, Chuck Hill wrote:
>>>>>>>
>>>>>>>> I will suggest not doing that in a Wonder app. :-) I think you should move the code. There are a few choices:
>>>>>>>>
>>>>>>>> 1. Use this notification:
>>>>>>>> /**
>>>>>>>> *Notificationtopostwhenallapplicationinitializationprocessesarecomplete(includingmigrations)
>>>>>>>> */
>>>>>>>> publicstaticfinalString ApplicationDidFinishInitializationNotification= "NSApplicationDidFinishInitializationNotification";
>>>>>>>>
>>>>>>>>
>>>>>>>> 2. Use this method:
>>>>>>>> /**
>>>>>>>> *Calledaftermigrationsfinishrunning.
>>>>>>>> *@parammigratorthemigratorthatwasused
>>>>>>>> */
>>>>>>>> protected void migrationsDidRun(ERXMigrator migrator) {
>>>>>>>> // DO NOTHING
>>>>>>>> }
>>>>>>>>
>>>>>>>> 3. Use this method:
>>>>>>>> /**
>>>>>>>> *Calledwhentheapplicationposts
>>>>>>>> *{@link WOApplication#ApplicationDidFinishLaunchingNotification}.
>>>>>>>> *Overridethistoperformapplicationspecifictasksaftertheapplication
>>>>>>>> *hasbeeninitialized.THisisagoodspottoperformbatchapplication
>>>>>>>> *tasks.
>>>>>>>> */
>>>>>>>> public void didFinishLaunching() {
>>>>>>>> }
>>>>>>>>
>>>>>>>> Chuck
>>>>>>>>
>>>>>>>>
>>>>>>>> On Apr 6, 2011, at 11:07 AM, Miguel Angel Torres Avila wrote:
>>>>>>>>
>>>>>>>>> Thanks Chuck, Paul and Mike for your help
>>>>>>>>>
>>>>>>>>> The principal problem was that Migrations functionality is called automatically after my own code that loads some info from de data base, so if the migration has changes in a table that is considered in my code the app crashes before the migration occurs.
>>>>>>>>>
>>>>>>>>> The solution is to add the Chuck's code before everything else in the constructor of my Application class.
>>>>>>>>>
>>>>>>>>> if (ERXMigrator.shouldMigrateAtStartup())
>>>>>>>>> {
>>>>>>>>> try
>>>>>>>>> {
>>>>>>>>> migrator().migrateToLatest();
>>>>>>>>> }
>>>>>>>>> catch (ERXMigrationFailedException e)
>>>>>>>>> {
>>>>>>>>> // It might be a missing plugin problem
>>>>>>>>> new ERXJDBCConnectionAnalyzer(databaseConnectionDictionary());
>>>>>>>>> throw e;
>>>>>>>>> }
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Apr 6, 2011, at 12:51 PM, Paul D Yu wrote:
>>>>>>>>>
>>>>>>>>>> Look at the _dbupdater table in your database.
>>>>>>>>>>
>>>>>>>>>> It should have a row in there with your EOModel name in it; set the version back to null.
>>>>>>>>>>
>>>>>>>>>> Paul
>>>>>>>>>>
>>>>>>>>>> On Apr 6, 2011, at 1:43 PM, Mike Schrag wrote:
>>>>>>>>>>
>>>>>>>>>>> More than likely you've already run once, and the migration did nothing, so it succeeded, and it's not going to run it again unless you modify the data in the migration version table to reset it back.
>>>>>>>>>>>
>>>>>>>>>>> On Apr 6, 2011, at 1:24 PM, Miguel Angel Torres Avila wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Thanks Paul
>>>>>>>>>>>>
>>>>>>>>>>>> For some reason the code inside the upgrade class is never called.
>>>>>>>>>>>>
>>>>>>>>>>>> I think I should mistyped something. I am checking now.
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Apr 6, 2011, at 12:16 PM, Paul D Yu wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Miguel
>>>>>>>>>>>>>
>>>>>>>>>>>>> You will need to call the external sql script from inside of your Migration.java file.
>>>>>>>>>>>>>
>>>>>>>>>>>>> @Override
>>>>>>>>>>>>> public void upgrade(EOEditingContext editingContext, ERXMigrationDatabase database) throws Throwable {
>>>>>>>>>>>>> ERXJDBCUtilities.executeUpdateScriptFromResourceNamed(database.adaptorChannel(), "*DInAdminEOModel1_Postgresql_Upgrade.migration*", "DIModelFramework");
>>>>>>>>>>>>> }
>>>>>>>>>>>>>
>>>>>>>>>>>>> Something like that?
>>>>>>>>>>>>>
>>>>>>>>>>>>> Paul
>>>>>>>>>>>>> On Apr 6, 2011, at 1:07 PM, Chuck Hill wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Is this a "full" Wonder app, extending ERXApplication? If not, you need to initiate the migration:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> if (ERXMigrator.shouldMigrateAtStartup())
>>>>>>>>>>>>>> {
>>>>>>>>>>>>>> try
>>>>>>>>>>>>>> {
>>>>>>>>>>>>>> migrator().migrateToLatest();
>>>>>>>>>>>>>> }
>>>>>>>>>>>>>> catch (ERXMigrationFailedException e)
>>>>>>>>>>>>>> {
>>>>>>>>>>>>>> // It might be a missing plugin problem
>>>>>>>>>>>>>> new ERXJDBCConnectionAnalyzer(databaseConnectionDictionary());
>>>>>>>>>>>>>> throw e;
>>>>>>>>>>>>>> }
>>>>>>>>>>>>>> }
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Chuck
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Apr 6, 2011, at 9:47 AM, Miguel Angel Torres Avila wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi all,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I am trying to implement Migrations in an existing Application.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I followed the instructions in this page:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> http://webobjects.mdimension.com/hudson/job/Wonder/javadoc/er/extensions/migration/package-summary.html
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> and this one
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> http://webobjects.mdimension.com/hudson/job/Wonder/javadoc/er/extensions/migration/ERXMigration.html
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> I think the steps are:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> *1. Modify properties file:*
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> # Migrations
>>>>>>>>>>>>>>> er.migration.migrateAtStartup=true
>>>>>>>>>>>>>>> er.migration.createTablesIfNecessary=true
>>>>>>>>>>>>>>> er.migration.modelNames=DInAdminEOModel
>>>>>>>>>>>>>>> er.extensions.migration.ERXMigration.useDatabaseSpecificMigrations=true
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> DInAdminEOModel.InitialMigrationVersion=1
>>>>>>>>>>>>>>> DInAdminEOModel.MigrationClassPrefix=com.toracom.app.migration.DInAdminEOModel
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> *2. Create class **com.toracom.app.migration.DInAdminEOModel1.java*
>>>>>>>>>>>>>>> *
>>>>>>>>>>>>>>> *
>>>>>>>>>>>>>>> /////// BEGIN CLASS
>>>>>>>>>>>>>>> package com.toracom.app.migration;
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> import com.webobjects.eoaccess.EOAdaptorChannel;
>>>>>>>>>>>>>>> import com.webobjects.eoaccess.EOModel;
>>>>>>>>>>>>>>> import com.webobjects.eocontrol.EOEditingContext;
>>>>>>>>>>>>>>> import com.webobjects.foundation.NSArray;
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> import er.extensions.migration.ERXMigration;
>>>>>>>>>>>>>>> import er.extensions.migration.ERXModelVersion;
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> public class DInAdminEOModel1 extends ERXMigration {
>>>>>>>>>>>>>>> public NSArray<ERXModelVersion> modelDependencies() {
>>>>>>>>>>>>>>> returnnull;
>>>>>>>>>>>>>>> }
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> @Override
>>>>>>>>>>>>>>> public void upgrade(EOEditingContext editingContext, EOAdaptorChannel channel, EOModel model) throws Throwable {
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> }
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> @Override
>>>>>>>>>>>>>>> public void downgrade(EOEditingContext editingContext,EOAdaptorChannel channel, EOModel model) throws Throwable {
>>>>>>>>>>>>>>> // TODO Auto-generated method stub
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> }
>>>>>>>>>>>>>>> }
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ////// END CLASS
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> *3. Create DInAdminEOModel1_Postgresql_Upgrade.migration file*
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ALTER TABLE parametros ADD COLUMN modulo_cfdivault_habilitado varchar(5);
>>>>>>>>>>>>>>> UDPATE parametros SET modulo_cfdivault_habilitado = 'false';
>>>>>>>>>>>>>>> ALTER TABLE parametros ALTER COLUMN modulo_cfdivault_habilitado SET NOT NULL;
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> When I run my application never get the SQL code executed. In the Application class I load a Parametros entity but I get the following error
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Apr 06 11:38:11 dinadmin[55559] DEBUG NSLog - evaluateExpression: <com.webobjects.jdbcadaptor.PostgresqlExpression: "SELECT DISTINCT t0.directorio_raiz_procesamiento_cfd, t0.email_formato, t0.encoding_archivo_fuente, t0.encoding_escritura_cfd, t0.encoding_escritura_div_sol, t0.encoding_escritura_xml_co, t0.encoding_escritura_xml_impresion, t0.encoding_lectura_jaxb, t0.encoding_obtencion_co, t0.encoding_trans_co, t0.fh, t0.fhc, t0.formato_fecha_dhtmlxgrid, t0.formato_numero_registro_bd, t0.formato_numero_registro_bd_corto, t0.fsh, t0.fshnm, t0.iva, t0.logs_debug, t0.logs_path, t0.logs_stdout, t0.metodo_impresion, t0.modulo_cfdivault_habilitado, t0.moneda_id, t0.nd, t0.ne <http://t0.ne/>, t0.nm, t0.nombre_aplicacion, t0.np <http://t0.np/>, t0.ntc, t0.parametros_id, t0.retraso_daemon, t0.rfc_fisica, t0.rfc_moral, t0.sistema_inicializado, t0.url_birt_viewer, t0.version_comprobante FROM parametros t0" withBindings: >
>>>>>>>>>>>>>>> Apr 06 11:38:11 dinadmin[55559] DEBUG NSLog - === Rollback Internal Transaction
>>>>>>>>>>>>>>> ERROR: column t0.modulo_cfdivault_habilitado does not existat org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1608)
>>>>>>>>>>>>>>> at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1343)
>>>>>>>>>>>>>>> at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:194)
>>>>>>>>>>>>>>> at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
>>>>>>>>>>>>>>> at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:336)
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Because the modulo_cfdivault_habilitado column does not exist, so the migration's file is never executed.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Am I missing something, maybe a missing Framework?
>>>>>>>>>>>>>>> *
>>>>>>>>>>>>>>> *
>>>>>>>>>>>>>>> Thanks in advance.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> -- Chuck Hill Senior Consultant / VP Development
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
>>>>>>>>>>>>>> http://www.global-village.net/products/practical_webobjects
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>>>>>
>>>>>>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>>>>
>>>>>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>>>
>>>>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>>>
>>>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>>
>>>>>>>> -- Chuck Hill Senior Consultant / VP Development
>>>>>>>>
>>>>>>>> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
>>>>>>>> http://www.global-village.net/products/practical_webobjects
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>
>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>>
>>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>
>>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________
>>>>> Ing. Miguel Angel Torres Avila
>>>>> Director General
>>>>> Tel: +52 (33) 3367 1892
>>>>> Cel: +52 (33) 3106 8758
>>>>> E-mail: email@hidden <mailto:email@hidden>
>>>>> www.toracom.net <http://www.toracom.net/>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Do not post admin requests to the list. They will be ignored.
>>>>> Webobjects-dev mailing list (email@hidden <mailto:email@hidden>)
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>
>>>>> This email sent to email@hidden <mailto:email@hidden>
>>>>
>>>> --
>>>> Chuck Hill Senior Consultant / VP Development
>>>>
>>>> Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
>>>> http://www.global-village.net/products/practical_webobjects
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>> _______________________________
>>> Ing. Miguel Angel Torres Avila
>>> Director General
>>> Tel: +52 (33) 3367 1892
>>> Cel: +52 (33) 3106 8758
>>> E-mail: email@hidden <mailto:email@hidden>
>>> www.toracom.net <http://www.toracom.net/>
>>>
>>> Antes de imprimir, piense en el Medio Ambiente. Before printing think about the Environment. Avant d'imprimer, pensez à l'Environnement
>>>
>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list (email@hidden <mailto: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
--
Chuck Hill Senior Consultant / VP Development
Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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