mirror-nourybot/migrations/dev/README.md
2023-12-11 01:32:00 +01:00

1 KiB

Migrations

Tool: golang-migrate

Create Database

$ sudo -u postgres psql
psql (14.3)
Type "help" for help.

postgres=# CREATE DATABASE nourybot;
CREATE DATABASE
postgres=# \c nourybot;
You are now connected to database "nourybot" as user "postgres".
nourybot=# CREATE ROLE username WITH LOGIN PASSWORD 'password';
CREATE ROLE
nourybot=# CREATE EXTENSION IF NOT EXISTS citext;
CREATE EXTENSION
nourybot=# 

Connect to Database

$ psql --host=localhost --dbname=nourybot --username=username
psql (14.3)
Type "help" for help.

nourybot=> 

Apply migrations

$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" up
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" down

Fix Dirty database

$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" force 1