CFMigrations question. I have a need to dynamicall...
# box-products
r
CFMigrations question. I have a need to dynamically set a datasource when running migrations. I came up with the below solution and I am curios to see if anyone has any comments.
Copy code
var migrationService = getInstance( "migrationService:core" );		
migrationService.getManager().setDatasource('someOtherDatasource');
migrationService.runAllMigrations('up');
w
Did you try your solution? I think it should just work, if your datasource is present. I built a special app to sync multiple datasources so I created a separate manager for every datasource. But that were only 5 datasources. If you are using the default QBmigrationmanager there are more ways to do this. You could change the datasource on the fly in an interceptor based on some value in the prc or rc, e.g.
Copy code
/**
     * preQBExecute
     */
    function preQBExecute( event, data, buffer, rc, prc ){
        var thisDataSource = event.getPrivateValue( "mainDatasource","" );
        if ( len( thisDataSource) && !data.options.keyExists("dataSource") ){
            data.options["dataSource"] = thisDataSource;
        }
    }
In this case there is no default datasource and if nobody has set the datasource yet, I set it to the value of
prc.mainDatasource
r
Thanks @wil-shiftinsert