

CREATE EXTENSION if not EXISTS "uuid-ossp"
	SCHEMA "public"
	VERSION "1.1";


-- DROP SCHEMA public;

CREATE SCHEMA IF NOT EXISTS public AUTHORIZATION pg_database_owner;

-- DROP SEQUENCE "LawyerVideoConferenceParticip_LawyerVideoConferenceParticip_seq";

CREATE SEQUENCE "LawyerVideoConferenceParticip_LawyerVideoConferenceParticip_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "LawyerVideoConferenceSchedule_LawyerVideoConferenceSchedule_seq";

CREATE SEQUENCE "LawyerVideoConferenceSchedule_LawyerVideoConferenceSchedule_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "LookupDataValues_LookupDataValueID_seq";

CREATE SEQUENCE "LookupDataValues_LookupDataValueID_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "LookupData_LookupDataID_seq";

CREATE SEQUENCE "LookupData_LookupDataID_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "TransactionDeclineReasons_TransactionDeclineReasonID_seq";

CREATE SEQUENCE "TransactionDeclineReasons_TransactionDeclineReasonID_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "TransactionSelfies_TransactionSelfieID_seq";

CREATE SEQUENCE "TransactionSelfies_TransactionSelfieID_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "TransactionSignatoryDeclineRe_TransactionSignatoryDeclineRe_seq";

CREATE SEQUENCE "TransactionSignatoryDeclineRe_TransactionSignatoryDeclineRe_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE "VideoRecordings_VideoRecordingID_seq";

CREATE SEQUENCE "VideoRecordings_VideoRecordingID_seq"
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE errorlogs_errorlogid_seq;

CREATE SEQUENCE errorlogs_errorlogid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE eventlogs_eventlogid_seq;

CREATE SEQUENCE eventlogs_eventlogid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE identificationdocuments_identificationdocumentid_seq;

CREATE SEQUENCE identificationdocuments_identificationdocumentid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE lawyers_lawyerid_seq;

CREATE SEQUENCE lawyers_lawyerid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE templates_templateid_seq;

CREATE SEQUENCE templates_templateid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 2147483647
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE transactiondocuments_transactiondocumentid_seq;

CREATE SEQUENCE transactiondocuments_transactiondocumentid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE transactionnotary_transactionnotaryid_seq;

CREATE SEQUENCE transactionnotary_transactionnotaryid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE transactionotp_transactionotpid_seq;

CREATE SEQUENCE transactionotp_transactionotpid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE transactions_transactionid_seq;

CREATE SEQUENCE transactions_transactionid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE transactionsignatories_transactionsignatoryid_seq;

CREATE SEQUENCE transactionsignatories_transactionsignatoryid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;
-- DROP SEQUENCE users_userid_seq;

CREATE SEQUENCE users_userid_seq
	INCREMENT BY 1
	MINVALUE 1
	MAXVALUE 9223372036854775807
	START 1
	CACHE 1
	NO CYCLE;-- public."ErrorLogs" definition

-- Drop table

-- DROP TABLE "ErrorLogs";

CREATE TABLE "ErrorLogs" (
	"ErrorLogID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"Message" varchar NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"Severity" varchar NULL,
	"Exception" varchar NULL,
	"Stacktrace" varchar NULL,
	"ErrorLog_UID" uuid DEFAULT uuid_generate_v4() NULL,
	CONSTRAINT errorlogs_pk PRIMARY KEY ("ErrorLogID")
);
CREATE INDEX "ErrorLogs_CreatedOn_IDX" ON public."ErrorLogs" USING btree ("CreatedOn" DESC);
CREATE UNIQUE INDEX "ErrorLogs_ErrorLog_UID_IDX" ON public."ErrorLogs" USING btree ("ErrorLog_UID");


-- public."LookupData" definition

-- Drop table

-- DROP TABLE "LookupData";

CREATE TABLE "LookupData" (
	"LookupDataID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"LookupData_UID" uuid DEFAULT uuid_generate_v4() NOT NULL,
	"Category" varchar NULL,
	"ParentCategory" varchar NULL,
	"Name" varchar NOT NULL,
	"Description" varchar NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	CONSTRAINT "LookupData_pk" PRIMARY KEY ("LookupDataID"),
	CONSTRAINT "LookupData_unique" UNIQUE ("LookupData_UID")
);
CREATE UNIQUE INDEX "LookupData_Name_Category_IDX" ON public."LookupData" USING btree ("Name", "Category");


-- public."Templates" definition

-- Drop table

-- DROP TABLE "Templates";

CREATE TABLE "Templates" (
	"TemplateID" int4 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"Name" varchar NOT NULL,
	"Description" varchar NULL,
	"Pagecount" int4 NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"TemplateUrl" varchar NULL,
	"Template_UID" uuid DEFAULT uuid_generate_v4() NULL,
	CONSTRAINT templates_pk PRIMARY KEY ("TemplateID")
);


-- public."Users" definition

-- Drop table

-- DROP TABLE "Users";

CREATE TABLE "Users" (
	"UserID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"Email" varchar NOT NULL,
	"PasswordHash" varchar NOT NULL,
	"PhoneNumber" varchar NULL,
	"Firstname" varchar NULL,
	"Lastname" varchar NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"User_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"Role" varchar DEFAULT 'user'::character varying NULL,
	"BirthDate" date NOT NULL,
	"Middlename" varchar NULL,
	"Suffix" varchar NULL,
	"Prefix" varchar NULL,
	CONSTRAINT users_pk PRIMARY KEY ("UserID"),
	CONSTRAINT users_unique_email UNIQUE ("Email"),
	CONSTRAINT users_unique_uid UNIQUE ("User_UID")
);


-- public."EventLogs" definition

-- Drop table

-- DROP TABLE "EventLogs";

CREATE TABLE "EventLogs" (
	"EventLogID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"StreamID" int8 NOT NULL,
	"LogType" varchar NOT NULL,
	"LogDate" time DEFAULT now() NULL,
	"UserID" int8 NULL,
	"Payload" varchar NOT NULL,
	"Description" varchar NULL,
	"EventLog_UID" uuid DEFAULT uuid_generate_v4() NULL,
	CONSTRAINT eventlogs_pk PRIMARY KEY ("EventLogID"),
	CONSTRAINT eventlogs_users_fk FOREIGN KEY ("UserID") REFERENCES "Users"("UserID")
);
CREATE UNIQUE INDEX "EventLogs_EventLog_UID_IDX" ON public."EventLogs" USING btree ("EventLog_UID");
CREATE INDEX "EventLogs_LogDate_IDX" ON public."EventLogs" USING btree ("LogDate" DESC);
CREATE INDEX "EventLogs_StreamID_IDX" ON public."EventLogs" USING btree ("StreamID");
CREATE INDEX "EventLogs_UserID_IDX" ON public."EventLogs" USING btree ("UserID");


-- public."IdentificationDocuments" definition

-- Drop table

-- DROP TABLE "IdentificationDocuments";

CREATE TABLE "IdentificationDocuments" (
	"IdentificationDocumentID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"Type" varchar NOT NULL,
	"ExpirationDate" date NOT NULL,
	"Filename" varchar NOT NULL,
	"File" bytea NOT NULL,
	"UserID" int8 NOT NULL,
	"IdNumber" varchar NOT NULL,
	"PlaceIssued" varchar NOT NULL,
	"DateIssued" date NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NOT NULL,
	"IdentificationDocument_UID" uuid DEFAULT uuid_generate_v4() NOT NULL,
	"IsDeleted" bool NULL,
	"UploadedOn" timestamp NOT NULL,
	CONSTRAINT identificationdocuments_pk PRIMARY KEY ("IdentificationDocumentID"),
	CONSTRAINT identificationdocuments_users_fk FOREIGN KEY ("UserID") REFERENCES "Users"("UserID")
);
CREATE UNIQUE INDEX "IdentificationDocuments_IdentificationDocument_UID_IDX" ON public."IdentificationDocuments" USING btree ("IdentificationDocument_UID");


-- public."Lawyers" definition

-- Drop table

-- DROP TABLE "Lawyers";

CREATE TABLE "Lawyers" (
	"LawyerID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"Rollnumber" varchar NULL,
	"IBPNumber" varchar NULL,
	"MCLEComplianceNumber" varchar NULL,
	"MCLEDate" date NULL,
	"PTRNumber" varchar NULL,
	"PTRDate" date NULL,
	"PTRlocation" varchar NULL,
	"OfficeAddress" varchar NULL,
	"UserID" int8 NOT NULL,
	"Lawyer_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"CommissionNumber" varchar NULL,
	"CommissionLocation" varchar NULL,
	"CommissionExpiration" date NULL,
	"Status" varchar DEFAULT 'Registered'::character varying NULL,
	CONSTRAINT lawyers_pk PRIMARY KEY ("LawyerID"),
	CONSTRAINT lawyers_users_fk FOREIGN KEY ("UserID") REFERENCES "Users"("UserID")
);


-- public."LookupDataValues" definition

-- Drop table

-- DROP TABLE "LookupDataValues";

CREATE TABLE "LookupDataValues" (
	"LookupDataValueID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"LookupDataValue_UID" uuid DEFAULT uuid_generate_v4() NOT NULL,
	"LookupDataID" int8 NULL,
	"Value" varchar NOT NULL,
	"Title" varchar NULL,
	"SortOrder" int4 NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	CONSTRAINT "LookupDataValues_pk" PRIMARY KEY ("LookupDataValueID"),
	CONSTRAINT "LookupDataValues_unique" UNIQUE ("LookupDataValue_UID"),
	CONSTRAINT "LookupDataValues_LookupData_FK" FOREIGN KEY ("LookupDataID") REFERENCES "LookupData"("LookupDataID")
);


-- public."Transactions" definition

-- Drop table

-- DROP TABLE "Transactions";

CREATE TABLE "Transactions" (
	"TransactionID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionDate" date NOT NULL,
	"PrincipalID" int8 NOT NULL,
	"Status" varchar NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"Transaction_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"PreferredLawyerID" int8 NULL,
	"LawyerID" int8 NULL,
	"IsRecorded" bool NULL,
	CONSTRAINT transactions_pk PRIMARY KEY ("TransactionID"),
	CONSTRAINT "Transactions_Lawyers_FK" FOREIGN KEY ("LawyerID") REFERENCES "Lawyers"("LawyerID"),
	CONSTRAINT "Transactions_PreferredLawyers_FK" FOREIGN KEY ("PreferredLawyerID") REFERENCES "Lawyers"("LawyerID"),
	CONSTRAINT "Transactions_Users_FK" FOREIGN KEY ("PrincipalID") REFERENCES "Users"("UserID")
);
CREATE INDEX "Transactions_TransactionDate_IDX" ON public."Transactions" USING btree ("TransactionDate" DESC);
CREATE UNIQUE INDEX "Transactions_Transaction_UID_IDX" ON public."Transactions" USING btree ("Transaction_UID");


-- public."LawyerVideoConferenceSchedule" definition

-- Drop table

-- DROP TABLE "LawyerVideoConferenceSchedule";

CREATE TABLE "LawyerVideoConferenceSchedule" (
	"LawyerVideoConferenceScheduleID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"LawyerID" int8 NOT NULL,
	"TransactionID" int8 NOT NULL,
	"MeetingDate" timestamp NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"LawyerVideoConferenceSchedule_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"Status" varchar NULL,
	"MeetingRoomID" varchar NULL,
	"MeetingRoomTokenID" varchar NULL,
	"MeetingRoomUserID" varchar NULL,
	"ServerCallID" varchar NULL,
	"RecordingID" varchar NULL,
	CONSTRAINT "LawyerVideoConferenceSchedule_pk" PRIMARY KEY ("LawyerVideoConferenceScheduleID"),
	CONSTRAINT "LawyerVideoConferenceSchedule_unique" UNIQUE ("LawyerVideoConferenceSchedule_UID"),
	CONSTRAINT "LawyerVideoConferenceSchedule_Lawyers_FK" FOREIGN KEY ("LawyerID") REFERENCES "Lawyers"("LawyerID"),
	CONSTRAINT "LawyerVideoConferenceSchedule_Transactions_FK" FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID")
);
CREATE INDEX "LawyerVideoConferenceSchedule_RecordingID_IDX" ON public."LawyerVideoConferenceSchedule" USING btree ("RecordingID");
CREATE INDEX "LawyerVideoConferenceSchedule_TransactionID_IDX" ON public."LawyerVideoConferenceSchedule" USING btree ("TransactionID");


-- public."TransactionDeclineReasons" definition

-- Drop table

-- DROP TABLE "TransactionDeclineReasons";

CREATE TABLE "TransactionDeclineReasons" (
	"TransactionDeclineReasonID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionID" int8 NOT NULL,
	"Reason" varchar NOT NULL,
	"LawyerID" int8 NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"TransactionDeclineReason_UID" uuid DEFAULT uuid_generate_v4() NULL,
	CONSTRAINT "TransactionDeclineReasons_pk" PRIMARY KEY ("TransactionDeclineReasonID"),
	CONSTRAINT "TransactionDeclineReasons_Lawyers_FK" FOREIGN KEY ("LawyerID") REFERENCES "Lawyers"("LawyerID"),
	CONSTRAINT "TransactionDeclineReasons_Transactions_FK" FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID")
);
CREATE UNIQUE INDEX "TransactionDeclineReasons_TransactionDeclineReason_UID_IDX" ON public."TransactionDeclineReasons" USING btree ("TransactionDeclineReason_UID");


-- public."TransactionDocuments" definition

-- Drop table

-- DROP TABLE "TransactionDocuments";

CREATE TABLE "TransactionDocuments" (
	"TransactionDocumentID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionID" int8 NOT NULL,
	"Filename" varchar NOT NULL,
	"Notes" varchar NULL,
	"File" bytea NOT NULL,
	"UploadedOn" timestamp NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"TransactionDocument_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"DocumentType" varchar NOT NULL,
	CONSTRAINT transactiondocuments_pk PRIMARY KEY ("TransactionDocumentID"),
	CONSTRAINT transactiondocuments_transactions_fk FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID")
);


-- public."TransactionNotary" definition

-- Drop table

-- DROP TABLE "TransactionNotary";

CREATE TABLE "TransactionNotary" (
	"TransactionNotaryID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionID" int8 NOT NULL,
	"DocNumber" varchar NULL,
	"BookNumber" varchar NULL,
	"PageNumber" varchar NULL,
	"Series" varchar NULL,
	"SignedOn" date NULL,
	"Remarks" varchar NULL,
	"LawyerID" int8 NOT NULL,
	"CertificateType" varchar NULL,
	"TemplateID" int4 NULL,
	"PageCount" int4 NULL,
	"TransactionNotary_UID" uuid DEFAULT uuid_generate_v4() NULL,
	CONSTRAINT transactionnotary_pk PRIMARY KEY ("TransactionNotaryID"),
	CONSTRAINT transactionnotary_lawyers_fk FOREIGN KEY ("LawyerID") REFERENCES "Lawyers"("LawyerID"),
	CONSTRAINT transactionnotary_templates_fk FOREIGN KEY ("TemplateID") REFERENCES "Templates"("TemplateID"),
	CONSTRAINT transactionnotary_transactions_fk FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID")
);


-- public."TransactionOTP" definition

-- Drop table

-- DROP TABLE "TransactionOTP";

CREATE TABLE "TransactionOTP" (
	"TransactionOTPID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionID" int8 NOT NULL,
	"VerifiedOn" time NOT NULL,
	"PrintCoords" varchar NOT NULL,
	"Status" varchar NOT NULL,
	"UserID" int8 NOT NULL,
	"TransactionOTP_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"OTPHash" varchar NOT NULL,
	"OTPUserInput" varchar NULL,
	"IPAddress" varchar NULL,
	"Longitude" numeric NULL,
	"Lattitude" numeric NULL,
	"Device" varchar NULL,
	"File_Liveness" bytea NULL,
	CONSTRAINT transactionotp_pk PRIMARY KEY ("TransactionOTPID"),
	CONSTRAINT "TransactionOTP_Users_FK" FOREIGN KEY ("UserID") REFERENCES "Users"("UserID"),
	CONSTRAINT transactionotp_transactions_fk FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID")
);
CREATE INDEX "TransactionOTP_TransactionID_IDX" ON public."TransactionOTP" USING btree ("TransactionID");
CREATE UNIQUE INDEX "TransactionOTP_TransactionOTP_UID_IDX" ON public."TransactionOTP" USING btree ("TransactionOTP_UID");


-- public."TransactionSelfies" definition

-- Drop table

-- DROP TABLE "TransactionSelfies";

CREATE TABLE "TransactionSelfies" (
	"TransactionSelfieID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionID" int8 NULL,
	"IdentificationDocumentID" int8 NULL,
	"File" bytea NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"TransactionSelfie_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"UserID" int8 NOT NULL,
	CONSTRAINT "TransactionSelfies_pk" PRIMARY KEY ("TransactionSelfieID"),
	CONSTRAINT "TransactionSelfies_IdentificationDocuments_FK" FOREIGN KEY ("IdentificationDocumentID") REFERENCES "IdentificationDocuments"("IdentificationDocumentID"),
	CONSTRAINT "TransactionSelfies_Transactions_FK" FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID"),
	CONSTRAINT "TransactionSelfies_Users_FK" FOREIGN KEY ("UserID") REFERENCES "Users"("UserID")
);
CREATE UNIQUE INDEX "TransactionSelfies_TransactionSelfie_UID_IDX" ON public."TransactionSelfies" USING btree ("TransactionSelfie_UID");


-- public."TransactionSignatories" definition

-- Drop table

-- DROP TABLE "TransactionSignatories";

CREATE TABLE "TransactionSignatories" (
	"TransactionSignatoryID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"TransactionID" int8 NOT NULL,
	"UserID" int8 NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"Status" varchar NOT NULL,
	"Email" varchar NOT NULL,
	"Type" varchar NOT NULL,
	"TransactionSignatory_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"InvitationCode" varchar NOT NULL,
	CONSTRAINT transactionsignatories_pk PRIMARY KEY ("TransactionSignatoryID"),
	CONSTRAINT transactionsignatories_transactions_fk FOREIGN KEY ("TransactionID") REFERENCES "Transactions"("TransactionID"),
	CONSTRAINT transactionsignatories_users_fk FOREIGN KEY ("UserID") REFERENCES "Users"("UserID")
);
CREATE INDEX "TransactionSignatories_InvitationCode_IDX" ON public."TransactionSignatories" USING btree ("InvitationCode");
CREATE INDEX "TransactionSignatories_TransactionID_IDX" ON public."TransactionSignatories" USING btree ("TransactionID", "Email");
CREATE UNIQUE INDEX "TransactionSignatories_TransactionSignatory_UID_IDX" ON public."TransactionSignatories" USING btree ("TransactionSignatory_UID");


-- public."TransactionSignatoryDeclineReasons" definition

-- Drop table

-- DROP TABLE "TransactionSignatoryDeclineReasons";

CREATE TABLE "TransactionSignatoryDeclineReasons" (
	"TransactionSignatoryDeclineReasonID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"UserID" int8 NOT NULL,
	"DeclineReason" varchar NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"TransactionSignatoryDeclineReason_UID" uuid DEFAULT uuid_generate_v4() NOT NULL,
	"TransactionID" int8 NOT NULL,
	"TransactionSignatoryID" int8 NULL,
	CONSTRAINT "TransactionSignatoryDeclineReasons_pk" PRIMARY KEY ("TransactionSignatoryDeclineReasonID"),
	CONSTRAINT "TransactionSignatoryDeclineReasons_unique" UNIQUE ("TransactionSignatoryDeclineReason_UID"),
	CONSTRAINT "TransactionSignatoryDeclineReasons_TransactionSignatories_FK" FOREIGN KEY ("TransactionSignatoryID") REFERENCES "TransactionSignatories"("TransactionSignatoryID"),
	CONSTRAINT "TransactionSignatoryDeclineReasons_Users_FK" FOREIGN KEY ("UserID") REFERENCES "Users"("UserID")
);
CREATE INDEX "TransactionSignatoryDeclineReasons_UserID_IDX" ON public."TransactionSignatoryDeclineReasons" USING btree ("UserID", "TransactionID");


-- public."VideoRecordings" definition

-- Drop table

-- DROP TABLE "VideoRecordings";

CREATE TABLE "VideoRecordings" (
	"VideoRecordingID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"VideoConferenceScheduleID" int8 NOT NULL,
	"Path" varchar NOT NULL,
	"LocationType" varchar NOT NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"VideoRecording_UID" uuid DEFAULT uuid_generate_v4() NULL,
	CONSTRAINT "VideoRecordings_pk" PRIMARY KEY ("VideoRecordingID"),
	CONSTRAINT "VideoRecordings_unique" UNIQUE ("VideoConferenceScheduleID"),
	CONSTRAINT "VideoRecordings_unique_UID" UNIQUE ("VideoRecording_UID"),
	CONSTRAINT "VideoRecordings_LawyerVideoConferenceSchedule_FK" FOREIGN KEY ("VideoConferenceScheduleID") REFERENCES "LawyerVideoConferenceSchedule"("LawyerVideoConferenceScheduleID")
);


-- public."LawyerVideoConferenceParticipants" definition

-- Drop table

-- DROP TABLE "LawyerVideoConferenceParticipants";

CREATE TABLE "LawyerVideoConferenceParticipants" (
	"LawyerVideoConferenceParticipantID" int8 GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
	"LawyerVideoConferenceScheduleID" int8 NOT NULL,
	"ParticipantID" int8 NOT NULL,
	"Status" varchar NULL,
	"CreatedOn" timestamp DEFAULT now() NULL,
	"LawyerVideoConferenceParticipant_UID" uuid DEFAULT uuid_generate_v4() NULL,
	"MeetingRoomTokenID" varchar NULL,
	"MeetingRoomUserID" varchar NULL,
	CONSTRAINT "LawyerVideoConferenceParticipants_pk" PRIMARY KEY ("LawyerVideoConferenceParticipantID"),
	CONSTRAINT "LawyerVideoConferenceParticipants_LawyerVideoConferenceSchedule" FOREIGN KEY ("LawyerVideoConferenceScheduleID") REFERENCES "LawyerVideoConferenceSchedule"("LawyerVideoConferenceScheduleID"),
	CONSTRAINT "LawyerVideoConferenceParticipants_Users_FK" FOREIGN KEY ("ParticipantID") REFERENCES "Users"("UserID")
);
CREATE UNIQUE INDEX "LawyerVideoConferenceParticipants_LawyerVideoConferenceParticip" ON public."LawyerVideoConferenceParticipants" USING btree ("LawyerVideoConferenceParticipant_UID");
CREATE UNIQUE INDEX "LawyerVideoConferenceParticipants_LawyerVideoConferenceSchedule" ON public."LawyerVideoConferenceParticipants" USING btree ("LawyerVideoConferenceScheduleID", "ParticipantID");



-- DROP FUNCTION public.uuid_generate_v1();

CREATE OR REPLACE FUNCTION public.uuid_generate_v1()
 RETURNS uuid
 LANGUAGE c
 PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_generate_v1$function$
;

-- DROP FUNCTION public.uuid_generate_v1mc();

CREATE OR REPLACE FUNCTION public.uuid_generate_v1mc()
 RETURNS uuid
 LANGUAGE c
 PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_generate_v1mc$function$
;

-- DROP FUNCTION public.uuid_generate_v3(uuid, text);

CREATE OR REPLACE FUNCTION public.uuid_generate_v3(namespace uuid, name text)
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_generate_v3$function$
;

-- DROP FUNCTION public.uuid_generate_v4();

CREATE OR REPLACE FUNCTION public.uuid_generate_v4()
 RETURNS uuid
 LANGUAGE c
 PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_generate_v4$function$
;

-- DROP FUNCTION public.uuid_generate_v5(uuid, text);

CREATE OR REPLACE FUNCTION public.uuid_generate_v5(namespace uuid, name text)
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_generate_v5$function$
;

-- DROP FUNCTION public.uuid_nil();

CREATE OR REPLACE FUNCTION public.uuid_nil()
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_nil$function$
;

-- DROP FUNCTION public.uuid_ns_dns();

CREATE OR REPLACE FUNCTION public.uuid_ns_dns()
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_ns_dns$function$
;

-- DROP FUNCTION public.uuid_ns_oid();

CREATE OR REPLACE FUNCTION public.uuid_ns_oid()
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_ns_oid$function$
;

-- DROP FUNCTION public.uuid_ns_url();

CREATE OR REPLACE FUNCTION public.uuid_ns_url()
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_ns_url$function$
;

-- DROP FUNCTION public.uuid_ns_x500();

CREATE OR REPLACE FUNCTION public.uuid_ns_x500()
 RETURNS uuid
 LANGUAGE c
 IMMUTABLE PARALLEL SAFE STRICT
AS '$libdir/uuid-ossp', $function$uuid_ns_x500$function$
;
