Skip to content

Commit 4147f89

Browse files
Merge pull request #7 from ChrisSaxonOra/inventory-shipments
Inventory shipments
2 parents 6428dd7 + 61a511e commit 4147f89

File tree

9 files changed

+6495
-3921
lines changed

9 files changed

+6495
-3921
lines changed

customer_orders/co_comments.sql

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ comment on column order_items.unit_price
119119

120120
comment on column order_items.quantity
121121
is 'How many items of this product the customer purchased';
122+
123+
comment on column order_items.shipment_id
124+
is 'Where this product will be delivered';
122125

123126
comment on table customer_order_products
124127
is 'A summary of who placed each order and what they bought';
@@ -202,4 +205,41 @@ comment on column product_orders.total_sales
202205
is 'The total value of orders placed';
203206

204207
comment on column product_orders.order_count
205-
is 'The total number of orders placed';
208+
is 'The total number of orders placed';
209+
210+
comment on table shipments
211+
is 'Details of where ordered goods will be delivered';
212+
213+
comment on column shipments.shipment_id
214+
is 'Auto-incrementing primary key';
215+
216+
comment on column shipments.store_id
217+
is 'Which location the goods will be transported from';
218+
219+
comment on column shipments.customer_id
220+
is 'Who this shipment is for';
221+
222+
comment on column shipments.delivery_address
223+
is 'Where the goods will be transported to';
224+
225+
comment on column shipments.shipment_status
226+
is 'The current status of the shipment. Valid values are:
227+
CREATED - the shipment is ready for order assignment
228+
SHIPPED - the goods have been dispatched
229+
IN-TRANSIT - the goods are en-route to their destination
230+
DELIVERED - the good have arrived at their destination';
231+
232+
comment on table inventory
233+
is 'Details of the quantity of stock available for products at each location';
234+
235+
comment on column inventory.inventory_id
236+
is 'Auto-incrementing primary key';
237+
238+
comment on column inventory.store_id
239+
is 'Which location the goods are located at';
240+
241+
comment on column inventory.product_id
242+
is 'Which item this stock is for';
243+
244+
comment on column inventory.product_inventory
245+
is 'The current quantity in stock';

customer_orders/co_constraints.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,37 @@ alter table orders add constraint orders_status_c
3030
alter table orders add constraint orders_store_id_fk foreign key (store_id)
3131
references stores (store_id);
3232

33+
alter table shipments add constraint shipments_pk primary key (shipment_id);
34+
35+
alter table shipments add constraint shipments_store_id_fk
36+
foreign key (store_id) references stores (store_id);
37+
38+
alter table shipments add constraint shipments_customer_id_fk
39+
foreign key (customer_id) references customers (customer_id);
40+
41+
alter table shipments add constraint shipment_status_c
42+
check ( shipment_status in
43+
( 'CREATED', 'SHIPPED', 'IN-TRANSIT', 'DELIVERED'));
44+
3345
alter table order_items add constraint order_items_pk primary key ( order_id, line_item_id );
3446

3547
alter table order_items add constraint order_items_order_id_fk
3648
foreign key (order_id) references orders (order_id);
3749

50+
alter table order_items add constraint order_items_shipment_id_fk
51+
foreign key (shipment_id) references shipments (shipment_id);
52+
3853
alter table order_items add constraint order_items_product_id_fk
3954
foreign key (product_id) references products (product_id);
4055

4156
alter table order_items add constraint order_items_product_u unique ( product_id, order_id );
57+
58+
alter table inventory add constraint inventory_pk primary key (inventory_id);
59+
60+
alter table inventory add constraint inventory_store_product_u unique (store_id, product_id);
61+
62+
alter table inventory add constraint inventory_store_id_fk
63+
foreign key (store_id) references stores (store_id);
64+
65+
alter table inventory add constraint shipments_product_id_fk
66+
foreign key (product_id) references products (product_id);

customer_orders/co_dml.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
PROMPT Removing existing data
22

33
truncate table order_items;
4+
truncate table inventory;
5+
delete shipments;
46
delete orders;
57
delete stores;
68
delete customers;
@@ -12,7 +14,9 @@ PROMPT Inserting data
1214
@@products
1315
@@stores
1416
@@orders
17+
@@shipments
1518
@@order_items
19+
@@inventory
1620

1721
commit;
1822

customer_orders/co_drop_objects.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ drop table stores
1515
cascade constraints;
1616
drop table customers
1717
cascade constraints;
18+
drop table inventory
19+
cascade constraints;
20+
drop table shipments
21+
cascade constraints;

customer_orders/co_set_identity_starts.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ alter table customers
1818

1919
alter table orders
2020
modify order_id
21+
generated by default on null as identity (
22+
start with limit value
23+
);
24+
25+
alter table shipments
26+
modify shipment_id
27+
generated by default on null as identity (
28+
start with limit value
29+
);
30+
31+
alter table inventory
32+
modify inventory_id
2133
generated by default on null as identity (
2234
start with limit value
2335
);

customer_orders/co_tables.sql

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,37 @@ create table orders (
4141
store_id integer not null)
4242
;
4343

44+
create table shipments (
45+
shipment_id integer
46+
generated by default on null as identity,
47+
store_id integer not null,
48+
customer_id integer not null,
49+
delivery_address varchar2(512 char) not null,
50+
shipment_status varchar2(100 char) not null)
51+
;
52+
4453
create table order_items (
45-
order_id integer not null,
46-
line_item_id integer not null,
47-
product_id integer not null,
48-
unit_price number(10,2) not null,
49-
quantity integer not null)
54+
order_id integer not null,
55+
line_item_id integer not null,
56+
product_id integer not null,
57+
unit_price number(10,2) not null,
58+
quantity integer not null,
59+
shipment_id integer)
60+
;
61+
62+
create table inventory (
63+
inventory_id integer
64+
generated by default on null as identity,
65+
store_id integer not null,
66+
product_id integer not null,
67+
product_inventory integer not null)
5068
;
5169

5270
PROMPT Creating indexes
5371

5472
create index customers_name_i on customers ( full_name );
5573
create index orders_customer_id_i on orders ( customer_id );
56-
create index orders_store_id_i on orders ( store_id );
74+
create index orders_store_id_i on orders ( store_id );
75+
create index shipments_store_id_i on shipments ( store_id );
76+
create index shipments_customer_id_i on shipments ( customer_id );
77+
create index inventory_product_id_i on inventory ( product_id );

0 commit comments

Comments
 (0)