diff --git a/db/sql/1-tables.sql b/db/sql/1-tables.sql index d5d7224..d0dba16 100644 --- a/db/sql/1-tables.sql +++ b/db/sql/1-tables.sql @@ -46,7 +46,8 @@ create table sos."item" ( item_description text not null, item_urlslug citext unique not null, item_price_cents integer not null, - item_published boolean not null default true + item_published boolean not null default true, + item_tax_percent_override numeric(8,6) null ); create table sos."cart_item" ( @@ -261,3 +262,7 @@ create table sos."item_stockchange_admin" ( stockchange_withdrawal_uuid uuid references sos."admin_withdrawal" (withdrawal_uuid) ); + +create table sos."config" ( + config_default_tax_percent numeric(8,6) not null default 7.250 +); diff --git a/db/sql/2-views.sql b/db/sql/2-views.sql index d116bf6..1440f1d 100644 --- a/db/sql/2-views.sql +++ b/db/sql/2-views.sql @@ -1,6 +1,12 @@ create or replace view sos.v_item as select - "item".*, + "item".item_uuid, + "item".item_name, + "item".item_description, + "item".item_urlslug, + "item".item_price_cents, + "item".item_published, + coalesce("item".item_tax_percent_override, "config".config_default_tax_percent) as item_tax_rate, "image".image_uuid, "image".image_featured, "image".image_mime_type, @@ -8,6 +14,7 @@ create or replace view sos.v_item as "user".user_email as uploader_email, coalesce(num_added - num_removed, 0) as item_number_in_stock from sos."item" + left join sos."config" on true left join sos."image" on item.item_uuid = image.image_item_uuid left join sos."user" on image.image_uploader_uuid = "user".user_uuid left join