I created an app in NodeJS using ExpressJS, I hosted my app on AppFog and it works, however, I made a few update on my local version, now I'd like to update my App on AppFog but I got a problem, because I updated my models in local and now, I can't update my AppFog database...
What am I suppose to do? Delete the App and Update again? I'll lost all my data in my database...
Logs:
Error: ER_BAD_FIELD_ERROR: Unknown column 'tags' in 'field list'
First export the database to keep a backup just in case this does not go as expected.
af apps
to get the db service name for the appaf export-service [service-name]
to get a download url of a backupNext tunnel the service to your local box. Note this can be a little finicky so give it a few tries if needed.
af tunnel [service-name]
1: none <- this will let you connect using sequel pro 2: mysql <- to make manual tweeks 3: mysqldump
Finally repair the database structure as needed to get your app working and then update the app.
Additionally, in the future you might what to use an ORM like Sequelize which has non-destructive db migrations that can be run when the app starts up after an af update
Somewhere early in your startup file:
// Sudo code. see af online docs on how to get the bound service creds
if (process.env.NODE_ENV == "production") {
var sequelize = new Sequelize(appfog.dbname, appfog.username, appfog.password, ...)
var migratorOptions = { path: process.cwd() + '/migrations' };
var migrator = sequelize.getMigrator(migratorOptions);
migrator.migrate();
}