automigrate / autoupdate

55 views
Skip to first unread message

Moez Ben Aissa

unread,
Feb 26, 2015, 9:29:25 AM2/26/15
to loopb...@googlegroups.com
Hi all,

I have write a method to create all my models. 
now, I want to write the method that update my models. (delete a tables, a field ... add proertie to a field...)

code expl : 

var app = require(process.cwd() + '/server/server.js');
var dataSource = app.dataSources.mysql;
var configfile = process.cwd() + '/server/model-config.json';
var models = require(configfile);
var l = Object.keys(models).length;

 var i = 0;

 Object.keys( models ).forEach( function( model ){
    i = i + 1;

    if(models[model].dataSource === 'mysql'){
        console.log("try to update model : " + model);
        dataSource.autoupdate( model, function(){
        console.log('Table ' + v + ' has been updated ('+i+'/'+l+').' );
      });
    }else{
        console.log('warning : Table --> '+ model +' is ignored, it dont have the dataSource  --> '+ models[model].dataSource);
    }  
 });


I have used also this : 

function callback(err) {
      if (err) {
        console.log('Error :  Problem when updating the table ' + tableName);            
      }else{
      console.log('Info :  autoupdate the table  : ' +tableName);   
      }
    }
var tableName;

for (var model in models) {
tableName = model;
      if(models[model].dataSource === 'mysql'){
     dataSource.automigrate(tableName, callback);
        }
        else {
          console.log('warning : Table --> '+ tableName +' is ignored, it dont have the dataSource  --> '+ models[model].dataSource);
        }
    }   


Prb : 
There is no changes after the execution of this script in the database!!!!
Does the methd "autoupdate" do what I expected?

Thanks in advance.



Moez Ben Aissa

unread,
Feb 26, 2015, 9:32:59 AM2/26/15
to loopb...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages