Inventory Databases FFFFF
Inventory Databases FFFFF
The very first step is to create the Inventory Database. It can be created using the query
as shown below.
CREATE SCHEMA `inventory` DEFAULT CHARACTER SET utf8mb4 COLLATE
utf8mb4_unicode_ci;
I have used the character set utf8mb4 to support a wide range of characters.
User Table
In this section, we will design the User Table to store user information. Users can
manage their own profiles. Also, the users can use the application according to the roles
assigned to them. You can also refer to the tutorial RBAC Database in MySql to
implement a complete RBAC system for managing roles and permissions. Below
mentioned is the description of all the columns of the User Table.
Id The unique id to identify the user.
Role Id The role of the user. It can be Admin, Supplier, Salesperson, and Customer.
First Name The first name of the user.
Middle Name The middle name of the user.
Last Name The last name of the user.
Mobile The mobile number of the user. It can be used for login and registration purposes.
Email The email of the user. It can be used for login and registration purposes.
Password The password hash generated by the appropriate algorithm. We must avoid storing plain o
Hash passwords.
Registered At This column can be used to calculate the life of the user with the application.
Last Login It can be used to identify the last login of the user.
Intro A brief introduction of the User.
Profile User details.
The User Table with the appropriate constraints is shown below.
CREATE TABLE `inventory`.`user` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`roleId` SMALLINT NOT NULL,
`firstName` VARCHAR(50) NULL DEFAULT NULL,
`middleName` VARCHAR(50) NULL DEFAULT NULL,
`lastName` VARCHAR(50) NULL DEFAULT NULL,
`username` VARCHAR(50) NULL DEFAULT NULL,
`mobile` VARCHAR(15) NULL,
`email` VARCHAR(50) NULL,
`passwordHash` VARCHAR(32) NOT NULL,
`registeredAt` DATETIME NOT NULL,
`lastLogin` DATETIME NULL DEFAULT NULL,
`intro` TINYTEXT NULL DEFAULT NULL,
`profile` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `uq_username` (`username` ASC),
UNIQUE INDEX `uq_mobile` (`mobile` ASC),
UNIQUE INDEX `uq_email` (`email` ASC) );
Product Table
In this section, we will design the Product Table to store the product data. Below
mentioned is the description of all the columns of the Product Table.
Id The unique id to identify the product.
Title The product title to be displayed on the Inventory.
Summary The summary to mention the key highlights.
Type The type to distinguish between the different product types.
Created At It stores the date and time at which the product is created.
Updated At It stores the date and time at which the product is updated.
Content The column used to store the additional details of the product.
The Product Table with the appropriate constraints is shown below.
CREATE TABLE `inventory`.`product` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(75) NOT NULL,
`summary` TINYTEXT NULL,
`type` SMALLINT(6) NOT NULL DEFAULT 0,
`createdAt` DATETIME NOT NULL,
`updatedAt` DATETIME NULL DEFAULT NULL,
`content` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
Product Meta
The Product Meta Table can be used to store additional information about products
including the product banner URL etc. Below mentioned is the description of all the
columns of the Product Meta Table.
Id The unique id to identify the product meta.
Product Id The product id to identify the parent product.
Key The key identifying the meta.
Content The column used to store the product metadata.
The Product Meta Table with the appropriate constraints is as shown below.
CREATE TABLE `inventory`.`product_meta` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`productId` BIGINT NOT NULL,
`key` VARCHAR(50) NOT NULL,
`content` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `idx_meta_product` (`productId` ASC),
UNIQUE INDEX `uq_product_meta` (`productId` ASC, `key` ASC),
CONSTRAINT `fk_meta_product`
FOREIGN KEY (`productId`)
REFERENCES `inventory`.`product` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
Category Table and Product Category Table
In this section, we will design the Category Table and Product Category Table to store
the product categories and their mappings. Below mentioned is the description of all the
columns of the Category Table.
Id The unique id to identify the category.
Parent Id The parent id to identify the parent category.
Title The category title.
Meta Title The meta title to be used for browser title and SEO.
Slug The category slug to form the URL.
Content The column used to store the category details.
The Category Table with the appropriate constraints is as shown below.
CREATE TABLE `inventory`.`category` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`parentId` BIGINT NULL DEFAULT NULL,
`title` VARCHAR(75) NOT NULL,
`metaTitle` VARCHAR(100) NULL DEFAULT NULL,
`slug` VARCHAR(100) NOT NULL,
`content` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`id`));