--------------------------------------------------------
--  File created - Wednesday-July-15-2015   
--------------------------------------------------------
-- DROP TABLE "CODES_MAPPING";
-- DROP TABLE "VERIFICATION_CONTENT";
-- DROP TABLE "VV_ELECTORAL_AUTHORITY";
-- DROP TABLE "VERIFICATION_DATA";
-- DROP TABLE "VERIFICATION_SET_DATA";
-- DROP SEQUENCE "CODES_MAPPING_SEQ";
-- DROP SEQUENCE "VERIFICATION_CONTENT_SEQ";
-- DROP SEQUENCE "VV_ELECTORAL_AUTHORITY_SEQ";
-- DROP SEQUENCE "VERIFICATION_DATA_SEQ";
-- DROP SEQUENCE "VERIFICATION_SET_DATA_SEQ";
--------------------------------------------------------
--  DDL for Sequence CODES_MAPPING_SEQ
--------------------------------------------------------

   CREATE SEQUENCE  "CODES_MAPPING_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence VERIFICATION_CONTENT_SEQ
--------------------------------------------------------

   CREATE SEQUENCE  "VERIFICATION_CONTENT_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence VV_ELECTORAL_AUTHORITY_SEQ
--------------------------------------------------------

   CREATE SEQUENCE  "VV_ELECTORAL_AUTHORITY_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence VERIFICATION_DATA_SEQ
--------------------------------------------------------

   CREATE SEQUENCE  "VERIFICATION_DATA_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Sequence VERIFICATION_SET_DATA_SEQ
--------------------------------------------------------

   CREATE SEQUENCE  "VERIFICATION_SET_DATA_SEQ"  MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE ;
--------------------------------------------------------
--  DDL for Table CODES_MAPPING
--------------------------------------------------------

  CREATE TABLE "CODES_MAPPING" 
   (	"ID" NUMBER(*,0), 
	"TENANT_ID" VARCHAR2(100 CHAR), 
	"ELECTION_EVENT_ID" VARCHAR2(100 CHAR), 
	"VERIFICATION_CARD_ID" VARCHAR2(100 CHAR), 
	"JSON" CLOB
   ) ;
--------------------------------------------------------
--  DDL for Table VERIFICATION_CONTENT
--------------------------------------------------------

  CREATE TABLE "VERIFICATION_CONTENT" 
   (	"ID" NUMBER(*,0), 
	"TENANT_ID" VARCHAR2(100 CHAR), 
	"ELECTION_EVENT_ID" VARCHAR2(100 BYTE), 
	"VERIFICATION_CARD_SET_ID" VARCHAR2(100 BYTE), 
	"JSON" CLOB
   ) ;
--------------------------------------------------------
--  DDL for Table VV_ELECTORAL_AUTHORITY
--------------------------------------------------------

  CREATE TABLE "VV_ELECTORAL_AUTHORITY" 
   (	"ID" NUMBER(*,0), 
	"TENANT_ID" VARCHAR2(100 CHAR), 
	"ELECTION_EVENT_ID" VARCHAR2(100 BYTE), 
	"ELECTORAL_AUTHORITY_ID" VARCHAR2(100 BYTE), 
	"JSON" CLOB
   ) ;
--------------------------------------------------------
--  DDL for Table VERIFICATION_DATA
--------------------------------------------------------

  CREATE TABLE "VERIFICATION_DATA" 
   (	"ID" NUMBER(*,0), 
	"TENANT_ID" VARCHAR2(100 BYTE), 
	"ELECTION_EVENT_ID" VARCHAR2(100 BYTE), 
	"VERIFICATION_CARD_ID" VARCHAR2(100 BYTE), 
	"VERIFICATION_CARD_SET_ID" VARCHAR2(100 BYTE), 
	"VERIFICATION_CARD_KEYSTORE" CLOB, 
	"SIGNED_VERIFICATION_PUBLIC_KEY" CLOB
   ) ;
--------------------------------------------------------
--  DDL for Table VERIFICATION_SET_DATA
--------------------------------------------------------

  CREATE TABLE "VERIFICATION_SET_DATA" 
   (	"ID" NUMBER(*,0), 
	"TENANT_ID" VARCHAR2(100 BYTE), 
	"ELECTION_EVENT_ID" VARCHAR2(100 BYTE), 
	"VERIFICATION_CARD_SET_ID" VARCHAR2(100 CHAR), 
	"JSON" CLOB
   ) ;
   
--------------------------------------------------------
--  DDL for Index CODES_MAPPING_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "CODES_MAPPING_UK1" ON "CODES_MAPPING" ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_ID") 
  ;
--------------------------------------------------------
--  DDL for Index VERIFICATION_CONTENT_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "VERIFICATION_CONTENT_UK1" ON "VERIFICATION_CONTENT" ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_SET_ID") 
  ;
--------------------------------------------------------
--  DDL for Index VV_ELECTORAL_AUTHORITY_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "VV_ELECTORAL_AUTHORITY_UK1" ON "VV_ELECTORAL_AUTHORITY" ("TENANT_ID", "ELECTION_EVENT_ID", "ELECTORAL_AUTHORITY_ID") 
  ;

--------------------------------------------------------
--  DDL for Index VERIFICATION_SET_DATA_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "VERIFICATION_SET_DATA_UK1" ON "VERIFICATION_SET_DATA" ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_SET_ID") 
  ;
  
--------------------------------------------------------
--  DDL for Index VERIFICATION_DATA_UK1
--------------------------------------------------------

  CREATE UNIQUE INDEX "VERIFICATION_DATA_UK1" ON "VERIFICATION_DATA" ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_ID")
  ;
  
--------------------------------------------------------
--  Constraints for Table VERIFICATION_CONTENT
--------------------------------------------------------

  ALTER TABLE "VERIFICATION_CONTENT" ADD CONSTRAINT "VERIFICATION_CONTENT_UK1" UNIQUE ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_SET_ID") ENABLE;
  ALTER TABLE "VERIFICATION_CONTENT" ADD PRIMARY KEY ("ID") ENABLE;
  ALTER TABLE "VERIFICATION_CONTENT" MODIFY ("JSON" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_CONTENT" MODIFY ("VERIFICATION_CARD_SET_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_CONTENT" MODIFY ("ELECTION_EVENT_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_CONTENT" MODIFY ("TENANT_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_CONTENT" MODIFY ("ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table VV_ELECTORAL_AUTHORITY
--------------------------------------------------------

  ALTER TABLE "VV_ELECTORAL_AUTHORITY" ADD CONSTRAINT "VV_ELECTORAL_AUTHORITY_UK1" UNIQUE ("TENANT_ID", "ELECTION_EVENT_ID", "ELECTORAL_AUTHORITY_ID") ENABLE;
  ALTER TABLE "VV_ELECTORAL_AUTHORITY" ADD PRIMARY KEY ("ID") ENABLE;
  ALTER TABLE "VV_ELECTORAL_AUTHORITY" MODIFY ("JSON" NOT NULL ENABLE);
  ALTER TABLE "VV_ELECTORAL_AUTHORITY" MODIFY ("ELECTORAL_AUTHORITY_ID" NOT NULL ENABLE);
  ALTER TABLE "VV_ELECTORAL_AUTHORITY" MODIFY ("ELECTION_EVENT_ID" NOT NULL ENABLE);
  ALTER TABLE "VV_ELECTORAL_AUTHORITY" MODIFY ("TENANT_ID" NOT NULL ENABLE);
  ALTER TABLE "VV_ELECTORAL_AUTHORITY" MODIFY ("ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table VERIFICATION_SET_DATA
--------------------------------------------------------

  ALTER TABLE "VERIFICATION_SET_DATA" ADD CONSTRAINT "VERIFICATION_SET_DATA_UK1" UNIQUE ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_SET_ID") ENABLE;
  ALTER TABLE "VERIFICATION_SET_DATA" ADD PRIMARY KEY ("ID") ENABLE;
  ALTER TABLE "VERIFICATION_SET_DATA" MODIFY ("JSON" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_SET_DATA" MODIFY ("VERIFICATION_CARD_SET_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_SET_DATA" MODIFY ("ELECTION_EVENT_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_SET_DATA" MODIFY ("TENANT_ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table VERIFICATION_DATA
--------------------------------------------------------

  
  ALTER TABLE "VERIFICATION_DATA" ADD CONSTRAINT "VERIFICATION_DATA_UK1" UNIQUE ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_ID") ENABLE;
  ALTER TABLE "VERIFICATION_DATA" ADD PRIMARY KEY ("ID") ENABLE;
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("SIGNED_VERIFICATION_PUBLIC_KEY" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("VERIFICATION_CARD_KEYSTORE" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("VERIFICATION_CARD_SET_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("VERIFICATION_CARD_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("ELECTION_EVENT_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("TENANT_ID" NOT NULL ENABLE);
  ALTER TABLE "VERIFICATION_DATA" MODIFY ("ID" NOT NULL ENABLE);
--------------------------------------------------------
--  Constraints for Table CODES_MAPPING
--------------------------------------------------------

  ALTER TABLE "CODES_MAPPING" ADD CONSTRAINT "CODES_MAPPING_UK1" UNIQUE ("TENANT_ID", "ELECTION_EVENT_ID", "VERIFICATION_CARD_ID") ENABLE;
  ALTER TABLE "CODES_MAPPING" ADD PRIMARY KEY ("ID") ENABLE;
  ALTER TABLE "CODES_MAPPING" MODIFY ("JSON" NOT NULL ENABLE);
  ALTER TABLE "CODES_MAPPING" MODIFY ("VERIFICATION_CARD_ID" NOT NULL ENABLE);
  ALTER TABLE "CODES_MAPPING" MODIFY ("ELECTION_EVENT_ID" NOT NULL ENABLE);
  ALTER TABLE "CODES_MAPPING" MODIFY ("TENANT_ID" NOT NULL ENABLE);
  ALTER TABLE "CODES_MAPPING" MODIFY ("ID" NOT NULL ENABLE);
  
  
  -- SIGNATURE
ALTER TABLE VERIFICATION_SET_DATA ADD ("SIGNATURE" CLOB);
--ALTER TABLE "VERIFICATION_SET_DATA" MODIFY ("SIGNATURE" NOT NULL ENABLE);
