From 5567875910dbbda6014192e404398f9fe488798e Mon Sep 17 00:00:00 2001 From: user-penguin Date: Sun, 10 Nov 2024 01:48:28 +0700 Subject: [PATCH] add goose --- .drone.yml | 6 ++++++ Makefile | 11 +++++++++++ migrations/20241109180651_add_user.sql | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 migrations/20241109180651_add_user.sql diff --git a/.drone.yml b/.drone.yml index 311924d..590f288 100644 --- a/.drone.yml +++ b/.drone.yml @@ -31,10 +31,14 @@ steps: - smm_core - docker-compose.yml - Dockerfile + - migrations rm: true - name: deploy image: appleboy/drone-ssh + environment: + DB_PASS: + from_secret: db_pass settings: host: from_secret: server_ip @@ -47,6 +51,8 @@ steps: command_timeout: 50s script: - cd deploys/smm_core + - export PATH=$PATH:/usr/local/go/bin:/$HOME/go/bin + - goose -allow-missing -dir ./migrations postgres "user=crab password=$${DB_PASS} dbname=smm-core host=localhost port=5432 sslmode=disable" up - docker-compose up -d --build --force-recreate trigger: diff --git a/Makefile b/Makefile index 4af4f6a..b3c465d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,17 @@ LOCAL_BIN := $(CURDIR)/bin PATH := $(LOCAL_BIN):$(PATH) +ifeq (local-migrations-create,$(firstword $(MAKECMDGOALS))) + migrationName := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + $(eval $(migrationName):;@:) +endif + +local-migrate-up: + @goose -allow-missing -dir ./migrations postgres "user=crab dbname=smm-core host=localhost port=5432 sslmode=disable" up + +local-migrations-create: + @goose -dir ./migrations postgres "user=crab dbname=smm-core host=localhost port=5432 sslmode=disable" create "${migrationName}" sql + local-go-init: export GOBIN := $(LOCAL_BIN) local-go-init: go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway diff --git a/migrations/20241109180651_add_user.sql b/migrations/20241109180651_add_user.sql new file mode 100644 index 0000000..2c9c2a4 --- /dev/null +++ b/migrations/20241109180651_add_user.sql @@ -0,0 +1,12 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS "user" ( + id SERIAL PRIMARY KEY, + chat_id TEXT NOT NULL +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS "user"; +-- +goose StatementEnd -- 2.40.1