2022-08-08 23:13:33 +02:00
|
|
|
# Migrations
|
|
|
|
|
|
|
|
Tool: [golang-migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)
|
|
|
|
|
2022-08-08 23:58:10 +02:00
|
|
|
## Create Database
|
|
|
|
```sql
|
2022-08-08 23:13:33 +02:00
|
|
|
$ 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=#
|
|
|
|
```
|
|
|
|
|
2022-08-08 23:58:10 +02:00
|
|
|
## Connect to Database
|
|
|
|
```sh
|
2022-08-08 23:13:33 +02:00
|
|
|
$ psql --host=localhost --dbname=nourybot --username=username
|
|
|
|
psql (14.3)
|
|
|
|
Type "help" for help.
|
|
|
|
|
|
|
|
nourybot=>
|
2022-08-08 23:58:10 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Apply migrations
|
|
|
|
```sh
|
|
|
|
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" up
|
|
|
|
```
|
|
|
|
|
|
|
|
```sh
|
|
|
|
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" down
|
|
|
|
```
|
|
|
|
|
|
|
|
## Fix Dirty database
|
|
|
|
```sh
|
|
|
|
$ migrate -path=./migrations -database="postgres://username:password@localhost/nourybot?sslmode=disable" force 1
|
2022-08-08 23:13:33 +02:00
|
|
|
```
|