add migration files

This commit is contained in:
lyx0 2022-08-08 23:58:10 +02:00
parent 6fbe68a0a4
commit 53481c274e
3 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1 @@
DROP TABLE IF EXISTS channels;

View file

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS channels (
id bigserial PRIMARY KEY,
joined_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
login text NOT NULL,
twitchid text NOT NULL,
announce BOOLEAN NOT NULL
);

View file

@ -2,7 +2,8 @@
Tool: [golang-migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate) Tool: [golang-migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)
``` ## Create Database
```sql
$ sudo -u postgres psql $ sudo -u postgres psql
psql (14.3) psql (14.3)
Type "help" for help. Type "help" for help.
@ -18,10 +19,25 @@ CREATE EXTENSION
nourybot=# nourybot=#
``` ```
``` ## Connect to Database
```sh
$ psql --host=localhost --dbname=nourybot --username=username $ psql --host=localhost --dbname=nourybot --username=username
psql (14.3) psql (14.3)
Type "help" for help. Type "help" for help.
nourybot=> nourybot=>
``` ```
## 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
```