-- CREATE TABLE sma_families (
-- `id`  int NOT NULL AUTO_INCREMENT ,
-- `name`  varchar(255) NULL ,
-- `slug`  varchar(255) NULL ,
-- `view_order`  int NULL ,
-- PRIMARY KEY (`id`)
-- )
-- ;

CREATE TABLE IF NOT EXISTS `sma_families` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `image` varchar(55) DEFAULT 'default-family-image.png',
  `slug` varchar(255) DEFAULT NULL,
  `view_order` int(11) DEFAULT NULL,
  `code` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

ALTER TABLE `sma_products`
ADD COLUMN `family_id`  int NULL AFTER `second_name`;

CREATE TABLE `sma_menu_items` (
`id`  int NOT NULL AUTO_INCREMENT ,
`text`  varchar(100) NULL ,
`link`  varchar(255) NULL ,
`view_order`  int NULL ,
`parent_id` int NULL,
PRIMARY KEY (`id`)
)
;

ALTER TABLE `sma_menu_items`
ADD COLUMN `level`  int NULL DEFAULT '0' AFTER `parent_id`;



-- Default Image Query

update sma_products set image = 'default-product-image.png' where image is null;
update sma_categories set image = 'default-category-image.png' where image is null;

ALTER TABLE `sma_categories`
MODIFY COLUMN `image`  varchar(55) CHARACTER SET utf8 COLLATE uFtf8_general_ci NULL DEFAULT 'default-category-image.png' AFTER `name`;


ALTER TABLE `sma_products`
MODIFY COLUMN `image`  varchar(55) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'default-product-image.png' AFTER `name`;


-----

CREATE TABLE `sma_menu_item_categories` (
  `id` int(11) NOT NULL,
  `menu_item_id` int(11) NOT NULL,
  `sub_category_id` int(11) NOT NULL,
  `view_order` int(11) DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `sma_menu_item_categories`
  ADD PRIMARY KEY (`id`);


  ALTER TABLE `sma_menu_item_categories`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=48;COMMIT;

  -----

  CREATE TABLE `sma_customer_groups_categories_discounts` (
  `id` int(11) NOT NULL,
  `customer_group_id` int(11) NOT NULL AUTO_INCREMENT,
  `category_id` int(11) NOT NULL,
  `percent` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

ALTER TABLE `sma_customer_groups_categories_discounts`
  ADD PRIMARY KEY (`id`);


UPDATE `sma_customer_groups` SET `percent`=0 WHERE 1

-----

