- Database Structure Summary
- Database Creation Description
- Database Schema
- Entity Relationship Diagram
- Database Normalization
- Running the Database
Marketplace was chosen as the business for which the database is being designed. The database consists of several tables, each representing a different entity.
-
Customers: Stores information about the customers.
-
Addresses: Stores the addresses of the customers.
-
Payment Methods: Stores the payment methods of the customers.
-
Sellers: Stores information about the sellers.
-
Orders: Stores information about the orders.
-
Items: Stores information about the items.
-
Customer Item Cart: Stores information about the items in the customer's cart.
-
Customer Item Wish: Stores information about the items in the customer's wish list.
-
Rates: Stores the ratings and comments given by customers to items.
-
Order Item: Stores information about the connection between items and order.
-
Warehouses: Stores information about the warehouses.
-
Warehouse Items: Stores information about the items in a warehouse.
Each table has a primary key, which uniquely identifies each record in the table. There are also several foreign key relationships between the tables, which establish links between related data across tables. For example, the customer_id in the Addresses table is a foreign key that references the id in the Customers table. This means that each address is associated with a specific customer.
This database is designed to support a variety of operations for an e-commerce platform, including customer management, order processing, item management, and warehouse management.
-
CREATE TABLE "customers" ( "id" integer PRIMARY KEY, "name" varchar, "surname" varchar, "login" varchar, "password" varchar, "age" int, "verified" boolean, "created_at" timestamp, "cart_price" float );We Started from creating table
customersit contains information about customers. Then we decided that we want to store delivery addresses and payment methods of customers. As one customer can have more than one addresses and payment method we created two more tablesaddressesandpayment_methodswhich are connected tocustomerstable by foreign keys. -
CREATE TABLE "addresses" ( "id" integer PRIMARY KEY, "customer_id" integer, "address" varchar ); -
CREATE TABLE "payment_methods" ( "customer_id" integer, "card_number" varchar, "cvc" int, "card_holder" varchar, "valid_until" varchar, PRIMARY KEY ("customer_id", "card_number") ); -
CREATE TABLE "sellers" ( "id" integer PRIMARY KEY, "title" varchar, "login" varchar, "password" varchar, "rate" float, "created_at" timestamp, "address" varchar, "card_number" varchar, "total_sales" float ); -
CREATE TABLE "items" ( "id" integer PRIMARY KEY, "title" varchar, "category" enum, "rate" float, "description" text, "seller_id" integer, "cost" float, "created_at" timestamp ); -
CREATE TABLE "customer_item_cart" ( "customer_id" integer, "item_id" integer, "amount" int, PRIMARY KEY ("customer_id", "item_id") );Table
customer_item_cartcontains information about items that are present in the cart of customers. It is connected tocustomersanditemstables by foreign keyscustomer_idanditem_id. By adding item to cart we connect customer with item. Primary key constraint is added tocustomer_idanditem_idto avoid duplication of product in one cart. -
CREATE TABLE "customer_item_wish" ( "customer_id" integer, "item_id" integer, PRIMARY KEY ("customer_id", "item_id") ); -
CREATE TABLE "rates" ( "customer_id" integer, "item_id" integer, "rate" float, "body" text, PRIMARY KEY ("customer_id", "item_id") ); -
CREATE TABLE "orders" ( "id" integer PRIMARY KEY, "customer_id" integer, "delivery_address" varchar, "status" enum, "total_cost" float, "created_at" timestamp, "comment" text ); -
CREATE TABLE "order_item" ( "order_id" integer, "item_id" integer, "amount" int, PRIMARY KEY ("order_id", "item_id") ); -
CREATE TABLE "warehouses" ( "id" integer PRIMARY KEY, "title" varchar, "address" varchar ); -
CREATE TABLE "warehouse_items" ( "warehouse_id" integer, "item_id" integer, "amount" int, PRIMARY KEY ("warehouse_id", "item_id") );
Here is the schema of the database that was created for the prototype. It is autogenerated from working instance of postgres database.
During the design of the database, we followed these steps:
Each cell in the table must contain only a single value, and that value must be atomic, i.e., it cannot be divided further.
No Repeating Groups: Each column should have a single value corresponding to each row. Avoid repeating groups or arrays in a single column.
Each non-prime attribute (i.e., not part of any candidate key) must be fully functionally dependent on the entire primary key, not just part of it. This means that every attribute in the table must be functionally dependent on the primary key.
There should be no transitive dependencies. This means that no non-prime attribute should be dependent on another non-prime attribute. Every non-prime attribute must be directly dependent on the primary key.
Ensure it meets 1NF and there are no partial dependencies, meaning every attribute is fully dependent on the primary key.
Ensure it meets 2NF and there are no transitive dependencies, meaning every non-prime attribute is directly dependent on the primary key.
To run the database you need to run postgres database on your local machine. You can do it by running the following command in the terminal:
docker-compose up

