From 25126c176fe2061792cf0119930dcaa558d336e6 Mon Sep 17 00:00:00 2001 From: valitovgaziz Date: Mon, 5 Aug 2024 23:27:46 +0500 Subject: [PATCH] Golang migrator added. Need switch to gooos. --- .env | 3 ++- api/Dockerfile | 2 ++ api/db/migrations/000001_create_users_table.down.sql | 1 + api/db/migrations/000001_create_users_table.up.sql | 6 ++++++ api/go.mod | 1 + api/go.sum | 2 ++ api/src/models/user.go | 11 +++++++++++ db/Dockerfile | 0 8 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 api/db/migrations/000001_create_users_table.down.sql create mode 100644 api/db/migrations/000001_create_users_table.up.sql create mode 100644 api/src/models/user.go delete mode 100644 db/Dockerfile diff --git a/.env b/.env index cfa95af..74ebe01 100644 --- a/.env +++ b/.env @@ -3,4 +3,5 @@ DB_PASSWORD=postgres DB_NAME=postgres DB_PORT=5432 HOST_DB=db -SERVER_PORT=8000 \ No newline at end of file +SERVER_PORT=8000 +POSTGRESQL_URL='postgres://postgres:postgres@db:5432/postgres?sslmode=disable' \ No newline at end of file diff --git a/api/Dockerfile b/api/Dockerfile index 0a7bda9..2a188cf 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -8,4 +8,6 @@ RUN go mod tidy RUN go build -o bin/api.exe cmd/main.go +RUN + ENTRYPOINT [ "bin/api.exe" ] \ No newline at end of file diff --git a/api/db/migrations/000001_create_users_table.down.sql b/api/db/migrations/000001_create_users_table.down.sql new file mode 100644 index 0000000..365a210 --- /dev/null +++ b/api/db/migrations/000001_create_users_table.down.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS users; \ No newline at end of file diff --git a/api/db/migrations/000001_create_users_table.up.sql b/api/db/migrations/000001_create_users_table.up.sql new file mode 100644 index 0000000..512cf1a --- /dev/null +++ b/api/db/migrations/000001_create_users_table.up.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXIST users( + id UUID PRIMARY KEY, + name VARCHAR(50) NOT NULL, + password VARCHAR(50) NOT NULL, + email VARCHAR(300) UNIQUE NOT NULL +); \ No newline at end of file diff --git a/api/go.mod b/api/go.mod index 066f4f6..0c9a9d4 100644 --- a/api/go.mod +++ b/api/go.mod @@ -25,6 +25,7 @@ require ( require ( github.com/fatih/color v1.17.0 // indirect + github.com/google/uuid v1.6.0 github.com/ilyakaznacheev/cleanenv v1.5.0 github.com/jinzhu/gorm v1.9.16 github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/api/go.sum b/api/go.sum index 78b6527..caceada 100644 --- a/api/go.sum +++ b/api/go.sum @@ -11,6 +11,8 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw= github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2lOrsHHvr4= github.com/ilyakaznacheev/cleanenv v1.5.0/go.mod h1:a5aDzaJrLCQZsazHol1w8InnDcOX0OColm64SlIi6gk= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= diff --git a/api/src/models/user.go b/api/src/models/user.go new file mode 100644 index 0000000..19f04b9 --- /dev/null +++ b/api/src/models/user.go @@ -0,0 +1,11 @@ +package models + +import "github.com/google/uuid" + +type User struct { + Id uuid.UUID `json:"id"` + Name string `json:"name"` + Email string `json:"email"` + Password string `json:"password"` + Phone string `json:"phone"` +} diff --git a/db/Dockerfile b/db/Dockerfile deleted file mode 100644 index e69de29..0000000