/*
-- Query:
-- Date: 2020-05-14 20:59
*/
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (1,'Tested');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (2,'Sold');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (3,'Wiped');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (4,'Refunded');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (5,'Repaired');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (6,'Released to Owner');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (7,'Upgraded');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (8,'Received');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (9,'In Transit');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (10,'Picked Up');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (11,'Delivered');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (12,'Attempted');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (13,'Delayed');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (14,'Delivery Scheduled');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (15,'Note');
INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (16,'Other');


-- MySQL Workbench Synchronization
-- Generated: 2020-06-02 22:54
-- Model: New Model
-- Version: 1.0
-- Project: Name of the project
-- Author: Skylar Ittner

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

ALTER TABLE `c1machinemanager`.`components`
ADD COLUMN `manufacturer` VARCHAR(255) NULL DEFAULT NULL AFTER `price`;

CREATE TABLE IF NOT EXISTS `c1machinemanager`.`trackingcodes` (
  `trackid` INT(11) NOT NULL AUTO_INCREMENT,
  `machineid` VARCHAR(20) NOT NULL,
  `code` VARCHAR(255) NOT NULL,
  `codetype` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`trackid`, `machineid`),
  UNIQUE INDEX `trkid_UNIQUE` (`trackid` ASC),
  INDEX `fk_trackingcodes_machines1_idx` (`machineid` ASC),
  CONSTRAINT `fk_trackingcodes_machines1`
    FOREIGN KEY (`machineid`)
    REFERENCES `c1machinemanager`.`machines` (`machineid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE IF NOT EXISTS `c1machinemanager`.`containers` (
  `containerid` INT(11) NOT NULL AUTO_INCREMENT,
  `barcode` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`containerid`),
  UNIQUE INDEX `containerid_UNIQUE` (`containerid` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE IF NOT EXISTS `c1machinemanager`.`container_contents` (
  `containerid` INT(11) NOT NULL,
  `machineid` VARCHAR(20) NOT NULL,
  PRIMARY KEY (`containerid`, `machineid`),
  INDEX `fk_containers_has_machines_machines1_idx` (`machineid` ASC),
  INDEX `fk_containers_has_machines_containers1_idx` (`containerid` ASC),
  CONSTRAINT `fk_containers_has_machines_containers1`
    FOREIGN KEY (`containerid`)
    REFERENCES `c1machinemanager`.`containers` (`containerid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_containers_has_machines_machines1`
    FOREIGN KEY (`machineid`)
    REFERENCES `c1machinemanager`.`machines` (`machineid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;


-- MySQL Workbench Synchronization
-- Generated: 2020-06-26 19:56
-- Model: New Model
-- Version: 1.0
-- Project: Name of the project
-- Author: Skylar Ittner

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

ALTER SCHEMA `c1machinemanager`  DEFAULT CHARACTER SET utf8  DEFAULT COLLATE utf8_general_ci ;

ALTER TABLE `c1machinemanager`.`machines`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ,
ADD COLUMN `type` INT(11) NOT NULL DEFAULT 14 AFTER `machineid`,
ADD INDEX `fk_machines_machine_types1_idx` (`type` ASC);

ALTER TABLE `c1machinemanager`.`components`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

ALTER TABLE `c1machinemanager`.`component_types`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

ALTER TABLE `c1machinemanager`.`events`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

ALTER TABLE `c1machinemanager`.`event_types`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

ALTER TABLE `c1machinemanager`.`schedule`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

ALTER TABLE `c1machinemanager`.`clients`
CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

CREATE TABLE IF NOT EXISTS `c1machinemanager`.`trackingcodes` (
  `trackid` INT(11) NOT NULL AUTO_INCREMENT,
  `machineid` VARCHAR(20) NOT NULL,
  `code` VARCHAR(255) NOT NULL,
  `codetype` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`trackid`, `machineid`),
  UNIQUE INDEX `trkid_UNIQUE` (`trackid` ASC),
  INDEX `fk_trackingcodes_machines1_idx` (`machineid` ASC),
  CONSTRAINT `fk_trackingcodes_machines1`
    FOREIGN KEY (`machineid`)
    REFERENCES `c1machinemanager`.`machines` (`machineid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE IF NOT EXISTS `c1machinemanager`.`container_contents` (
  `containerid` INT(11) NOT NULL,
  `machineid` VARCHAR(20) NOT NULL,
  PRIMARY KEY (`containerid`, `machineid`),
  INDEX `fk_containers_has_machines_machines1_idx` (`machineid` ASC),
  INDEX `fk_containers_has_machines_containers1_idx` (`containerid` ASC),
  CONSTRAINT `fk_containers_has_machines_containers1`
    FOREIGN KEY (`containerid`)
    REFERENCES `c1machinemanager`.`containers` (`containerid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_containers_has_machines_machines1`
    FOREIGN KEY (`machineid`)
    REFERENCES `c1machinemanager`.`machines` (`machineid`)
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

CREATE TABLE IF NOT EXISTS `c1machinemanager`.`machine_types` (
  `machinetypeid` INT(11) NOT NULL AUTO_INCREMENT,
  `typename` VARCHAR(50) NOT NULL,
  `icon` VARCHAR(50) NOT NULL,
  PRIMARY KEY (`machinetypeid`),
  UNIQUE INDEX `machinetypeid_UNIQUE` (`machinetypeid` ASC))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;

INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (1,'Desktop','fas fa-desktop');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (2,'Laptop','fas fa-laptop');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (3,'Server','fas fa-server');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (4,'Smartphone','fas fa-mobile-alt');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (5,'Network Device','fas fa-network-wired');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (6,'Keyboard','far fa-keyboard');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (7,'Mouse','fas fa-mouse');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (8,'Cable','fas fa-plug');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (9,'Tablet','fas fa-tablet-alt');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (10,'Television','fas fa-tv');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (11,'Storage Device','fas fa-hdd');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (12,'Speaker','fas fa-volume-up');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (13,'Device','fas fa-desktop');
INSERT INTO `machine_types` (`machinetypeid`,`typename`,`icon`) VALUES (14,'Machine','fas fa-desktop');

ALTER TABLE `c1machinemanager`.`machines`
ADD CONSTRAINT `fk_machines_machine_types1`
  FOREIGN KEY (`type`)
  REFERENCES `c1machinemanager`.`machine_types` (`machinetypeid`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;


INSERT INTO `event_types` (`eventid`,`eventname`) VALUES (99, 'Device ID Generated');

ALTER TABLE `machines`
ADD COLUMN `deleted` TINYINT(1) NOT NULL DEFAULT 0 AFTER `publicnotes`;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;


-- MySQL Workbench Synchronization
-- Generated: 2020-07-15 18:11
-- Model: New Model
-- Version: 1.0
-- Project: Name of the project
-- Author: Skylar Ittner

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

ALTER TABLE `machinemanager`.`components`
DROP FOREIGN KEY `fk_components_machines1`;

ALTER TABLE `machinemanager`.`components`
CHANGE COLUMN `machineid` `machineid` VARCHAR(20) NULL DEFAULT NULL ,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`compid`);

ALTER TABLE `machinemanager`.`components`
ADD CONSTRAINT `fk_components_machines1`
  FOREIGN KEY (`machineid`)
  REFERENCES `machinemanager`.`machines` (`machineid`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
