This assumes you already have a PostgreSQL server running, with an empty database created
- Install git and node v12
- Clone this repository
- Open terminal in repo's folder
- Run
npm install
- Set the environment variable
DATABASE_URL
in your shell. Example:export DATABASE_URL=postgres://user:password@domain:5432/db_name
- Run
npm run build:db
to migrate db, and buildPERMISSIONS.js
- Run development server
npm run dev
- Fork this repo and configure it in vercel as a Sapper app
- Set the environment variables
DATABASE_URL
SECRET_SESSION
─ you can get one withopenssl rand -base64 30
Set the environment variable DATABASE_URL
in your shell. Example:
postgres://user:password@domain:5432/db_name
- In Linux, run
export DATABASE_URL=postgres://user:password@domain:5432/db_name
- In Windows, powershell run
$env:DATABASE_URL="postgres://user:password@domain:5432/db_name"
Now you can run the server, or any migration-command, in this same shell / terminal session
Any DB-related-command you run in another terminal window, will not work, you'll have to re-declare DATABASE_URL
there
- To migrate all pending migrations:
npm run migrate up
- To undo one migration
npm run migrate down
- To undo
n
migrationsnpm run migrate down {n}
- To redo
n
migrationsnpm run migrate redo {n}
npm run migrate create 'name of migration'
DO NOT USE THIS TO CREATE PERMISSIONS, see Permissions section
That will create an empty migration like /migrations/1603225902395_name-of-migration.js
, see existing migrations to see how this works, or check node-pg-migrate's docs
Permissions must be created using a migration, to automate the deployment.
I made some scripts to automate this process, see CRUD permissions or single permissions
PERMISSIONS.js
is a file that is not included in the repo, because it's builded after each DB-migration. See PERMISSIONS.js.README for more details
It allows you to easily import permission's ids and names when developing API endpoints, to validate permissions.
To build that file, run npm run build:permissions.js
, but most likely you will be running npm run build:db
which migrates any pending changes and then builds the file.
To create CRUD permissions (Create, Read, Update, Delete)
npm run create:crudPermissions accounts
That will create a migration to insert the following permissions:
- accounts_create
- accounts_read
- accounts_update
- accounts_delete
To migrate them and build PERMISSIONS.js
npm run build:db
npm run create:permissions approve_loans ask_for_approval
That will create a migration to insert the following permissions:
- approve_loans
- ask_for_approval
To migrate them and build PERMISSIONS.js
npm run build:db