--
-- Database: minibase_material
--
CREATE DATABASE IF NOT EXISTS minibase_material DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE minibase_material;

DROP TABLE IF EXISTS products;
CREATE TABLE products (
	  product_id int(11) NOT NULL COMMENT 'Primary Key for Database referencing',
	  manufacturer varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'The mane of the manufacturer',
	  product_no varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'The product No of the manufacturer ',
	  core_product varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Core product no of the manufacturer ',
	  ordering_code varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Ordering code from the manufacturer, if it is different than the product no',
	  description varchar(300) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'A brief and simple description of the article',
	  status varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Actual status of the products life cycle',
	  buy_cost float NOT NULL COMMENT 'our standard buy price.',
	  pricing_scheme varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'If the manufacturer of the product allows a pricing scheme for this product',
	  price_change_flag tinyint(1) NOT NULL COMMENT 'did the price changed since the last update ? this flag should be carefully monitored to be sure that every client was informed before resetting it !!!',
	  currency varchar(6) NOT NULL COMMENT 'The currency with which the manufaturer sells'
	  lead_time_days int(11) NOT NULL COMMENT 'Actual lead time on this product in days',
	  physical_form int(11) NOT NULL COMMENT 'The physical form of the product. is it a flower ? or is it a box or is it tssop18 packaged IC ?',
	  packing varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Available packing options for the product, plastic wrap, tray, bulk, reel and so on.',
	  packing_size int(11) NOT NULL COMMENT 'How many items are there in one packing ? Ex : A basket of 50 tomatoes. ',
	  minimum_order_quantity int(11) NOT NULL COMMENT 'What is the minimum order quantity that the manufacturer allows. no one will send you only one flower seed. ',
	  minimum_awarding_quantity int(11) NOT NULL COMMENT 'If we support an customer of ours and the manufacturer proposes a special pricing condition for this product. This is the quantity that must be reached before we can be awarded for our efforts in order to get the promised special price.   ',
	  minimum_quote_quantity int(11) NOT NULL COMMENT 'If no special pricing conditions are available, this is the first price break quantity. for the rest a quotation should be asked.  ',
	  proposed_margin int(11) NOT NULL COMMENT 'Margins defined/proposed by the organisation for this article ',
	  container varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Shipping container form of the packaged product.',
	  container_size int(11) NOT NULL COMMENT 'How many items are there in one shipping container ? 5 baskets of 50 tomatoes for a total of 250 tomatoes.',
	  product_class int(11) NOT NULL COMMENT 'Class of product. \r\nThis should be defined by the organisation.',
	  product_category int(11) NOT NULL COMMENT 'Category of the product. \r\nThis should be linked to the product_categories_table defined by the organisation.',
	  product_family int(11) NOT NULL COMMENT 'Family of the product. \r\nThis should be defined by the organisation.',
	  product_group int(11) NOT NULL COMMENT 'Group of the product. \r\nThis should be defined by the organisation.',
	  last_update_date date NOT NULL COMMENT 'Last date that this product has had an updated field',
	  last_time_buy_date date NOT NULL COMMENT 'Last time that this product can be purchased',
	  obsolete_date date NOT NULL COMMENT 'The date since/at which this product will be declared obsolete',
	  pollution_level varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Depending on the Product some pollution level requirement can be met or not.',
	  production_site int(11) NOT NULL COMMENT 'The production site for this product. This should be linked to the manufacturer profile.',
	  comment_manufacturer varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Comments fomr the manufaturer'
	  comment varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Special comments. '
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE products
  ADD PRIMARY KEY (product_id);

ALTER TABLE products
  MODIFY product_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key for Database referencing';
-- --------------------------------------------------------

DROP TABLE IF EXISTS product_categories;
CREATE TABLE product_categories (
	  category_id int(11) NOT NULL COMMENT 'Primary Key for database use',
	  category_reference int(11) NOT NULL COMMENT 'Internal reference no o this category. if a logical referencing is needed instead of the category_id. ',
	  category_name varchar(75) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Name of the category',
	  category_description int(11) NOT NULL COMMENT 'Description of the category'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE product_categories
  ADD PRIMARY KEY (category_id);

ALTER TABLE product_categories
  MODIFY category_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key for database referencing';
-- --------------------------------------------------------

DROP TABLE IF EXISTS product_classes;
CREATE TABLE product_classes (
	  class_id int(11) NOT NULL COMMENT 'Primary Key for database use',
	  class_reference int(11) NOT NULL COMMENT 'Internal reference no o this class. if a logical referencing is needed instead of the class_id. ',
	  class_name varchar(75) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Name of the class',
	  class_description int(11) NOT NULL COMMENT 'Description of the class'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE product_classes
  ADD PRIMARY KEY (class_id);

ALTER TABLE product_classes
  MODIFY class_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key for database referencing';
-- --------------------------------------------------------

DROP TABLE IF EXISTS product_families;
CREATE TABLE product_families (
	  family_id int(11) NOT NULL COMMENT 'Primary Key for database use',
	  family_reference int(11) NOT NULL COMMENT 'Internal reference no o this family. if a logical referencing is needed instead of the family_id. ',
	  family_name varchar(75) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Name of the family',
	  family_description int(11) NOT NULL COMMENT 'Description of the family'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE product_families
  ADD PRIMARY KEY (family_id);

ALTER TABLE product_families
  MODIFY family_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key for database referencing';
-- --------------------------------------------------------


DROP TABLE IF EXISTS product_groups;
CREATE TABLE product_groups (
	  goup_id int(11) NOT NULL COMMENT 'Primary Key for database use',
	  group_reference int(11) NOT NULL COMMENT 'Internal reference no o this group. if a logical referencing is needed instead of the group_id. ',
	  group_name varchar(75) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Name of the group',
	  group_description int(11) NOT NULL COMMENT 'Description of the group'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

ALTER TABLE product_groups
  ADD PRIMARY KEY (goup_id);


ALTER TABLE product_groups
  MODIFY goup_id int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key for database referencing';
COMMIT;
