-- -----------------------------------------------------
-- Table imageTypeT
-- -----------------------------------------------------
DROP TABLE IF EXISTS imageTypeT ;

CREATE TABLE IF NOT EXISTS imageTypeT (
  id CHAR(10) BINARY NOT NULL,
  isDefault ENUM('y') NULL,
  added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  UNIQUE INDEX isDefault_UNIQUE (isDefault ASC))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Data for table imageTypeT
-- -----------------------------------------------------
START TRANSACTION;
INSERT INTO imageTypeT (id, isDefault, added) VALUES ('image', 'y', NULL);
INSERT INTO imageTypeT (id, isDefault, added) VALUES ('panorama', NULL, NULL);
INSERT INTO imageTypeT (id, isDefault, added) VALUES ('video', NULL, NULL);

COMMIT;


-- -----------------------------------------------------
-- Table imageT
-- -----------------------------------------------------
alter table imageT add imageTypeId char(10) binary not null after sorter;

update imageT set
    imageTypeId = 'image';

alter table imageT add videoType varchar(50) not null defaulT '' after imageTypeId;
alter table imageT add url varchar(255) not null default '' after videoType;
alter table imageT add extraId varchar(255) not null default '' after url;

alter table imageT add addedUserId int unsigned null after added;
alter table imageT add addedUserName varchar(255) null after addedUserId;
alter table imageT add addedIp varchar(40) null after addedUserName;
alter table imageT add changedUserId int unsigned null after changed;
alter table imageT add changedUserName varchar(255) null after changedUserId;
alter table imageT add changedIp varchar(40) null after changedUserName;

alter table imageT add index fk_imageT_imageTypeT1_idx (imageTypeId asc);
alter table imageT add constraint fk_imageT_imageTypeT1
    foreign key (imageTypeId)
    references imageTypeT (id)
    on delete no action
    on update no action;

