Open Mvitimin opened 1 year ago
restaurant-schema.sql
DROP SCHEMA IF EXISTS restaurant CASCADE;
CREATE SCHEMA restaurant;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
DROP TABLE IF EXISTS restaurant.restaurants CASCADE;
CREATE TABLE restaurant.restaurants
(
id uuid NOT NULL,
name character varying COLLATE pg_catalog."default" NOT NULL,
active boolean NOT NULL,
CONSTRAINT restaurants_pkey PRIMARY KEY (id)
);
DROP TYPE IF EXISTS approval_status;
CREATE TYPE approval_status AS ENUM ('APPROVED', 'REJECTED');
DROP TABLE IF EXISTS restaurant.order_approval CASCADE;
CREATE TABLE restaurant.order_approval
(
id uuid NOT NULL,
restaurant_id uuid NOT NULL,
order_id uuid NOT NULL,
status approval_status NOT NULL,
CONSTRAINT order_approval_pkey PRIMARY KEY (id)
);
DROP TABLE IF EXISTS restaurant.products CASCADE;
CREATE TABLE restaurant.products
(
id uuid NOT NULL,
name character varying COLLATE pg_catalog."default" NOT NULL,
price numeric(10,2) NOT NULL,
available boolean NOT NULL,
CONSTRAINT products_pkey PRIMARY KEY (id)
);
DROP TABLE IF EXISTS restaurant.restaurant_products CASCADE;
CREATE TABLE restaurant.restaurant_products
(
id uuid NOT NULL,
restaurant_id uuid NOT NULL,
product_id uuid NOT NULL,
CONSTRAINT restaurant_products_pkey PRIMARY KEY (id)
);
ALTER TABLE restaurant.restaurant_products
ADD CONSTRAINT "FK_RESTAURANT_ID" FOREIGN KEY (restaurant_id)
REFERENCES restaurant.restaurants (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE RESTRICT
NOT VALID;
ALTER TABLE restaurant.restaurant_products
ADD CONSTRAINT "FK_PRODUCT_ID" FOREIGN KEY (product_id)
REFERENCES restaurant.products (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE RESTRICT
NOT VALID;
DROP MATERIALIZED VIEW IF EXISTS restaurant.order_restaurant_m_view;
CREATE MATERIALIZED VIEW restaurant.order_restaurant_m_view
TABLESPACE pg_default
AS
SELECT r.id AS restaurant_id,
r.name AS restaurant_name,
r.active AS restaurant_active,
p.id AS product_id,
p.name AS product_name,
p.price AS product_price,
p.available AS product_available
FROM restaurant.restaurants r,
restaurant.products p,
restaurant.restaurant_products rp
WHERE r.id = rp.restaurant_id AND p.id = rp.product_id
WITH DATA;
refresh materialized VIEW restaurant.order_restaurant_m_view;
DROP function IF EXISTS restaurant.refresh_order_restaurant_m_view;
CREATE OR replace function restaurant.refresh_order_restaurant_m_view()
returns trigger
AS '
BEGIN
refresh materialized VIEW restaurant.order_restaurant_m_view;
return null;
END;
' LANGUAGE plpgsql;
DROP trigger IF EXISTS refresh_order_restaurant_m_view ON restaurant.restaurant_products;
CREATE trigger refresh_order_restaurant_m_view
after INSERT OR UPDATE OR DELETE OR truncate
ON restaurant.restaurant_products FOR each statement
EXECUTE PROCEDURE restaurant.refresh_order_restaurant_m_view();
restaurant-data.sql
INSERT INTO restaurant.restaurants(id, name, active)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb45', 'restaurant_1', TRUE);
INSERT INTO restaurant.restaurants(id, name, active)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb46', 'restaurant_2', FALSE);
INSERT INTO restaurant.products(id, name, price, available)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb47', 'product_1', 25.00, FALSE);
INSERT INTO restaurant.products(id, name, price, available)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb48', 'product_2', 50.00, TRUE);
INSERT INTO restaurant.products(id, name, price, available)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb49', 'product_3', 20.00, FALSE);
INSERT INTO restaurant.products(id, name, price, available)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb50', 'product_4', 40.00, TRUE);
INSERT INTO restaurant.restaurant_products(id, restaurant_id, product_id)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb51', 'd215b5f8-0249-4dc5-89a3-51fd148cfb45', 'd215b5f8-0249-4dc5-89a3-51fd148cfb47');
INSERT INTO restaurant.restaurant_products(id, restaurant_id, product_id)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb52', 'd215b5f8-0249-4dc5-89a3-51fd148cfb45', 'd215b5f8-0249-4dc5-89a3-51fd148cfb48');
INSERT INTO restaurant.restaurant_products(id, restaurant_id, product_id)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb53', 'd215b5f8-0249-4dc5-89a3-51fd148cfb46', 'd215b5f8-0249-4dc5-89a3-51fd148cfb49');
INSERT INTO restaurant.restaurant_products(id, restaurant_id, product_id)
VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb54', 'd215b5f8-0249-4dc5-89a3-51fd148cfb46', 'd215b5f8-0249-4dc5-89a3-51fd148cfb50');
{
"customerId": "d215b5f8-0249-4dc5-89a3-51fd148cfb41",
"restaurantId": "d215b5f8-0249-4dc5-89a3-51fd148cfb45",
"address": {
"street": "street_1",
"postalCode": "1000AB",
"city": "Amsterdam"
},
"price": 200.00,
"items": [
{
"productId": "d215b5f8-0249-4dc5-89a3-51fd148cfb48",
"quantity": 1,
"price": 50.00,
"subTotal": 50.00
},
{
"productId": "d215b5f8-0249-4dc5-89a3-51fd148cfb48",
"quantity": 3,
"price": 50.00,
"subTotal": 150.00
}
]
}
{
"customerId": "d215b5f8-0249-4dc5-89a3-51fd148cfb41",
"username": "user_1",
"firstName": "First",
"lastName": "User"
}
Compression 압축률
http://happinessoncode.com/2019/01/18/kafka-compression-ratio/
Producer Configuration
https://docs.confluent.io/platform/current/installation/configuration/producer-configs.html
Consumer Configuration
https://docs.confluent.io/platform/current/installation/configuration/consumer-configs.html
Avro
https://docs.confluent.io/platform/current/schema-registry/fundamentals/serdes-develop/serdes-avro.html#