Skip to content

Commit

Permalink
[Feat] schema.sql
Browse files Browse the repository at this point in the history
Separated database table/view initialization to a separate script, which
is runned upon starting the postgres docker container.

References #58, #59, #60, #61 and #62.
  • Loading branch information
angel-penchev committed Jan 27, 2021
1 parent 730273a commit ef9a0ea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ services:

database:
image: "postgres"
logging:
driver: none
ports:
- 5432:5432
env_file:
- .env
volumes:
- ./schema.sql:/docker-entrypoint-initdb.d/schema.sql

queue:
image: "rabbitmq:management"
Expand All @@ -105,8 +105,8 @@ services:
image: "nginx:stable"
depends_on:
- order-service
# - delivery-service
# - user-service
- delivery-service
- user-service
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
Expand Down
30 changes: 30 additions & 0 deletions server/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE IF NOT EXISTS orders (
id UUID PRIMARY KEY,
sender_id UUID NOT NULL,
sender_location_latitude FLOAT8 NOT NULL,
sender_location_longitude FLOAT8 NOT NULL,
receiver_id UUID NOT NULL,
receiver_location_latitude FLOAT8 NOT NULL,
receiver_location_longitude FLOAT8 NOT NULL,
source_ip TEXT NOT NULL,
source_browser TEXT NOT NULL,
source_referrer TEXT,
created_on TIMESTAMPTZ NOT NULL
);


DROP VIEW IF EXISTS orders_view;
CREATE VIEW orders_view AS
SELECT
a.id,
a.sender_id as senderId,
a.sender_location_latitude AS senderLocationLatitude,
a.sender_location_longitude AS senderLocationLongitude,
a.receiver_id AS receiverId,
a.receiver_location_latitude AS receiverLocationLatitude,
a.receiver_location_longitude AS receiverLocationLongitude,
a.source_ip AS sourceIp,
a.source_browser AS sourceBrowser,
a.source_referrer AS sourceReferrer,
a.created_on AS createdOn
FROM orders as a

0 comments on commit ef9a0ea

Please sign in to comment.