node.js - nodejs database migration module -
i looking module migration in node.js application. using sequelize orm. have found couple of solutions such migration in sequelize can't find enough examples adding column(changing schema) or adding enteries table.
could give module complete examples both altering schema adding existing enteries?
my application hosted on heroku please highlight how use on heroku?
thanks
you can , should use sequelize migrations if you're using sequelize in application. library has great documentation handling migrations.
in terms of adding columns sequelize, first create migration through command line. run sequelize -c migration-name. example can be: sequelize -c add_location_to_users.
once run command, you'll find migration file in root directory migrations folder. describe migration should change in database. keep example, here sample method.
migration.addcolumn( 'users', 'location', datatypes.string ) running migration add column 'location' datatype string 'user' table.
http://sequelizejs.com/docs/latest/migrations#functions link take other functions have available sequelize, include changing column, renaming column, renaming table, etc.
in terms of adding entries table, sequelize gives option run create or findorcreate on model. here example user table.
user.create({ name: 'foo', email: 'bar', location: 'new york' }).success(function(user) { console.log(user.location); //this prints users location }) you have access user (the created entry in database) in callback in success(), printed new users location above. instances section of documentation find other methods around dealing instance of classes (or 'entry in database').
Comments
Post a Comment