-
countryTable:- This table stores information about countries.
- It has a primary key
id, anamefield to store the country name, and various timestamp fields (created_atandupdated_at) to track the creation and modification times of records. - Additionally, it has fields for sorting order ("order"), whether the country is published (
is_published), and whether it is active (is_active).
-
vatTable:- This table stores information about Value Added Tax (VAT) rates for different products or services.
- It has a primary key
id, anamefield to describe the VAT, avatfield to store the VAT rate, and timestamp fields (created_atandupdated_at) for record management. - Similar to the
countrytable, it also has fields for sorting order, publication status, and activity status.
-
countryvatTable:- This is an intermediate table used to establish a many-to-many relationship between countries and VAT rates.
- It contains foreign keys
country_idandvat_idthat reference theidfields in thecountryandvattables, respectively. - The primary key for this table is a combination of
country_idandvat_id, making sure that each combination of country and VAT rate is unique.
-
customerTable:- This table stores information about customers.
- It has a primary key
id, a foreign keycountry_idthat references theidfield in thecountrytable, a foreign keyvat_idthat references theidfield in thevattable, and fields for the customer's name and timestamps. - Like other tables, it also has fields for sorting order, publication status, and activity status.
-
customeraddressTable:- This table stores the addresses of customers.
- It has a primary key
id, a foreign keycustomer_idthat references theidfield in thecustomertable, anaddressfield to store the address information, and timestamps. - As usual, it has fields for sorting order, publication status, and activity status.
-
bannerTable:- This table stores information about banners, which are typically used for advertising.
- It has a primary key
id, alocationfield to indicate where the banner is displayed, fields for acode, aurl, and anbanner_imageto represent the banner, and timestamps. - Also, fields for sorting order, publication status, and activity status are included.
-
bannerstatisticTable:- This table tracks statistics for banner views.
- It has a primary key
id, a foreign keybanner_idthat references theidfield in thebannertable, asession_idfield to identify the session during which the banner was viewed, and timestamps.
-
appointmentTable:- This table stores information about appointments.
- It has a primary key
id, adescriptionfield for the appointment description, astart_atfield to store the start time of the appointment, and timestamps. - As usual, fields for sorting order, publication status, and activity status are included.
-
pressreleaseTable:- This table stores information about press releases.
- It has a primary key
id, adescriptionfield for the press release content, afilepathfield to store the file path of the press release (if any), and timestamps. - Additionally, fields for sorting order, publication status, and activity status are included.
-
mediaTable:- This table stores information about media files.
- It has a primary key
id, amedia_pathfield to store the path of the media file, and timestamps. - Similar to other tables, fields for sorting order, publication status, and activity status are included.
-
eventTable:- This table stores information about events.
- It has a primary key
id, anamefield to store the event name, adescriptionfield for the event details,start_atandend_atfields to indicate the event's start and end times, and timestamps. - Also, fields for sorting order, publication status, and activity status are included.
-
eventmediaTable:- This table establishes a many-to-many relationship between events and media files.
- It contains foreign keys
event_idandmedia_idthat reference theidfields in theeventandmediatables, respectively. - The primary key for this table is a combination of
event_idandmedia_id, ensuring uniqueness of event-media associations.
-
supplierTable:- This table stores information about suppliers.
- It has a primary key
id, anamefield to store the supplier's name, and timestamps. - As usual, fields for sorting order, publication status, and activity status are included.
-
tagTable:- This table stores information about tags.
- It has a primary key
id, anamefield to store the tag name, and timestamps. - Similarly, fields for sorting order, publication status, and activity status are included.
-
brandTable:- This table stores information about brands.
- It has a primary key
id, anamefield for the brand name, alogo_imagefield to store the path of the brand's logo image (if any), and timestamps. - Additionally, fields for sorting order, publication status, and activity status are included.
-
supplierbrandTable:- This table establishes a many-to-many relationship between suppliers and brands.
- It contains foreign keys
brand_idandsupplier_idthat reference theidfields in thebrandandsuppliertables, respectively. - The primary key for this table is a combination of
brand_idandsupplier_id, ensuring uniqueness of brand-supplier associations.
-
categoryTable:- This table stores information about categories.
- It has a primary key
id, ahero_imagefield to store the path of the category's hero image (if any), anamefield for the category name, and timestamps. - Also, fields for sorting order, publication status, and activity status are included.
-
relatedcategoryTable:- This table establishes a many-to-many relationship between categories.
- It contains foreign keys
from_category_idandto_category_idthat reference theidfields in thecategorytable. - The primary key for this table is a combination of
from_category_idandto_category_id, ensuring uniqueness of category-category associations.
-
featureTable:- This table stores information about product features.
- It has a primary key
id, anamefield to store the feature name, and timestamps. - As usual, fields for sorting order, publication status, and activity status are included.
-
featureattributeTable:- This table stores information about attributes related to features.
- It has a primary key
id, a foreign keyfeature_idthat references theidfield in thefeaturetable, anamefield for the attribute name, and timestamps.
-
categoryfeatureTable:- This table establishes a many-to-many relationship between categories and features.
- It contains foreign keys
feature_idandcategory_idthat reference theidfields in thefeatureandcategorytables, respectively. - The primary key for this table is a combination of
feature_idandcategory_id, ensuring uniqueness of feature-category associations.
-
productTable:- This table stores information about products available in the online store.
- It has a primary key
id, a foreign keybrand_idthat references theidfield in thebrandtable (indicating the product's brand), anamefield for the product name, ahero_imagefield to store the path of the product's hero image (if any), and timestamps. - As usual, fields for sorting order, publication status, and activity status are included.
-
relatedproductTable:- This table establishes a many-to-many relationship between products.
- It contains foreign keys
from_product_idandto_product_idthat reference theidfield in theproducttable. - The primary key for this table is a combination of
from_product_idandto_product_id, ensuring uniqueness of product-product associations.
-
productsupplierTable:- This table establishes a many-to-many relationship between products and suppliers.
- It contains foreign keys
product_idandsupplier_idthat reference theidfields in theproductandsuppliertables, respectively. - The primary key for this table is a combination of
product_idandsupplier_id, ensuring uniqueness of product-supplier associations.
-
productpriceTable:- This table stores pricing information for products based on various criteria such as country, VAT rate, and supplier.
- It contains foreign keys
product_id,vat_id,country_id, andsupplier_idthat reference the corresponding tables (product, vat, country, and supplier), representing the specific product's price in a given country, with a particular VAT rate, from a specific supplier. - The table also contains a
pricefield to store the price of the product, ais_defaultfield to indicate if this is the default price for the product, and timestamps.
-
productcustomerpriceTable:- This table stores pricing information for products based on various criteria such as country, VAT rate, and customer.
- It contains foreign keys
product_id,vat_id,country_id, andcustomer_idthat reference the corresponding tables (product, vat, country, and customer), representing the specific product's price for a given customer in a particular country, with a specific VAT rate. - The table also contains a
pricefield to store the price of the product for the customer, ais_defaultfield to indicate if this is the default price for the product-customer combination, and timestamps.
-
productcategoryTable:- This table establishes a many-to-many relationship between products and categories.
- It contains foreign keys
product_idandcategory_idthat reference theidfields in theproductandcategorytables, respectively. - The primary key for this table is a combination of
product_idandcategory_id, ensuring uniqueness of product-category associations.
-
producttagTable:- This table establishes a many-to-many relationship between products and tags.
- It contains foreign keys
product_idandtag_idthat reference theidfields in theproductandtagtables, respectively. - The primary key for this table is a combination of
product_idandtag_id, ensuring uniqueness of product-tag associations.
-
productmediaTable:- This table establishes a many-to-many relationship between products and media files.
- It contains foreign keys
product_idandmedia_idthat reference theidfields in theproductandmediatables, respectively. - The primary key for this table is a combination of
product_idandmedia_id, ensuring uniqueness of product-media associations.
-
productattributeTable:- This table stores information about product attributes.
- It contains foreign keys
product_id,feature_id, andfeatureattribute_idthat reference the corresponding tables (product, feature, and featureattribute). - The primary key for this table is a combination of
product_id,feature_id, andfeatureattribute_id, ensuring uniqueness of product-attribute associations.
-
offerTable:- This table stores information about offers or promotions available in the online store.
- It has a primary key
id, anamefield to describe the offer, adescriptionfield for additional details,start_atandend_atfields to specify the offer's duration, and timestamps. - As usual, fields for sorting order, publication status, and activity status are included.
-
offerdetailTable:- This table stores information about the details of offers and their associated products.
- It contains foreign keys
product_idandoffer_idthat reference theidfields in theproductandoffertables, respectively. - The table also contains a
pricefield to store the discounted price for the product during the offer, along with timestamps.
-
shoppingcartitemTable:- This table stores information about items in a shopping cart.
- It has a primary key
id, a foreign keyproduct_idthat references theidfield in theproducttable (indicating the product in the cart), aquantityfield to represent the number of products in the cart, acart_idfield to uniquely identify the shopping cart, and timestamps.
-
orderTable:- This table stores information about orders placed by customers.
- It has a primary key
id, atotalfield to store the total amount of the order, aquantityfield to represent the total quantity of products in the order, anemailfield to store the email address of the customer, and timestamps.
-
orderdetailTable:- This table stores information about the details of an order, including the products and quantities.
- It contains foreign keys
order_idandproduct_idthat reference theidfield in theorderandproducttables, respectively. - The table also contains a
quantityfield to represent the quantity of a product in the order and apricefield to store the price of the product at the time of the order, along with timestamps.
-
This database schema models various entities and their relationships in an e-commerce or online store application. The relationships between different tables are established using foreign keys, and the primary keys ensure the uniqueness of records within each table. The timestamps (created_at and updated_at) help track the creation and modification times of records.
Keep in mind that the schema provided here is just a starting point and may need further refinement based on specific application requirements and use cases. Additionally, the schema can be expanded or modified to accommodate new features and functionalities as the application evolves.
create table country(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table vat(
id serial primary key not null,
name varchar(200),
vat int not null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table countryvat(
country_id int references country(id),
vat_id int references vat(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(country_id, vat_id)
);
create table customer(
id serial primary key not null,
country_id int references country(id),
vat_id int references vat(id),
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table customeraddress(
id serial primary key not null,
customer_id int references customer(id),
address varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table banner(
id serial primary key not null,
location int not null default 1,
code text null,
url text null,
banner_image text null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table bannerstatistic(
id serial primary key not null,
banner_id int references banner(id),
session_id text null,
created_at timestamp not null default now()
);
create table appointment(
id serial primary key not null,
description text null,
start_at timestamp not null default now(),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table pressrelease(
id serial primary key not null,
description text null,
filepath text null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table media(
id serial primary key not null,
media_path text not null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table event(
id serial primary key not null,
name varchar(200),
description text null,
start_at timestamp not null default now(),
end_at timestamp not null default now(),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table eventmedia(
event_id int references event(id),
media_id int references media(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(event_id, media_id)
);
create table supplier(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table tag(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table brand(
id serial primary key not null,
name varchar(200),
logo_image text null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table supplierbrand(
brand_id int references brand(id),
supplier_id int references supplier(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(brand_id, supplier_id)
);
create table category(
id serial primary key not null,
hero_image text null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table relatedcategory(
from_category_id int references category(id),
to_category_id int references category(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(from_category_id, to_category_id)
);
create table feature(
id serial primary key not null,
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table featureattribute(
id serial primary key not null,
feature_id int references feature(id),
name varchar(200),
created_at timestamp not null default now(),
updated_at timestamp not null default now()
);
create table categoryfeature(
feature_id int references feature(id),
category_id int references feature(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(feature_id, category_id)
);
create table product(
id serial primary key not null,
brand_id int null references brand(id),
name varchar(200),
hero_image text null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table relatedproduct(
from_product_id int references product(id),
to_product_id int references product(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(from_product_id, to_product_id)
);
create table productsupplier(
product_id int references product(id),
supplier_id int references supplier(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(product_id, supplier_id)
);
create table productprice(
product_id int references product(id),
vat_id int references vat(id),
country_id int references country(id),
supplier_id int references supplier(id),
price NUMERIC(6, 4) not null default 0,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
is_default BOOLEAN NOT NULL default True,
PRIMARY KEY(product_id, country_id,vat_id, supplier_id)
);
create table productcustomerprice(
product_id int references product(id),
vat_id int references vat(id),
country_id int references country(id),
customer_id int references customer(id),
price NUMERIC(6, 4) not null default 0,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
is_default BOOLEAN NOT NULL default True,
PRIMARY KEY(product_id, country_id, vat_id, customer_id)
);
create table productcategory(
product_id int references product(id),
category_id int references category(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(product_id, category_id)
);
create table producttag(
product_id int references product(id),
tag_id int references tag(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(product_id, tag_id)
);
create table productmedia(
product_id int references product(id),
media_id int references media(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(product_id, media_id)
);
create table productattribute(
product_id int references product(id),
feature_id int references feature(id),
featureattribute_id int references featureattribute(id),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(product_id, feature_id, featureattribute_id)
);
create table offer(
id serial primary key not null,
name varchar(200),
description text null,
start_at timestamp not null default now(),
end_at timestamp not null default now(),
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
"order" int not null default 0,
is_published BOOLEAN NOT NULL default False,
is_active BOOLEAN NOT NULL default True
);
create table offerdetail(
product_id int references product(id),
offer_id int references offer(id),
price NUMERIC(6, 4) not null default 0,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(product_id, offer_id)
);
create table shoppingcartitem(
id serial primary key not null,
product_id int references product(id),
quantity int not null,
cart_id text not null,
created_at timestamp not null default now(),
updated_at timestamp not null default now()
);
create table "order"(
id serial primary key not null,
total NUMERIC(6, 4) not null,
quantity int not null,
email text not null,
created_at timestamp not null default now(),
updated_at timestamp not null default now()
);
create table orderdetail(
order_id int references "order"(id),
product_id int references product(id),
quantity int not null,
price NUMERIC(6, 4) not null,
created_at timestamp not null default now(),
updated_at timestamp not null default now(),
PRIMARY KEY(order_id, product_id)
);