diff --git a/deployments/main/docker-compose.yaml b/deployments/main/docker-compose.yaml index da5ff20..66257cc 100644 --- a/deployments/main/docker-compose.yaml +++ b/deployments/main/docker-compose.yaml @@ -14,64 +14,3 @@ services: AUTH_URL: 'http://10.8.0.8:59300/user' ports: - 10.8.0.9:1488:1488 - - storer: - hostname: squiz-storer - container_name: squiz-storer - image: $CI_REGISTRY_IMAGE/main-storer:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY - PORT: 1489 - MINIO_EP: 'storage.yandexcloud.net' - MINIO_AK: 'YCAJEOcqqTHpiwL4qFwLfHPNA' - MINIO_SK: 'YCNIAIat0XqdDzycWsYKX3OU7mPor6S0WmMoG4Ry' - PG_CRED: 'host=10.8.0.9 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - ports: - - 10.8.0.9:1489:1489 - worker: - hostname: squiz-worker - container_name: squiz-worker - image: $CI_REGISTRY_IMAGE/main-worker:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PG_CRED: 'host=10.8.0.9 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - KAFKA_BROKER: '10.8.0.8:9092' - KAFKA_TOPIC: 'tariffs' - QUIZ_ID: quizCnt - AMOUNT: 10 - UNLIM_ID: quizUnlimTime - REDIS_HOST: '10.8.0.9:6379' - REDIS_PASSWORD: 'Redalert2' - REDIS_DB: 2 - SMTP_API_URL: 'https://api.smtp.bz/v1/smtp/send' - SMTP_HOST: 'connect.smtp.bz' - SMTP_PORT: '587' - SMTP_UNAME: 'team@pena.digital' - SMTP_PASS: 'AyMfwqA9LkQH' - SMTP_API_KEY: '8tv2xcsfCMBX3TCQxzgeeEwAEYyQrPUp0ggw' - SMTP_SENDER: 'recovery@noreply.pena.digital' - CUSTOMER_SERVICE_ADDRESS: 'http://10.8.0.8:8065/' - answerer: - hostname: squiz-answerer - container_name: squiz-answerer - image: $CI_REGISTRY_IMAGE/main-answerer:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY - PORT: 1490 - MINIO_EP: 'storage.yandexcloud.net' - MINIO_AK: 'YCAJEOcqqTHpiwL4qFwLfHPNA' - MINIO_SK: 'YCNIAIat0XqdDzycWsYKX3OU7mPor6S0WmMoG4Ry' - PG_CRED: 'host=10.8.0.9 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - REDIS_HOST: '10.8.0.9:6379' - REDIS_PASSWORD: 'Redalert2' - REDIS_DB: 2 - ports: - - 10.8.0.9:1490:1490 diff --git a/deployments/main/staging/docker-compose.yaml b/deployments/main/staging/docker-compose.yaml index 4aaed26..693c593 100644 --- a/deployments/main/staging/docker-compose.yaml +++ b/deployments/main/staging/docker-compose.yaml @@ -15,63 +15,3 @@ services: ports: - 1488:1488 - storer: - hostname: squiz-storer - container_name: squiz-storer - image: $CI_REGISTRY_IMAGE/storer:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY - PORT: 1489 - MINIO_EP: 'storage.yandexcloud.net' - MINIO_AK: 'YCAJEOcqqTHpiwL4qFwLfHPNA' - MINIO_SK: 'YCNIAIat0XqdDzycWsYKX3OU7mPor6S0WmMoG4Ry' - PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - ports: - - 1489:1489 - worker: - hostname: squiz-worker - container_name: squiz-worker - image: $CI_REGISTRY_IMAGE/worker:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - KAFKA_BROKER: '10.6.0.11:9092' - KAFKA_TOPIC: 'tariffs' - QUIZ_ID: quizCnt - AMOUNT: 10 - UNLIM_ID: quizUnlimTime - REDIS_HOST: '10.6.0.23:6379' - REDIS_PASSWORD: 'Redalert2' - REDIS_DB: 2 - SMTP_HOST: 'connect.mailclient.bz' - SMTP_PORT: '587' - SMTP_SENDER: 'noreply@mailing.pena.digital' - SMTP_IDENTITY: '' - SMTP_USERNAME: 'kotilion.95@gmail.com' - SMTP_PASSWORD: 'vWwbCSg4bf0p' - SMTP_API_KEY: 'P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev' - CUSTOMER_SERVICE_ADDRESS: 'http://10.6.0.11:8065/' - answerer: - hostname: squiz-answerer - container_name: squiz-answerer - image: $CI_REGISTRY_IMAGE/answerer:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY - PORT: 1490 - MINIO_EP: 'storage.yandexcloud.net' - MINIO_AK: 'YCAJEOcqqTHpiwL4qFwLfHPNA' - MINIO_SK: 'YCNIAIat0XqdDzycWsYKX3OU7mPor6S0WmMoG4Ry' - PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - REDIS_HOST: '10.6.0.23:6379' - REDIS_PASSWORD: 'Redalert2' - REDIS_DB: 2 - ports: - - 1490:1490 diff --git a/deployments/staging/docker-compose.yaml b/deployments/staging/docker-compose.yaml index 76c10ae..9cb57b2 100644 --- a/deployments/staging/docker-compose.yaml +++ b/deployments/staging/docker-compose.yaml @@ -14,64 +14,3 @@ services: AUTH_URL: 'http://10.6.0.11:59300/user' ports: - 1488:1488 - - storer: - hostname: squiz-storer - container_name: squiz-storer - image: $CI_REGISTRY_IMAGE/staging-storer:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY - PORT: 1489 - MINIO_EP: 'storage.yandexcloud.net' - MINIO_AK: 'YCAJEOcqqTHpiwL4qFwLfHPNA' - MINIO_SK: 'YCNIAIat0XqdDzycWsYKX3OU7mPor6S0WmMoG4Ry' - PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - ports: - - 1489:1489 - worker: - hostname: squiz-worker - container_name: squiz-worker - image: $CI_REGISTRY_IMAGE/staging-worker:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - KAFKA_BROKER: '10.6.0.11:9092' - KAFKA_TOPIC: 'tariffs' - QUIZ_ID: quizCnt - AMOUNT: 10 - UNLIM_ID: quizUnlimTime - REDIS_HOST: '10.6.0.23:6379' - REDIS_PASSWORD: 'Redalert2' - REDIS_DB: 2 - SMTP_HOST: 'connect.mailclient.bz' - SMTP_PORT: '587' - SMTP_SENDER: 'noreply@mailing.pena.digital' - SMTP_IDENTITY: '' - SMTP_USERNAME: 'kotilion.95@gmail.com' - SMTP_PASSWORD: 'vWwbCSg4bf0p' - SMTP_API_KEY: 'P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev' - CUSTOMER_SERVICE_ADDRESS: 'http://10.6.0.11:8065/' - answerer: - hostname: squiz-answerer - container_name: squiz-answerer - image: $CI_REGISTRY_IMAGE/staging-answerer:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID - tty: true - environment: - IS_PROD_LOG: 'false' - IS_PROD: 'false' - PUBLIC_ACCESS_SECRET_KEY: $JWT_PUBLIC_KEY - PORT: 1490 - MINIO_EP: 'storage.yandexcloud.net' - MINIO_AK: 'YCAJEOcqqTHpiwL4qFwLfHPNA' - MINIO_SK: 'YCNIAIat0XqdDzycWsYKX3OU7mPor6S0WmMoG4Ry' - PG_CRED: 'host=10.6.0.23 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable' - REDIS_HOST: '10.6.0.23:6379' - REDIS_PASSWORD: 'Redalert2' - REDIS_DB: 2 - ports: - - 1490:1490 diff --git a/deployments/testmigrate/docker-compose.yaml b/deployments/testmigrate/docker-compose.yaml deleted file mode 100644 index dd98264..0000000 --- a/deployments/testmigrate/docker-compose.yaml +++ /dev/null @@ -1,23 +0,0 @@ -version: '3' -services: - test-postgres: - image: postgres - environment: - POSTGRES_PASSWORD: Redalert2 - POSTGRES_USER: squiz - POSTGRES_DB: squiz - ports: - - 35432:5432 - networks: - - penatest - healthcheck: - test: pg_isready -U squiz - interval: 2s - timeout: 2s - retries: 10 - -networks: - penatest: - -# просто чтоб тестануть мигрировала ли бд -# в app/app.go pgdal, err := dal.New(ctx, "host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable") diff --git a/go.mod b/go.mod index a811cf9..23632c2 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf go.uber.org/zap v1.26.0 penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d - penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240313164312-4560248259a0 + penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314111040-7ed859ef7876 penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3 ) diff --git a/go.sum b/go.sum index a0404e9..54c3b69 100644 --- a/go.sum +++ b/go.sum @@ -186,7 +186,7 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d h1:gbaDt35HMDqOK84WYmDIlXMI7rstUcRqNttaT6Kx1do= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= -penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240313164312-4560248259a0 h1:YbffFOWneoINvEqCWClf5Zatu/a0VNo9RM0nYveCzhk= -penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240313164312-4560248259a0/go.mod h1:JgbH8cdAJBr3jx3BuY5nnuTyMdZ1XkRxo8a3w4Y3C0Y= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314111040-7ed859ef7876 h1:875+tdI7KuftCn9hZer2p9vq88FX0gbAaHOeCy1n6T4= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240314111040-7ed859ef7876/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y= penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3 h1:BLHIUnJAttW9OAW7A63H9ON/HPhXdpBa/YPUQWD4ORA= penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3/go.mod h1:/BFcX4F10DRuFuAHlwkKO+1QAXPL4i49x1tsrTwxlqE= diff --git a/schema/000001_init.down.sql b/schema/000001_init.down.sql new file mode 100644 index 0000000..54966a0 --- /dev/null +++ b/schema/000001_init.down.sql @@ -0,0 +1,24 @@ +-- Drop indexes +DROP INDEX IF EXISTS subquizes; +DROP INDEX IF EXISTS birthtime; +DROP INDEX IF EXISTS groups; +DROP INDEX IF EXISTS timeouted; +DROP INDEX IF EXISTS active ON quiz; +DROP INDEX IF EXISTS questiontype; +DROP INDEX IF EXISTS required; +DROP INDEX IF EXISTS relation; +DROP INDEX IF EXISTS active ON question; + +-- Drop tables +DROP TABLE IF EXISTS privileges; +DROP TABLE IF EXISTS answer; +DROP TABLE IF EXISTS question; +DROP TABLE IF EXISTS quiz; +DROP TABLE IF EXISTS account; + +-- Drop types +DO $$ +BEGIN +DROP TYPE IF EXISTS question_type; +DROP TYPE IF EXISTS quiz_status; +END$$; \ No newline at end of file diff --git a/schema/000001_init.up.sql b/schema/000001_init.up.sql new file mode 100644 index 0000000..9aefa67 --- /dev/null +++ b/schema/000001_init.up.sql @@ -0,0 +1,120 @@ +-- Create types +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'question_type') THEN +CREATE TYPE question_type AS ENUM ( + 'variant', + 'images', + 'varimg', + 'emoji', + 'text', + 'select', + 'date', + 'number', + 'file', + 'page', + 'rating' + ); +END IF; + + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'quiz_status') THEN +CREATE TYPE quiz_status AS ENUM ( + 'draft', + 'template', + 'stop', + 'start', + 'timeout', + 'offlimit' + ); +END IF; + + CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +END$$; + +-- Create tables +CREATE TABLE IF NOT EXISTS account ( + id UUID PRIMARY KEY, + user_id VARCHAR(24), + email VARCHAR(50), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + deleted BOOLEAN DEFAULT false + ); + +CREATE TABLE IF NOT EXISTS quiz ( + id bigserial UNIQUE NOT NULL PRIMARY KEY, + qid uuid DEFAULT uuid_generate_v4(), + accountid varchar(30) NOT NULL, + deleted boolean DEFAULT false, + archived boolean DEFAULT false, + fingerprinting boolean DEFAULT false, + repeatable boolean DEFAULT false, + note_prevented boolean DEFAULT false, + mail_notifications boolean DEFAULT false, + unique_answers boolean DEFAULT false, + super boolean DEFAULT false, + group_id bigint DEFAULT 0, + name varchar(280), + description text, + config text, + status quiz_status DEFAULT 'draft', + limit_answers integer DEFAULT 0, + due_to integer DEFAULT 0, + time_of_passing integer DEFAULT 0, + pausable boolean DEFAULT false, + version smallint DEFAULT 0, + version_comment text DEFAULT '', + parent_ids integer[], + created_at timestamp DEFAULT CURRENT_TIMESTAMP, + updated_at timestamp DEFAULT CURRENT_TIMESTAMP, + questions_count integer DEFAULT 0, + answers_count integer DEFAULT 0, + average_time_passing integer DEFAULT 0 + ); + +CREATE TABLE IF NOT EXISTS question ( + id bigserial UNIQUE NOT NULL PRIMARY KEY, + quiz_id bigint NOT NULL, + title varchar(512) NOT NULL, + description text, + questiontype question_type DEFAULT 'text', + required boolean DEFAULT false, + deleted boolean DEFAULT false, + page smallint DEFAULT 0, + content text, + version smallint DEFAULT 0, + parent_ids integer[], + created_at timestamp DEFAULT CURRENT_TIMESTAMP, + updated_at timestamp DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT quiz_relation FOREIGN KEY(quiz_id) REFERENCES quiz(id) + ); + +CREATE TABLE IF NOT EXISTS answer ( + id bigserial UNIQUE NOT NULL PRIMARY KEY, + content text, + quiz_id bigint NOT NULL REFERENCES quiz(id), + question_id bigint NOT NULL REFERENCES question(id), + fingerprint varchar(1024), + session varchar(20), + created_at timestamp DEFAULT CURRENT_TIMESTAMP + ); + +CREATE TABLE IF NOT EXISTS privileges ( + id SERIAL PRIMARY KEY, + privilegeID VARCHAR(50), + account_id UUID, + privilege_name VARCHAR(255), + amount INT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (account_id) REFERENCES account (id) + ); + +-- Create indexes +CREATE INDEX IF NOT EXISTS active ON question(deleted) WHERE deleted=false; +CREATE INDEX IF NOT EXISTS relation ON question(quiz_id DESC); +CREATE INDEX IF NOT EXISTS required ON question(required DESC); +CREATE INDEX IF NOT EXISTS questiontype ON question(questiontype); +CREATE INDEX IF NOT EXISTS active ON quiz(deleted, archived, status) WHERE deleted = false AND archived = false AND status = 'start'; +CREATE INDEX IF NOT EXISTS timeouted ON quiz(due_to DESC) WHERE deleted = false AND due_to <> 0 AND status <> 'timeout'; +CREATE INDEX IF NOT EXISTS groups ON quiz(super) WHERE super = true; +CREATE INDEX IF NOT EXISTS birthtime ON quiz(created_at DESC); +CREATE INDEX IF NOT EXISTS subquizes ON quiz(group_id DESC) WHERE group_id <> 0; diff --git a/schema/000002_init.down.sql b/schema/000002_init.down.sql new file mode 100644 index 0000000..0aa3d9e --- /dev/null +++ b/schema/000002_init.down.sql @@ -0,0 +1 @@ +ALTER TABLE answer DROP COLUMN IF EXISTS result; diff --git a/schema/000002_init.up.sql b/schema/000002_init.up.sql new file mode 100644 index 0000000..4083153 --- /dev/null +++ b/schema/000002_init.up.sql @@ -0,0 +1 @@ +ALTER TABLE answer ADD COLUMN result BOOLEAN DEFAULT FALSE; \ No newline at end of file diff --git a/schema/000003_init.down.sql b/schema/000003_init.down.sql new file mode 100644 index 0000000..94e352f --- /dev/null +++ b/schema/000003_init.down.sql @@ -0,0 +1 @@ +ALTER TABLE quiz DROP COLUMN IF EXISTS sessions_count; diff --git a/schema/000003_init.up.sql b/schema/000003_init.up.sql new file mode 100644 index 0000000..a292d62 --- /dev/null +++ b/schema/000003_init.up.sql @@ -0,0 +1 @@ +ALTER TABLE quiz ADD COLUMN sessions_count integer; diff --git a/schema/000004_init.down.sql b/schema/000004_init.down.sql new file mode 100644 index 0000000..b6d5ec4 --- /dev/null +++ b/schema/000004_init.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE quiz DROP COLUMN IF EXISTS new; +ALTER TABLE quiz DROP COLUMN IF EXISTS deleted; \ No newline at end of file diff --git a/schema/000004_init.up.sql b/schema/000004_init.up.sql new file mode 100644 index 0000000..9dc5591 --- /dev/null +++ b/schema/000004_init.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE answer ADD COLUMN new BOOLEAN DEFAULT TRUE; +ALTER TABLE answer ADD COLUMN deleted BOOLEAN DEFAULT FALSE; \ No newline at end of file diff --git a/schema/000005_init.down.sql b/schema/000005_init.down.sql new file mode 100644 index 0000000..ccae4f5 --- /dev/null +++ b/schema/000005_init.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE answer DROP COLUMN IF EXISTS email; +DROP INDEX IF EXISTS answer_email_unique_idx; \ No newline at end of file diff --git a/schema/000005_init.up.sql b/schema/000005_init.up.sql new file mode 100644 index 0000000..f2bfe97 --- /dev/null +++ b/schema/000005_init.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE answer ADD COLUMN email VARCHAR(50) NOT NULL DEFAULT ''; +CREATE UNIQUE INDEX IF NOT EXISTS answer_email_unique_idx ON answer (quiz_id, email) WHERE email <> ''; \ No newline at end of file