DROP TABLE IF EXISTS DELEGATE_ELECTION;

CREATE TABLE DELEGATE_ELECTION (
  ID_INTERNAL int(11) NOT NULL auto_increment,
  OJB_CONCRETE_CLASS VARCHAR(255) NOT NULL,
  KEY_CANDIDACY_PERIOD int(11),
  KEY_VOTING_PERIOD int(11),
  KEY_DEGREE int(11) NOT NULL,
  KEY_ELECTED_STUDENT int(11),
  KEY_EXECUTION_YEAR int(11) NOT NULL,
  KEY_CURRICULAR_YEAR int(11) NOT NULL,
  KEY_ROOT_DOMAIN_OBJECT int(11) NOT NULL default '1',
  PRIMARY KEY  (ID_INTERNAL),
  KEY KEY_CANDIDACY_PERIOD (KEY_CANDIDACY_PERIOD),
  KEY KEY_VOTING_PERIOD (KEY_VOTING_PERIOD),
  KEY KEY_DEGREE (KEY_DEGREE),
  KEY KEY_ELECTED_STUDENT (KEY_ELECTED_STUDENT),
  KEY KEY_EXECUTION_YEAR (KEY_EXECUTION_YEAR),
  KEY KEY_CURRICULAR_YEAR (KEY_CURRICULAR_YEAR),
  KEY KEY_ROOT_DOMAIN_OBJECT (KEY_ROOT_DOMAIN_OBJECT)
) ENGINE=InnoDB;


DROP TABLE IF EXISTS DELEGATE_ELECTION_CANDIDATES_STUDENT;

CREATE TABLE DELEGATE_ELECTION_CANDIDATES_STUDENT (
  KEY_DELEGATE_ELECTION int(11) NOT NULL,
  KEY_STUDENT int(11) NOT NULL,
  PRIMARY KEY  (KEY_DELEGATE_ELECTION, KEY_STUDENT),
  KEY KEY_DELEGATE_ELECTION (KEY_DELEGATE_ELECTION),
  KEY KEY_STUDENT (KEY_STUDENT)
) ENGINE=InnoDB;


DROP TABLE IF EXISTS DELEGATE_ELECTION_STUDENT;

CREATE TABLE DELEGATE_ELECTION_STUDENT (
  KEY_DELEGATE_ELECTION int(11) NOT NULL,
  KEY_STUDENT int(11) NOT NULL,
  PRIMARY KEY  (KEY_DELEGATE_ELECTION, KEY_STUDENT),
  KEY KEY_DELEGATE_ELECTION (KEY_DELEGATE_ELECTION),
  KEY KEY_STUDENT (KEY_STUDENT)
) ENGINE=InnoDB;


DROP TABLE IF EXISTS DELEGATE_ELECTION_VOTING_STUDENT;

CREATE TABLE DELEGATE_ELECTION_VOTING_STUDENT (
  KEY_DELEGATE_ELECTION int(11) NOT NULL,
  KEY_STUDENT int(11) NOT NULL,
  PRIMARY KEY  (KEY_DELEGATE_ELECTION, KEY_STUDENT),
  KEY KEY_DELEGATE_ELECTION (KEY_DELEGATE_ELECTION),
  KEY KEY_STUDENT (KEY_STUDENT)
) ENGINE=InnoDB;

DROP TABLE IF EXISTS DELEGATE_ELECTION_PERIOD;

CREATE TABLE DELEGATE_ELECTION_PERIOD (
  ID_INTERNAL int(11) NOT NULL auto_increment,
  OJB_CONCRETE_CLASS VARCHAR(255) NOT NULL,
  START_DATE VARCHAR(255),
  END_DATE VARCHAR(255),
  KEY_DELEGATE_ELECTION int(11),
  KEY_ROOT_DOMAIN_OBJECT int(11) NOT NULL default '1',
  PRIMARY KEY  (ID_INTERNAL),
  KEY KEY_DELEGATE_ELECTION (KEY_DELEGATE_ELECTION),
  KEY KEY_ROOT_DOMAIN_OBJECT (KEY_ROOT_DOMAIN_OBJECT)
) ENGINE=InnoDB;

DROP TABLE IF EXISTS DELEGATE_ELECTION_VOTE;

CREATE TABLE DELEGATE_ELECTION_VOTE (
  ID_INTERNAL int(11) NOT NULL auto_increment,
  KEY_DELEGATE_ELECTION int(11) NOT NULL,
  KEY_STUDENT int(11) NOT NULL,
  KEY_ROOT_DOMAIN_OBJECT int(11) NOT NULL default '1',
  PRIMARY KEY  (ID_INTERNAL),
  KEY KEY_DELEGATE_ELECTION (KEY_DELEGATE_ELECTION),
  KEY KEY_STUDENT (KEY_STUDENT),
  KEY KEY_ROOT_DOMAIN_OBJECT (KEY_ROOT_DOMAIN_OBJECT)
) ENGINE=InnoDB;