From a0567ba7d07657583d39baeb72b48ae18e4a7f05 Mon Sep 17 00:00:00 2001 From: timurIsaevIY <118661906+timurIsaevIY@users.noreply.github.com> Date: Sun, 29 Sep 2024 23:58:55 +0300 Subject: [PATCH] db settings added (#8) * db settings added * moved docker-compose * migrations added * migrations fixed * names added --- build/docker-compose.yml | 9 --------- build/main.Dockerfile | 2 +- cmd/main.go | 2 +- docker-compose.yml | 22 ++++++++++++++++++++++ migrations/01_up.sql | 7 +++++++ 5 files changed, 31 insertions(+), 11 deletions(-) delete mode 100644 build/docker-compose.yml create mode 100644 docker-compose.yml create mode 100644 migrations/01_up.sql diff --git a/build/docker-compose.yml b/build/docker-compose.yml deleted file mode 100644 index 655ce3d..0000000 --- a/build/docker-compose.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: "3.3" - -services: - main: - build: - context: . - dockerfile: ./build/main.Dockerfile - ports: - - 80:80 \ No newline at end of file diff --git a/build/main.Dockerfile b/build/main.Dockerfile index 474e8ad..48e674c 100644 --- a/build/main.Dockerfile +++ b/build/main.Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.7-alpine AS builder +FROM golang:1.23.1-alpine AS builder COPY . /github.com/go-park-mail-ru/2024_2_ThereWillBeName WORKDIR /github.com/go-park-mail-ru/2024_2_ThereWillBeName RUN go mod download diff --git a/cmd/main.go b/cmd/main.go index 47e1970..42603da 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -28,7 +28,7 @@ func main() { flag.IntVar(&cfg.Port, "port", 8080, "API server port") flag.StringVar(&cfg.Env, "env", "development", "Environment") flag.StringVar(&cfg.AllowedOrigin, "allowed-origin", "*", "Allowed origin") - flag.StringVar(&cfg.ConnStr, "connStr", "host=localhost port=5433 user=test_user password=1234567890 dbname=testdb_tripadvisor sslmode=disable", "PostgreSQL connection string") + flag.StringVar(&cfg.ConnStr, "connStr", "host=tripdb port=5432 user=service password=test dbname=trip sslmode=disable", "PostgreSQL connection string") flag.Parse() newPlaceRepo := placerepo.NewPLaceRepository() diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4642cef --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.3" + +services: + main: + container_name: main-service + build: + context: . + dockerfile: ./build/main.Dockerfile + ports: + - 8080:8080 + tripdb: + container_name: postgres + image: postgres:15 + environment: + POSTGRES_DB: "trip" + POSTGRES_USER: "service" + POSTGRES_PASSWORD: "test" + volumes: + - ./migrations:/docker-entrypoint-initdb.d + restart: unless-stopped + ports: + - 5432:5432 \ No newline at end of file diff --git a/migrations/01_up.sql b/migrations/01_up.sql new file mode 100644 index 0000000..de9f898 --- /dev/null +++ b/migrations/01_up.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS users +( + id SERIAL PRIMARY KEY, -- Уникальный идентификатор пользователя + login VARCHAR(255) NOT NULL, -- Логин пользователя + password VARCHAR(255) NOT NULL, -- Хэш пароля + created_at TIMESTAMP NOT NULL DEFAULT NOW() -- Дата создания пользователя +); \ No newline at end of file