From 1524ebced86fd97c7861cf248883c57a255377cf Mon Sep 17 00:00:00 2001 From: Shuhrat Tultaganov Date: Tue, 13 Dec 2022 16:45:22 +0300 Subject: [PATCH] Add migrations and model go struct --- configs/restServer/config.yaml | 2 +- docker-compose.yaml | 12 ++++++++++++ internal/bd/model/films.go | 21 +++++++++++++++++++++ internal/bd/repositoryes/filmsrepo.go | 18 ++++++++++++++++++ migrates/20221213130458_films.down.sql | 1 + migrates/20221213130458_films.up.sql | 21 +++++++++++++++++++++ 6 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yaml create mode 100644 internal/bd/model/films.go create mode 100644 internal/bd/repositoryes/filmsrepo.go create mode 100644 migrates/20221213130458_films.down.sql create mode 100644 migrates/20221213130458_films.up.sql diff --git a/configs/restServer/config.yaml b/configs/restServer/config.yaml index 0323cf9..3184bda 100644 --- a/configs/restServer/config.yaml +++ b/configs/restServer/config.yaml @@ -7,4 +7,4 @@ log_level: "debug" # db DB: - baseurlbd: "host=localhost user=tester dbname=testdb sslmode=disable" \ No newline at end of file + baseurlbd: "host=localhost user=admin password=root dbname=postgres sslmode=disable" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..c050f3c --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +version: '3.5' + +services: + database: + container_name: postgres + ports: + - "5432:5432" + environment: + - POSTGRES_PASSWORD=root + - POSTGRES_USER=admin + image: postgres + \ No newline at end of file diff --git a/internal/bd/model/films.go b/internal/bd/model/films.go new file mode 100644 index 0000000..1aa2e97 --- /dev/null +++ b/internal/bd/model/films.go @@ -0,0 +1,21 @@ +package model + +type Films struct { + id int + ru_title string + orig_title string + imdb_id string + kinopoisk_id string + posterUrl string + posterUrlPreview string + countries string + genres map[string]interface{} + year int + description string + ratingKinopoisk int + ratingImdb int + iframe_src string + ratingImdbVoteCount int + ratingKinopoiskVoteCount int + media map[string]interface{} +} diff --git a/internal/bd/repositoryes/filmsrepo.go b/internal/bd/repositoryes/filmsrepo.go new file mode 100644 index 0000000..e0b64de --- /dev/null +++ b/internal/bd/repositoryes/filmsrepo.go @@ -0,0 +1,18 @@ +package repositoryes + +import ( + "git.ukamnya.ru/stulyaganov/RestApi/internal/bd" + "git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model" +) + +type Filmsrepo struct { + DB *bd.Bd +} + +func Create(model.Films) (*model.Films, error) { + return nil, nil +} + +func FindDyId(id int) (*model.Films, error) { + return nil, nil +} diff --git a/migrates/20221213130458_films.down.sql b/migrates/20221213130458_films.down.sql new file mode 100644 index 0000000..a46e6e5 --- /dev/null +++ b/migrates/20221213130458_films.down.sql @@ -0,0 +1 @@ +DROP TABLE films; \ No newline at end of file diff --git a/migrates/20221213130458_films.up.sql b/migrates/20221213130458_films.up.sql new file mode 100644 index 0000000..4e1058a --- /dev/null +++ b/migrates/20221213130458_films.up.sql @@ -0,0 +1,21 @@ + +CREATE TABLE films ( + id INTEGER NOT NULL, + ru_title VARCHAR(256), + orig_title VARCHAR(255), + imdb_id VARCHAR(255), + kinopoisk_id INTEGER, + posterUrl VARCHAR(1500), + posterUrlPreview VARCHAR(1500), + countries JSON, + genres JSON, + year INTEGER, + description VARCHAR(20000), + ratingKinopoisk INTEGER, + ratingImdb INTEGER, + iframe_src VARCHAR(2000), + ratingImdbVoteCount INTEGER, + ratingKinopoiskVoteCount INTEGER, + media JSON, + PRIMARY KEY(id) +); \ No newline at end of file