diff --git a/migrations/000001_create_channels_table.down.sql b/migrations/000001_create_channels_table.down.sql new file mode 100644 index 0000000..1d28aad --- /dev/null +++ b/migrations/000001_create_channels_table.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS channels; \ No newline at end of file diff --git a/migrations/000001_create_channels_table.up.sql b/migrations/000001_create_channels_table.up.sql new file mode 100644 index 0000000..f884116 --- /dev/null +++ b/migrations/000001_create_channels_table.up.sql @@ -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 +); \ No newline at end of file diff --git a/migrations/README.md b/migrations/README.md index 090377e..5760832 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -2,7 +2,8 @@ Tool: [golang-migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate) -``` +## Create Database +```sql $ sudo -u postgres psql psql (14.3) Type "help" for help. @@ -18,10 +19,25 @@ CREATE EXTENSION nourybot=# ``` -``` +## Connect to Database +```sh $ psql --host=localhost --dbname=nourybot --username=username psql (14.3) Type "help" for help. 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 ``` \ No newline at end of file