
CREATE TABLE `was_user_attachment` (
  `user_attachment_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int(11) unsigned NOT NULL,
  `file_name` varchar(100) NOT NULL,
  `file_size` int(11) unsigned NOT NULL,
  `extension` varchar(10) NOT NULL,
  `file_title` varchar(200) DEFAULT NULL,
  `file_description` text DEFAULT NULL,
  `file_url` varchar(200) NOT NULL,
  `thumbnail_url` varchar(200) DEFAULT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`user_attachment_id`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB COMMENT='Store attachments files uploaded by users';

CREATE TRIGGER `was_user_attachment_insert_timestamp` BEFORE INSERT ON `was_user_attachment`
 FOR EACH ROW SET NEW.insert_timestamp = NOW();


CREATE TABLE `was_event_attachment` (
  `event_attachment_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `event_id` int(11) unsigned NOT NULL,
  `user_attachment_id` int(11) unsigned NOT NULL,
  `insert_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `update_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`event_attachment_id`),
  KEY `idx_event` (`event_id`),
  KEY `idx_user_attachment` (`user_attachment_id`)
) ENGINE=InnoDB COMMENT='Store attachments files used in the event';

CREATE TRIGGER `was_event_attachment_insert_timestamp` BEFORE INSERT ON `was_event_attachment`
 FOR EACH ROW SET NEW.insert_timestamp = NOW();

