CREATE TABLE IF NOT EXISTS `elections` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `agora_id` smallint NOT NULL,
  `position` varchar(64) NOT NULL,
  `maxVotes` smallint NOT NULL,
  `open` datetime,
  `close` datetime,
  
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS `candidates` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `candidate_uid` varchar(100),
  `name` varchar(64),
  `surname` varchar(64),
  `election_id` int(11),
  `votes` int(11),
  
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS `ballots` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ticket` int(11),
  `election_id` int(11) NOT NULL,
  `candidate_id` int(11),
  
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;

CREATE TABLE IF NOT EXISTS `elections_bodies` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `election_id` int(11) NOT NULL,
  `bodyCode` varchar(3) NOT NULL,
  `votes` smallint,
  
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
