Skip to content

Commit

Permalink
build: Set up new db-docker connection
Browse files Browse the repository at this point in the history
Co-authored-by: Youssef Muhamad <[email protected]>
Co-authored-by: Rogerio Junior <[email protected]>
  • Loading branch information
3 people committed Mar 4, 2021
1 parent 68b222e commit d3baaf6
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ run:
run-silent:
sudo docker-compose -f docker-compose.dev.yml up -d

run-build:
sudo docker-compose -f docker-compose.dev.yml up --build

test:
sudo docker-compose -f docker-compose.dev.yml run request python manage.py test

Expand Down
10 changes: 5 additions & 5 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ services:
environment:
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres@db:5432/request_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@db:5432/request_test
- DATABASE_URL=postgres://postgres:postgres@db:5432/requestlenditdb_dev
- DATABASE_TEST_URL=postgres://postgres:postgres@db:5432/requestlenditdb_test
depends_on:
- db

db:
build:
context: ./project/db
dockerfile: Dockerfile
image: postgres:13.2-alpine
ports:
- 5106:5432
volumes:
- ./project/db:/docker-entrypoint-initdb.d
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
6 changes: 0 additions & 6 deletions project/db/Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions project/db/create.sql

This file was deleted.

37 changes: 37 additions & 0 deletions project/db/create_dev.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE DATABASE requestLendItDB_dev
WITH
ENCODING = UTF8
LC_COLLATE = 'pt_BR.UTF-8'
LC_CTYPE = 'pt_BR.UTF-8'
TEMPLATE = template0;

\c requestlenditdb_dev

CREATE TABLE PRODUCT_CATEGORY (
productCategoryId SMALLSERIAL NOT NULL,
name TEXT NOT NULL,

CONSTRAINT PRODUCT_CATEGORY_PK PRIMARY KEY (productCategoryId)
);

CREATE TABLE REQUEST (
requestId UUID NOT NULL,
productName TEXT NOT NULL,
startDate DATE NOT NULL,
endDate DATE NOT NULL,
description TEXT NOT NULL,
requester TEXT NOT NULL,
lender TEXT NULL,
productCategoryId SMALLSERIAL NOT NULL,

CONSTRAINT REQUEST_PK PRIMARY KEY (requestId),

CONSTRAINT REQUEST_PRODUCT_CATEGORY_FK FOREIGN KEY (productCategoryId)
REFERENCES PRODUCT_CATEGORY (productCategoryId)
ON DELETE RESTRICT
ON UPDATE RESTRICT,

CONSTRAINT VALID_REQUESTER_EMAIL CHECK (requester ~* '^[\w\-\.]+@([\w-]+\.)+[\w-]{2,4}$'),
CONSTRAINT VALID_LENDER_EMAIL CHECK (lender ~* '^[\w\-\.]+@([\w-]+\.)+[\w-]{2,4}$'),
CONSTRAINT VALID_LENDER_USER CHECK (requester <> lender)
);
37 changes: 37 additions & 0 deletions project/db/create_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE DATABASE requestLendItDB_test
WITH
ENCODING = UTF8
LC_COLLATE = 'pt_BR.UTF-8'
LC_CTYPE = 'pt_BR.UTF-8'
TEMPLATE = template0;

\c requestlenditdb_test

CREATE TABLE PRODUCT_CATEGORY (
productCategoryId SMALLSERIAL NOT NULL,
name TEXT NOT NULL,

CONSTRAINT PRODUCT_CATEGORY_PK PRIMARY KEY (productCategoryId)
);

CREATE TABLE REQUEST (
requestId UUID NOT NULL,
productName TEXT NOT NULL,
startDate DATE NOT NULL,
endDate DATE NOT NULL,
description TEXT NOT NULL,
requester TEXT NOT NULL,
lender TEXT NULL,
productCategoryId SMALLSERIAL NOT NULL,

CONSTRAINT REQUEST_PK PRIMARY KEY (requestId),

CONSTRAINT REQUEST_PRODUCT_CATEGORY_FK FOREIGN KEY (productCategoryId)
REFERENCES PRODUCT_CATEGORY (productCategoryId)
ON DELETE RESTRICT
ON UPDATE RESTRICT,

CONSTRAINT VALID_REQUESTER_EMAIL CHECK (requester ~* '^[\w\-\.]+@([\w-]+\.)+[\w-]{2,4}$'),
CONSTRAINT VALID_LENDER_EMAIL CHECK (lender ~* '^[\w\-\.]+@([\w-]+\.)+[\w-]{2,4}$'),
CONSTRAINT VALID_LENDER_USER CHECK (requester <> lender)
);
2 changes: 1 addition & 1 deletion project/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create_app(self):
return app

def test_app_is_production(self):
elf.assertTrue(app.config["SECRET_KEY"] == "my_precious")
self.assertTrue(app.config["SECRET_KEY"] == "my_precious")
self.assertFalse(app.config["TESTING"])


Expand Down

0 comments on commit d3baaf6

Please sign in to comment.