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
HOST_DB=db
SERVER_PORT=8000
SSLmode=disable
POSTGRESQL_URL='postgres://postgres:postgres@db:5432/postgres?sslmode=disable'
# MIGRATOR
-1
View File
@@ -30,7 +30,6 @@ services:
- .env
ports:
- "${MIGRATOR_PORT}:${MIGRATOR_PORT}"
command: "goose -dir ./migratios postgres 'user=postgres dbname=postgres sslmode=disable' up"
volumes:
postgres-db:
+5 -4
View File
@@ -1,10 +1,11 @@
FROM golang:1.22.5
RUN go get github.com/pressly/goose/cmd/goose
WORKDIR /app
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 StatementBegin
CREATE TABLE users(
CREATE TABLE IF NOT EXISTS users(
id UUID NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL UNIQUE INDEX,
@@ -11,5 +11,5 @@ CREATE TABLE users(
-- +goose Down
-- +goose StatementBegin
DROP TABLE users;
DROP TABLE IF EXISTS users;
-- +goose StatementEnd