-- Table: public.common_user

-- DROP TABLE IF EXISTS public.common_user;

CREATE TABLE IF NOT EXISTS public.common_user
(
    id serial NOT NULL,
    password character varying(128) NOT NULL,
    last_login timestamp with time zone,
    is_superuser boolean NOT NULL,
    username character varying(100),
    first_name character varying(150) NOT NULL,
    last_name character varying(150) NOT NULL,
    email character varying(255) NOT NULL,
    alternate_email character varying(255),
    is_active boolean NOT NULL,
    is_staff boolean NOT NULL,
    date_joined timestamp with time zone NOT NULL,
    profile_pic character varying(1000),
    "skype_ID" character varying(50) NOT NULL,
    description text,
    device_token character varying(500),
    device_type character varying(256),
    platform character varying(50),
    social_id character varying(50),
    CONSTRAINT common_user_pkey PRIMARY KEY (id),
    CONSTRAINT common_user_email_key UNIQUE (email)
);


-- Table: public.accounts_chatbotdomains

-- DROP TABLE IF EXISTS public.accounts_chatbotdomains;

CREATE TABLE IF NOT EXISTS public.accounts_chatbotdomains
(
    id serial NOT NULL,
    domain character varying(255) NOT NULL,
    domain_name character varying(255),
    is_active boolean NOT NULL,
    CONSTRAINT accounts_chatbotdomains_pkey PRIMARY KEY (id)
);

-- Index: common_user_email_10572c84_like

-- DROP INDEX IF EXISTS public.common_user_email_10572c84_like;

CREATE INDEX IF NOT EXISTS common_user_email_10572c84_like
    ON public.common_user USING btree
    (email varchar_pattern_ops ASC NULLS LAST);

-- Table: public.accounts_colortheme

-- DROP TABLE IF EXISTS public.accounts_colortheme;

CREATE TABLE IF NOT EXISTS public.accounts_colortheme
(
    id serial NOT NULL,
    bot_logo character varying(255),
    session_time integer,
    primary_text_color character varying(255),
    primary_background_color character varying(255),
    user_message_bg_color character varying(255),
    user_message_text_color character varying(255),
    bot_message_bg_color character varying(255),
    bot_message_text_color character varying(255),
    domain_id integer,
    chat_bot_pop_logo character varying(255),
    secondary_background_color character varying(255),
    secondary_text_color character varying(255),
    website_logo character varying(255),
    bot_name character varying(255),
    welcome_message character varying(500),
    api_key character varying(255),
    api_key_limit integer,
    api_key_used_count integer,
    CONSTRAINT accounts_colortheme_pkey PRIMARY KEY (id),
    CONSTRAINT accounts_colortheme_domain_id_fe1ed264_fk_accounts FOREIGN KEY (domain_id)
        REFERENCES public.accounts_chatbotdomains (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED
);

-- Index: accounts_colortheme_domain_id_fe1ed264

-- DROP INDEX IF EXISTS public.accounts_colortheme_domain_id_fe1ed264;

CREATE INDEX IF NOT EXISTS accounts_colortheme_domain_id_fe1ed264
    ON public.accounts_colortheme USING btree
    (domain_id ASC NULLS LAST);


-- Table: public.accounts_chatbotquestions

-- DROP TABLE IF EXISTS public.accounts_chatbotquestions;

CREATE TABLE IF NOT EXISTS public.accounts_chatbotquestions
(
    id serial NOT NULL,
    question character varying(500),
    answer character varying(2000),
    intent character varying(255),
    keyword character varying(255),
    product_module character varying(255),
    domain_id integer,
    CONSTRAINT accounts_chatbotquestions_pkey PRIMARY KEY (id),
    CONSTRAINT accounts_chatbotques_domain_id_1b21c00d_fk_accounts FOREIGN KEY (domain_id)
        REFERENCES public.accounts_chatbotdomains (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED
);

-- Index: accounts_chatbotquestions_domain_id_1b21c00d

-- DROP INDEX IF EXISTS public.accounts_chatbotquestions_domain_id_1b21c00d;

CREATE INDEX IF NOT EXISTS accounts_chatbotquestions_domain_id_1b21c00d
    ON public.accounts_chatbotquestions USING btree
    (domain_id ASC NULLS LAST);

-- Table: public.accounts_chatbotquestionassistants

-- DROP TABLE IF EXISTS public.accounts_chatbotquestionassistants;

CREATE TABLE IF NOT EXISTS public.accounts_chatbotquestionassistants
(
    id serial NOT NULL,
    assistant_id integer,
    question_id integer,
    CONSTRAINT accounts_chatbotquestionassistants_pkey PRIMARY KEY (id),
    CONSTRAINT accounts_chatbotques_assistant_id_f3e0e975_fk_common_user FOREIGN KEY (assistant_id)
        REFERENCES public.common_user (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED,
    CONSTRAINT accounts_chatbotques_question_id_df610186_fk_accounts FOREIGN KEY (question_id)
        REFERENCES public.accounts_chatbotquestions (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        DEFERRABLE INITIALLY DEFERRED
);

-- Index: accounts_chatbotquestionassistants_assistant_id_f3e0e975

-- DROP INDEX IF EXISTS public.accounts_chatbotquestionassistants_assistant_id_f3e0e975;

CREATE INDEX IF NOT EXISTS accounts_chatbotquestionassistants_assistant_id_f3e0e975
    ON public.accounts_chatbotquestionassistants USING btree
    (assistant_id ASC NULLS LAST);

-- Index: accounts_chatbotquestionassistants_question_id_26ca90c5

-- DROP INDEX IF EXISTS public.accounts_chatbotquestionassistants_question_id_26ca90c5;

CREATE INDEX IF NOT EXISTS accounts_chatbotquestionassistants_question_id_26ca90c5
    ON public.accounts_chatbotquestionassistants USING btree
    (question_id ASC NULLS LAST);

-- Table: public.events

-- DROP TABLE IF EXISTS public.events;

CREATE TABLE IF NOT EXISTS public.events
(
    id serial NOT NULL,
    sender_id character varying(255) NOT NULL,
    type_name character varying(255) NOT NULL,
    "timestamp" double precision,
    intent_name character varying(255),
    action_name character varying(255),
    data text,
    CONSTRAINT events_pkey PRIMARY KEY (id)
);

-- Index: ix_events_sender_id

-- DROP INDEX IF EXISTS public.ix_events_sender_id;

CREATE INDEX IF NOT EXISTS ix_events_sender_id
    ON public.events USING btree
    (sender_id ASC NULLS LAST);


-- Table: public.accounts_chatbotpermissionmaster

-- DROP TABLE IF EXISTS public.accounts_chatbotpermissionmaster;

CREATE TABLE IF NOT EXISTS public.accounts_chatbotpermissionmaster
(
    id serial NOT NULL,
    name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    description character varying(500) COLLATE pg_catalog."default",
    category character varying(255) COLLATE pg_catalog."default",
    created_at timestamp with time zone NOT NULL DEFAULT NOW(),
    CONSTRAINT accounts_chatbotpermissionmaster_pkey PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS public.accounts_chatbotpermission
(
    id serial NOT NULL,
    created_at timestamp with time zone NOT NULL DEFAULT NOW(),
    domain_id integer,
    permission_id integer,
    CONSTRAINT accounts_chatbotpermission_pkey PRIMARY KEY (id),
    CONSTRAINT accounts_chatbotperm_domain_id_a9472904_fk_accounts_ FOREIGN KEY (domain_id)
        REFERENCES public.accounts_chatbotdomains (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT accounts_chatbotperm_permission_id_44d6cee1_fk_accounts_ FOREIGN KEY (permission_id)
        REFERENCES public.accounts_chatbotpermissionmaster (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
);
