From 53481c274e31490850210900c7ea4e7c960faee4 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Mon, 8 Aug 2022 23:58:10 +0200 Subject: [PATCH] add migration files --- .../000001_create_channels_table.down.sql | 1 + .../000001_create_channels_table.up.sql | 7 +++++++ migrations/README.md | 20 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 migrations/000001_create_channels_table.down.sql create mode 100644 migrations/000001_create_channels_table.up.sql 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