add categories table and local env #12

Merged
VLADIMIR merged 2 commits from add_categories into master 2024-11-19 07:47:37 +00:00
8 changed files with 65 additions and 6 deletions
Showing only changes of commit 6cfab72b9c - Show all commits

2
.vscode/launch.json vendored
View File

@ -1,7 +1,7 @@
{
"configurations": [
{
"name": "Launch eparser",
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",

View File

@ -7,11 +7,22 @@ ifeq (local-migrations-create,$(firstword $(MAKECMDGOALS)))
endif
local-migrate-up:
@goose -allow-missing -dir ./migrations postgres "user=crab dbname=smm-core host=localhost port=5432 sslmode=disable" up
@goose -allow-missing -dir ./migrations postgres "user=crab password=crab dbname=smm-core host=localhost port=5432 sslmode=disable" up
local-migrations-create:
@goose -dir ./migrations postgres "user=crab dbname=smm-core host=localhost port=5432 sslmode=disable" create "${migrationName}" sql
local-up:
docker-compose -f docker-compose-local.yml up -d --force-recreate --build
local-down:
docker-compose -f docker-compose-local.yml down
local-wait_db:
timeout 10s bash -c "until docker exec db pg_isready; do sleep 1; done"
local-restart: local-down local-up local-wait_db local-migrate-up
local-go-init: export GOBIN := $(LOCAL_BIN)
local-go-init:
go get github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
@ -23,6 +34,7 @@ local-go-init:
github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \
google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
go install github.com/pressly/goose/v3/cmd/goose@latest
generate:
rm -rf proto resources

22
docker-compose-local.yml Normal file
View File

@ -0,0 +1,22 @@
version: '3.9'
services:
db:
container_name: db
image: postgres
restart: always
shm_size: 128mb
environment:
POSTGRES_USER: crab
POSTGRES_PASSWORD: crab
POSTGRES_DB: smm-core
ports:
- 5432:5432
adminer:
Review

чем тебе божественный бобёр не угодил?

чем тебе божественный бобёр не угодил?
Review

Не надо себя ограничивать

Не надо себя ограничивать
container_name: adminer
image: adminer
restart: always
ports:
- 8100:8080

View File

@ -12,4 +12,4 @@ services:
networks:
common-network:
external: true
external: true

4
go.mod
View File

@ -6,7 +6,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
google.golang.org/protobuf v1.35.2
)
require (
@ -14,4 +14,6 @@ require (
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

7
go.sum
View File

@ -14,5 +14,12 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io=
google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -1,6 +1,6 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS "user" (
CREATE TABLE IF NOT EXISTS "users" (
id SERIAL PRIMARY KEY,
chat_id TEXT NOT NULL
);
@ -8,5 +8,5 @@ CREATE TABLE IF NOT EXISTS "user" (
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS "user";
DROP TABLE IF EXISTS "users";
-- +goose StatementEnd

View File

@ -0,0 +1,16 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS categories (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
user_id INT REFERENCES "users"(id),
favorite BOOLEAN DEFAULT FALSE,
"limit" INT DEFAULT 0
);
comment on column categories.limit is 'Лимит трат в месяц в копейках';
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS categories;
-- +goose StatementEnd