add users table migrations. Need to install goose into migrator

This commit is contained in:
valitovgaziz
2024-08-08 16:15:40 +05:00
parent 260a01b27c
commit f9a7615801
5 changed files with 11 additions and 7 deletions
+1
View File
@@ -4,6 +4,7 @@ DB_NAME=postgres
DB_PORT=5432 DB_PORT=5432
HOST_DB=db HOST_DB=db
SERVER_PORT=8000 SERVER_PORT=8000
SSLmode=disable
POSTGRESQL_URL='postgres://postgres:postgres@db:5432/postgres?sslmode=disable' POSTGRESQL_URL='postgres://postgres:postgres@db:5432/postgres?sslmode=disable'
# MIGRATOR # MIGRATOR
-1
View File
@@ -30,7 +30,6 @@ services:
- .env - .env
ports: ports:
- "${MIGRATOR_PORT}:${MIGRATOR_PORT}" - "${MIGRATOR_PORT}:${MIGRATOR_PORT}"
command: "goose -dir ./migratios postgres 'user=postgres dbname=postgres sslmode=disable' up"
volumes: volumes:
postgres-db: postgres-db:
+5 -4
View File
@@ -1,10 +1,11 @@
FROM golang:1.22.5 FROM golang:1.22.5
RUN go get github.com/pressly/goose/cmd/goose
WORKDIR /app WORKDIR /app
COPY migrations/* app/migrations/ COPY migrations/* app/migrations/
CMD [ "goose", "up", "-dir=/app/migrations" ] COPY go.mod app/
RUN go install github.com/pressly/goose/v3/cmd/goose@latest
CMD ["goose", "-dir=/app/migrations", "user=${DB_USER}", "dbname=${DB_NAME}", "sslmode=${SSLmode}" "up"]
+3
View File
@@ -0,0 +1,3 @@
module migrator
go 1.22.5
@@ -1,6 +1,6 @@
-- +goose Up -- +goose Up
-- +goose StatementBegin -- +goose StatementBegin
CREATE TABLE users( CREATE TABLE IF NOT EXISTS users(
id UUID NOT NULL PRIMARY KEY, id UUID NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL, name VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL UNIQUE INDEX, email VARCHAR(50) NOT NULL UNIQUE INDEX,
@@ -11,5 +11,5 @@ CREATE TABLE users(
-- +goose Down -- +goose Down
-- +goose StatementBegin -- +goose StatementBegin
DROP TABLE users; DROP TABLE IF EXISTS users;
-- +goose StatementEnd -- +goose StatementEnd