-- Deploy gaia:api_2015_11_14_tables_for_activity to mysql

BEGIN;

CREATE TABLE `api_activity` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `title` varchar(128) NOT NULL,
    `banner` varchar(128) NOT NULL,
    `description` longtext NOT NULL,
    `points` integer NOT NULL,
    `start_time` datetime(6) NOT NULL,
    `end_time` datetime(6),
    `is_online` bool NOT NULL,
    `show_win_list` bool NOT NULL,
    `win_limit` integer NOT NULL,
    `show_topics` bool NOT NULL,
    `participate_limit` integer NOT NULL,
	`participants` integer NOT NULL
)
;
CREATE TABLE `api_activitywinlist` (
    `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
    `activity_id` integer NOT NULL,
    `person_id` char(32) NOT NULL,
    `topic` integer NOT NULL,
    `created_at` datetime(6) NOT NULL
)
;
ALTER TABLE `api_activitywinlist` ADD CONSTRAINT `person_id_refs_id_ef9fd85f` FOREIGN KEY (`person_id`) REFERENCES `api_person` (`id`);
ALTER TABLE `api_activitywinlist` ADD CONSTRAINT `activity_id_refs_id_2b42bce4` FOREIGN KEY (`activity_id`) REFERENCES `api_activity` (`id`);

ALTER TABLE `api_problem` ADD COLUMN `activity_id` integer;
ALTER TABLE `api_problem` ADD CONSTRAINT `activity_id_refs_id_14d4dbff` FOREIGN KEY (`activity_id`) REFERENCES `api_activity` (`id`);

COMMIT;
