CREATE TABLE `OrderLineFriendPaymentStatus` (
  `id`    INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name`  VARCHAR(50)      NULL     DEFAULT NULL,
  `phase` INT              NOT NULL,
  `order` INT              NOT NULL,
  PRIMARY KEY (`id`)
)
  COMMENT = 'Tabella di gestione dei pagamenti ai friend'
  COLLATE = 'utf8_general_ci'
  ENGINE = InnoDB;

ALTER TABLE `OrderLine`
ADD COLUMN `orderLineFriendPaymentStatusId` INT(10) UNSIGNED NULL
AFTER `status`,
ADD CONSTRAINT `fk_OrderLine_OrderLineFriendPaymentStatus` FOREIGN KEY (`orderLineFriendPaymentStatusId`) REFERENCES `OrderLineFriendPaymentStatus` (`id`)
  ON UPDATE NO ACTION
  ON DELETE NO ACTION;

ALTER TABLE `OrderLine`
ADD COLUMN `orderLineFriendPaymentDate` TIMESTAMP NULL
AFTER `orderLineFriendPaymentStatusId`;


INSERT INTO `OrderLineFriendPaymentStatus` VALUES (1, 'To Pay', 1, 1);
INSERT INTO `OrderLineFriendPaymentStatus` VALUES (2, 'In Payment', 2, 2);
INSERT INTO `OrderLineFriendPaymentStatus` VALUES (3, 'Paying', 3, 3);
INSERT INTO `OrderLineFriendPaymentStatus` VALUES (4, 'Paid', 4, 4);

ALTER TABLE OrderLine DROP friendAcceptanceDate;
ALTER TABLE OrderLine DROP shipmentBookingDate;
ALTER TABLE OrderLine DROP arrivalDate;
ALTER TABLE OrderLine DROP acceptanceDate;