To deploy to staging:
sails run deploy
To connect to the staging database from your local dev environment:
sails_models__migrate=safe sails_datastores__default__ssl=true sails_datastores__default__adapter=sails-postgresql sails_datastores__default__url=postgres://…:…@…:…/… sails console
To completely wipe it of all data (while maintaining the schema), just run the same thing, but with sails_models__migrate=drop
:
sails_models__migrate=drop sails_datastores__default__ssl=true sails_datastores__default__adapter=sails-postgresql sails_datastores__default__url=postgres://…:…@…:…/… sails console
Troubleshooting tip: If you see schema migration errors on a deploy to staging, it probably just means that something was changed, but the bootstrap version was not incremented. To fix that, the easiest solution is to (A) first increment the bootstrap version (config/bootstrap.js), then (B) redeploy.
Do keep in mind though, that in "production production", manual schema migrations need to be run. The bootstrap script will ALWAYS refuse to drop the database when sails.config.environment==='production'-- in fact, just to be safe, it'll also refuse to drop the database if NODE_ENV=production, unless sails.config.environment is "staging".
Notes:
- Before migrating a database in production, be sure to put the site into maintenance mode and back up the existing database!
- To migrate a remote database, specify the database URL in the
DB_URL
environment var, e.g.postgres://mypguser:[email protected]:5432/dbname
.
- To initialize a new database, make sure that an empty PostgreSQL database with the desired name exists at the URL you want to deploy to.
- Run
npm run knex migrate:latest
to execute any previously-unrun migration scripts. For empty databases, this will first import the base SQL file. - Run
npm run knex migrate:rollback
to rollback all of the migrations that were executed the last timenpm run knex migrate:latest
was run. - Run
npm run knex-migrate up
ornpm run knex-migrate down
to execute/rollback a single migration. Helpful for testing migration scripts. - Run
npm run knex migrate:make <kebab-cased-description-of-migration>
to make a new migration script. See the Knex.js docs for more info on creating migration scripts. - Run
npm run knex
ornpm run knex-migrate
for more help with those commands.
If you've installed the pre-commit hook bundled in this project (sails run install-pre-commit-hook
),
then any time you try to commit a change to a model without also including an up/down migration script, you'll
see something like this:
∑ git commit -m "Make companyName of an Organization a required attribute."
____________________________________________________________________________________________________
Sorry to interrupt, but it looks like you're trying to commit a new/modified/deleted model file,
without an accompanying schema migration script. Manual up/down migration scripts are a way of
making sure the records in your production database are properly adjusted when models change, so
it's important to include one any time that happens-- especially if those models represent data
that is stored in a SQL database.
To make a new migration script, run:
npm run knex migrate:make <kebab-cased-description-of-migration>
(See the Knex.js docs on http://knexjs.com for further reference info.)
[?] If you're unsure or need advice, head over to https://sailsjs.com/support
____________________________________________________________________________________________________
To skip the commit hook (e.g. because you only changed some comments), use
--no-verify
.