CREATE DATABASE 'webshop' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;

# example link: https://fabric.inc/blog/commerce/ecommerce-database-design-example

CREATE TABLE 'user'
(
    id               int,
    lower_name       varchar(255),
    name             varchar(255),
    full_name        varchar(255),
    email            varchar(255),
    passwd           varchar(255),
    passwd_hash_algo varchar(255),
    is_admin         bool,
    created_at       timestamp,
    modified_at      timestamp
);

CREATE TABLE 'user_address'
(
    id            int,
    userid        int,
    address_line1 varchar(255),
    address_line2 varchar(255),
    city          varchar(255),
    postal_code   varchar(255),
    country       varchar(255),
    telephone     varchar(255),
    mobile        varchar(255)
);

CREATE TABLE 'user_payment'
(
    id           int,
    user_id      int,
    payment_type varchar(255),
    provider     varchar(255),
    account_no   int,
    expiry       date
);

CREATE TABLE 'shopping_session'
(
    id          int,
    user_id     varchar(255),
    total       decimal,
    created_at  timestamp,
    modified_at timestamp
);

CREATE TABLE 'cart_item'
(
    id          int,
    session_id  int,
    product_id  int,
    quantity    int,
    created_at  timestamp,
    modified_at timestamp
);

CREATE TABLE 'payment_details'
(
    id          int,
    order_id    int,
    amount      int,
    provider    varchar(255),
    status      varchar(255),
    created_at  timestamp,
    modified_at timestamp
);

CREATE TABLE 'order_items'
(
    id          int,
    order_id    int,
    product_id  int,
    quantity    int,
    created_at  timestamp,
    modified_at timestamp
);

CREATE TABLE 'order_details'
(
    id          int,
    user_id     varchar(255),
    total       decimal,
    payment_id  int,
    created_at  timestamp,
    modified_at timestamp
);

CREATE TABLE 'product'
(
    id           int,
    name         varchar(255),
    desc         text,
    SKU          varchar(255),
    category_id  int,
    inventory_id int,
    price        decimal,
    discount_id  int,
    created_at   timestamp,
    modified_at  timestamp,
    deleted_at   timestamp
);

CREATE TABLE 'product_category'
(
    id          int,
    name        varchar(255),
    desc        text,
    created_at  timestamp,
    modified_at timestamp,
    deleted_at  timestamp
);
CREATE TABLE 'product_inventory'
(
    id          int,
    quantity    int,
    created_at  timestamp,
    modified_at timestamp,
    deleted_at  timestamp
);
CREATE TABLE 'discount'
(
    id               int,
    name             varchar(255),
    desc             text,
    discount_percent decimal,
    active           bool,
    created_at       timestamp,
    modified_at      timestamp,
    deleted_at       timestamp
)