commit 1acccf472b0475aa84f621773ae7114efee454e8 Author: Витковских Евгений Date: Tue Jul 15 11:51:38 2025 +0300 БД на Postgres для инструктажей 1) General diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a39c1ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.vs \ No newline at end of file diff --git a/DB/General/Deployment/schema.psql b/DB/General/Deployment/schema.psql new file mode 100644 index 0000000..280bdcc --- /dev/null +++ b/DB/General/Deployment/schema.psql @@ -0,0 +1,3 @@ +CREATE SCHEMA Cabinet; +CREATE SCHEMA Auth; +CREATE SCHEMA Billing; diff --git a/DB/General/Deployment/tables.psql b/DB/General/Deployment/tables.psql new file mode 100644 index 0000000..b6fb051 --- /dev/null +++ b/DB/General/Deployment/tables.psql @@ -0,0 +1,16 @@ +CREATE TABLE IF NOT EXISTS Cabinet.Cabinet +( + id SERIAL PRIMARY KEY, + title text +); + +CREATE TABLE IF NOT EXISTS Auth."user" ( + id SERIAL PRIMARY KEY, + fullname text, + email text, + cabinetid integer DEFAULT 0, + isadmin boolean DEFAULT false, + login TEXT, + password TEXT, + FOREIGN KEY (CabinetId) REFERENCES Cabinet.Cabinet (Id) +); \ No newline at end of file diff --git a/DB/General/dbchangelog-master.xml b/DB/General/dbchangelog-master.xml new file mode 100644 index 0000000..6c9f244 --- /dev/null +++ b/DB/General/dbchangelog-master.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DB/General/docker-compose.yml b/DB/General/docker-compose.yml new file mode 100644 index 0000000..a8e3413 --- /dev/null +++ b/DB/General/docker-compose.yml @@ -0,0 +1,22 @@ +version: '3.8' +name: instructage-database + +services: + instructage-liquibase-accident: + container_name: instructage-liquibase-general + image: liquibase/liquibase:latest-alpine + volumes: + - .:/liquibase/changelog/ + entrypoint: + - "/bin/sh" + - "-c" + - sleep 0s && liquibase --defaultsFile=/liquibase/changelog/liquibase.properties update + + + +# docker network create instructage-network + +networks: + default: + external: true + name: instructage-network \ No newline at end of file diff --git a/DB/General/liquibase.properties b/DB/General/liquibase.properties new file mode 100644 index 0000000..2357de6 --- /dev/null +++ b/DB/General/liquibase.properties @@ -0,0 +1,5 @@ +searchPath: /liquibase/changelog +url: jdbc:postgresql://pg-instructage/general +changeLogFile: dbchangelog-master.xml +username:postgres +password:f0e87ce7-b857-4bbc-907c-ff0ab90514ad \ No newline at end of file diff --git a/Deploy.ps1 b/Deploy.ps1 new file mode 100644 index 0000000..bab2ebb --- /dev/null +++ b/Deploy.ps1 @@ -0,0 +1,18 @@ +docker network create instructage-network + +Set-Location PGServer +docker-compose down -v +docker-compose up --build -d + +Set-Location ../pgAdmin +docker-compose down -v +docker-compose up --build -d + +timeout 5 + +Set-Location ../db +Set-Location General +docker-compose down -v +docker-compose up --build -d + +Set-Location ../../ diff --git a/PGServer/docker-compose.yml b/PGServer/docker-compose.yml new file mode 100644 index 0000000..4fca6b2 --- /dev/null +++ b/PGServer/docker-compose.yml @@ -0,0 +1,60 @@ +version: '3.8' +name: instructage-database + +services: + pg-instructage: + container_name: pg-instructage + image: postgres:latest + restart: always + ports: + - 9999:5432 + environment: + POSTGRES_DB: postgres + POSTGRES_USER: postgres + POSTGRES_PASSWORD: "f0e87ce7-b857-4bbc-907c-ff0ab90514ad" + PGDATA: "/data" + #Включение логирования + command: [ "postgres", "-c", "log_statement=all", "-c", "log_destination=stderr", "-c", "log_duration=off" , "-c", "log_min_duration_statement=1000ms" ] + volumes: + #Путь, по которому будут лежать файлы баз данных + - instructage-db-data:/data + #При первом запуске через точку инициализации создаются пустые базы данных для дальнейшего заполнения через liquibase + - ./docker-entrypoint-initdb.d/:/docker-entrypoint-initdb.d/ + + # pgadmin: + # container_name: pgadmin + # image: dpage/pgadmin4:latest + # ports: + # - 15432:80 + # environment: + # PGADMIN_DEFAULT_EMAIL: sa@sa.sa + # PGADMIN_DEFAULT_PASSWORD: simDev321 + # PGADMIN_LISTEN_PORT: 80 + # volumes: + # - pgadmin:/var/lib/pgadmin + # depends_on: + # - pg-instructage + +volumes: + instructage-db-data: + # driver: local + # driver_opts: + # o: bind + # type: none + # device: C:/Postgres/pgdata + + + # pgadmin: + # name: pgadmin + # driver: local + # driver_opts: + # o: bind + # type: none + # device: C:/Postgres/PgAdmin + +# docker network create instructage-network + +networks: + default: + external: true + name: instructage-network diff --git a/PGServer/docker-entrypoint-initdb.d/init.sql b/PGServer/docker-entrypoint-initdb.d/init.sql new file mode 100644 index 0000000..fcb7171 --- /dev/null +++ b/PGServer/docker-entrypoint-initdb.d/init.sql @@ -0,0 +1 @@ +CREATE DATABASE General; \ No newline at end of file diff --git a/pgAdmin/docker-compose.yml b/pgAdmin/docker-compose.yml new file mode 100644 index 0000000..2289936 --- /dev/null +++ b/pgAdmin/docker-compose.yml @@ -0,0 +1,33 @@ +version: '3.8' +name: instructage-database + +services: + pgadmin: + container_name: pgadmin + image: dpage/pgadmin4:latest + ports: + - 15432:80 + environment: + PGADMIN_DEFAULT_EMAIL: sa@sa.sa + PGADMIN_DEFAULT_PASSWORD: simDev321 + PGADMIN_LISTEN_PORT: 80 + volumes: + - pgadmin:/var/lib/pgadmin + # depends_on: + # - postgres + +volumes: + pgadmin: + # name: pgadmin + # driver: local + # driver_opts: + # o: bind + # type: none + # device: D:/Docker/PostgreSQL/PgAdmin + +# docker network create fgissout-network + +networks: + default: + external: true + name: instructage-network \ No newline at end of file