Added project
This commit is contained in:
5
docker/db/Dockerfile
Normal file
5
docker/db/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM postgres:10-alpine
|
||||
COPY scripts/*.sql /docker-entrypoint-initdb.d/
|
||||
ADD scripts/1_init_schema.sql /docker-entrypoint-initdb.d
|
||||
ADD scripts/2_init_data.sql /docker-entrypoint-initdb.d
|
||||
RUN chmod a+r /docker-entrypoint-initdb.d/*
|
||||
32
docker/db/scripts/1_init_schema.sql
Normal file
32
docker/db/scripts/1_init_schema.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
CREATE SEQUENCE seq_employees START 5000;
|
||||
|
||||
CREATE TABLE employees
|
||||
(
|
||||
id BIGINT PRIMARY KEY DEFAULT nextval('seq_employees'),
|
||||
name VARCHAR NOT NULL,
|
||||
email VARCHAR NOT NULL
|
||||
);
|
||||
CREATE UNIQUE INDEX employees_unique_email_idx ON employees (email);
|
||||
|
||||
CREATE TABLE employee_personal_accounts (
|
||||
id BIGINT PRIMARY KEY DEFAULT nextval('seq_employees'),
|
||||
employee_id BIGINT NOT NULL,
|
||||
personal_account VARCHAR NOT NULL,
|
||||
FOREIGN KEY (employee_id) REFERENCES employees (id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE UNIQUE INDEX employee_personal_accounts_unique_employee_account_idx
|
||||
ON employee_personal_accounts (employee_id, personal_account);
|
||||
|
||||
CREATE TABLE personal_account_operations (
|
||||
id BIGINT PRIMARY KEY DEFAULT nextval('seq_employees'),
|
||||
personal_account_id BIGINT NOT NULL,
|
||||
operation_date_time TIMESTAMP NOT NULL,
|
||||
operation_type VARCHAR NOT NULL,
|
||||
-- Money data on PostgreSQL using Java https://stackoverflow.com/a/18170030
|
||||
operation_value DECIMAL NOT NULL,
|
||||
FOREIGN KEY (personal_account_id) REFERENCES employee_personal_accounts (id) ON DELETE CASCADE
|
||||
);
|
||||
CREATE UNIQUE INDEX personal_account_operations_unique_account_datetime_idx
|
||||
ON personal_account_operations (personal_account_id, operation_date_time);
|
||||
|
||||
|
||||
34
docker/db/scripts/2_init_data.sql
Normal file
34
docker/db/scripts/2_init_data.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
INSERT INTO employees (name, email) VALUES
|
||||
('Ivanov Ivan Ivanovich', 'ivanov@example.com'),
|
||||
('Petrov Vasily Victorovich', 'petrov@example.com');
|
||||
|
||||
INSERT INTO employee_personal_accounts (personal_account, employee_id)
|
||||
VALUES ('4154014152522741', 5000),
|
||||
('4131668358915203', 5000),
|
||||
('4281563275602455', 5000),
|
||||
('4103234971123321', 5001),
|
||||
('4132555843841699', 5001);
|
||||
|
||||
INSERT INTO personal_account_operations (operation_date_time, operation_type, operation_value, personal_account_id)
|
||||
VALUES ('2020-05-30 10:00:00'::timestamp, 'DEPOSIT', 840.35, 5002),
|
||||
('2020-05-28 11:05:10'::timestamp, 'DEPOSIT', 625.00, 5002),
|
||||
('2020-05-25 11:41:10'::timestamp, 'DEPOSIT', 1080.45, 5002),
|
||||
('2020-05-30 14:00:10'::timestamp, 'WITHDRAW', 652.33, 5002),
|
||||
('2020-05-26 18:10:10'::timestamp, 'WITHDRAW', 420.00, 5002),
|
||||
('2020-06-30 10:00:00'::timestamp, 'DEPOSIT', 1500.52, 5003),
|
||||
('2020-06-30 11:05:10'::timestamp, 'DEPOSIT', 800.73, 5003),
|
||||
('2020-06-30 14:00:10'::timestamp, 'WITHDRAW', 170.35, 5003),
|
||||
('2020-06-30 18:10:10'::timestamp, 'WITHDRAW', 320.00, 5003),
|
||||
('2020-07-15 12:05:10'::timestamp, 'DEPOSIT', 800.73, 5004),
|
||||
('2020-07-15 12:41:10'::timestamp, 'DEPOSIT', 350.00, 5004),
|
||||
('2020-07-15 15:00:10'::timestamp, 'WITHDRAW', 900.35, 5004),
|
||||
('2020-07-15 17:10:10'::timestamp, 'WITHDRAW', 600.00, 5004),
|
||||
('2020-05-15 11:05:10'::timestamp, 'DEPOSIT', 976.33, 5005),
|
||||
('2020-05-15 11:41:10'::timestamp, 'DEPOSIT', 850.00, 5005),
|
||||
('2020-05-15 14:00:10'::timestamp, 'WITHDRAW', 200.00, 5005),
|
||||
('2020-05-15 18:10:10'::timestamp, 'WITHDRAW', 375.85, 5005),
|
||||
('2020-04-30 09:00:00'::timestamp, 'DEPOSIT', 1200.52, 5006),
|
||||
('2020-04-30 10:35:00'::timestamp, 'DEPOSIT', 300.53, 5006),
|
||||
('2020-04-30 10:55:00'::timestamp, 'DEPOSIT', 450.60, 5006),
|
||||
('2020-04-30 12:20:10'::timestamp, 'WITHDRAW', 300.00, 5006),
|
||||
('2020-04-30 14:10:10'::timestamp, 'WITHDRAW', 402.95, 5006);
|
||||
15
docker/docker-compose.yml
Normal file
15
docker/docker-compose.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
version: '3.3'
|
||||
|
||||
services:
|
||||
db:
|
||||
build: ./db
|
||||
container_name: postgres
|
||||
volumes:
|
||||
- ./db_data/:/var/lib/postgresql/data/
|
||||
ports:
|
||||
- "7654:5432"
|
||||
restart: always
|
||||
environment:
|
||||
- POSTGRES_USER=test
|
||||
- POSTGRES_PASSWORD=test
|
||||
- POSTGRES_DB=test
|
||||
Reference in New Issue
Block a user