· 6 years ago · Oct 27, 2019, 03:42 AM
1--
2-- PostgreSQL database dump
3--
4
5-- Dumped from database version 9.6.10
6-- Dumped by pg_dump version 9.6.10
7
8SET statement_timeout = 0;
9SET lock_timeout = 0;
10SET idle_in_transaction_session_timeout = 0;
11SET client_encoding = 'UTF8';
12SET standard_conforming_strings = on;
13SELECT pg_catalog.set_config('search_path', '', false);
14SET check_function_bodies = false;
15SET client_min_messages = warning;
16SET row_security = off;
17
18--
19-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
20--
21
22CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
23
24
25--
26-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
27--
28
29COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
30
31
32--
33-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner:
34--
35
36CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
37
38
39--
40-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner:
41--
42
43COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';
44
45
46--
47-- Name: msd_income(integer); Type: FUNCTION; Schema: public; Owner: postgres
48--
49
50CREATE FUNCTION public.msd_income(service_id_to_check integer) RETURNS TABLE(income bigint, income_date date)
51 LANGUAGE plpgsql
52 AS $$
53BEGIN
54 RETURN QUERY
55
56
57SELECT sum(cr.charge_amount) AS sum,
58 timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on))::date AS d
59 FROM charges cr
60 JOIN contacts c ON c.id = cr.contact_id
61 WHERE cr.service_id = service_id_to_check
62 GROUP BY (timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on))::date)
63 ORDER BY (timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on))::date);
64
65
66END; $$;
67
68
69ALTER FUNCTION public.msd_income(service_id_to_check integer) OWNER TO postgres;
70
71--
72-- Name: msd_unsubs(integer); Type: FUNCTION; Schema: public; Owner: postgres
73--
74
75CREATE FUNCTION public.msd_unsubs(service_id_to_check integer) RETURNS TABLE(count bigint, deactivated_on date)
76 LANGUAGE plpgsql
77 AS $$
78BEGIN
79 RETURN QUERY
80 select count(distinct t.national_number), t.deactivated_on from (
81select c.national_number, utc2ir_dt(s.activated_on)::date as activated_on, utc2ir_dt(s.deactivated_on)::date as deactivated_on
82from subscriptions s inner join contacts c on s.contact_id = c.id
83where s.service_id= service_id_to_check
84) as t group by t.deactivated_on;
85
86END; $$;
87
88
89ALTER FUNCTION public.msd_unsubs(service_id_to_check integer) OWNER TO postgres;
90
91--
92-- Name: utc2ir_dt(timestamp without time zone); Type: FUNCTION; Schema: public; Owner: postgres
93--
94
95CREATE FUNCTION public.utc2ir_dt(i timestamp without time zone) RETURNS timestamp without time zone
96 LANGUAGE plpgsql IMMUTABLE
97 AS $$
98
99BEGIN
100 RETURN timezone('asia/tehran'::text, timezone('utc'::text, i));
101END;
102$$;
103
104
105ALTER FUNCTION public.utc2ir_dt(i timestamp without time zone) OWNER TO postgres;
106
107SET default_tablespace = '';
108
109SET default_with_oids = false;
110
111--
112-- Name: apikeys; Type: TABLE; Schema: public; Owner: postgres
113--
114
115CREATE TABLE public.apikeys (
116 id integer NOT NULL,
117 name character varying(255),
118 uuid uuid DEFAULT public.uuid_generate_v4(),
119 key uuid DEFAULT public.uuid_generate_v4(),
120 expiration_date timestamp without time zone,
121 start_date timestamp without time zone DEFAULT now(),
122 app_id integer,
123 inserted_at timestamp without time zone NOT NULL,
124 updated_at timestamp without time zone NOT NULL,
125 can_charge boolean DEFAULT true,
126 can_push_otp boolean DEFAULT true,
127 can_message boolean DEFAULT true,
128 can_push_notif boolean DEFAULT true,
129 charge_tpm integer DEFAULT 600,
130 message_tpm integer DEFAULT 600,
131 push_notif_tpm integer DEFAULT 2400,
132 push_otp_tpm integer DEFAULT 600
133);
134
135
136ALTER TABLE public.apikeys OWNER TO postgres;
137
138--
139-- Name: apikeys_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
140--
141
142CREATE SEQUENCE public.apikeys_id_seq
143 START WITH 1
144 INCREMENT BY 1
145 NO MINVALUE
146 NO MAXVALUE
147 CACHE 1;
148
149
150ALTER TABLE public.apikeys_id_seq OWNER TO postgres;
151
152--
153-- Name: apikeys_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
154--
155
156ALTER SEQUENCE public.apikeys_id_seq OWNED BY public.apikeys.id;
157
158
159--
160-- Name: apps; Type: TABLE; Schema: public; Owner: postgres
161--
162
163CREATE TABLE public.apps (
164 id integer NOT NULL,
165 name character varying(64) NOT NULL,
166 mo_url character varying(256) NOT NULL,
167 uuid uuid DEFAULT public.uuid_generate_v4(),
168 expiration_date timestamp without time zone,
169 start_date timestamp without time zone,
170 description text,
171 user_id integer NOT NULL,
172 service_id integer NOT NULL,
173 inserted_at timestamp without time zone NOT NULL,
174 updated_at timestamp without time zone NOT NULL,
175 is_active boolean DEFAULT true
176);
177
178
179ALTER TABLE public.apps OWNER TO postgres;
180
181--
182-- Name: apps_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
183--
184
185CREATE SEQUENCE public.apps_id_seq
186 START WITH 1
187 INCREMENT BY 1
188 NO MINVALUE
189 NO MAXVALUE
190 CACHE 1;
191
192
193ALTER TABLE public.apps_id_seq OWNER TO postgres;
194
195--
196-- Name: apps_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
197--
198
199ALTER SEQUENCE public.apps_id_seq OWNED BY public.apps.id;
200
201
202--
203-- Name: bulks; Type: TABLE; Schema: public; Owner: postgres
204--
205
206CREATE TABLE public.bulks (
207 id integer NOT NULL,
208 uuid uuid DEFAULT public.uuid_generate_v4(),
209 is_active boolean DEFAULT false NOT NULL,
210 bulk_count integer NOT NULL,
211 name character varying(128),
212 include_states jsonb,
213 exclude_states jsonb,
214 include_cities jsonb,
215 exclude_cities jsonb,
216 exclude_numbers jsonb,
217 include_numbers jsonb,
218 prepaid boolean DEFAULT false NOT NULL,
219 start_on timestamp without time zone NOT NULL,
220 end_on timestamp without time zone NOT NULL,
221 include_unsubs boolean DEFAULT false NOT NULL,
222 include_subs boolean DEFAULT false NOT NULL,
223 slack_id character varying(128),
224 slack_mmesgae character varying(256),
225 service_id integer NOT NULL,
226 expected_reaction_id integer NOT NULL,
227 inserted_at timestamp without time zone NOT NULL,
228 updated_at timestamp without time zone NOT NULL
229);
230
231
232ALTER TABLE public.bulks OWNER TO postgres;
233
234--
235-- Name: bulks_contacts; Type: TABLE; Schema: public; Owner: postgres
236--
237
238CREATE TABLE public.bulks_contacts (
239 contact_id integer,
240 bulk_id integer
241);
242
243
244ALTER TABLE public.bulks_contacts OWNER TO postgres;
245
246--
247-- Name: bulks_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
248--
249
250CREATE SEQUENCE public.bulks_id_seq
251 START WITH 1
252 INCREMENT BY 1
253 NO MINVALUE
254 NO MAXVALUE
255 CACHE 1;
256
257
258ALTER TABLE public.bulks_id_seq OWNER TO postgres;
259
260--
261-- Name: bulks_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
262--
263
264ALTER SEQUENCE public.bulks_id_seq OWNED BY public.bulks.id;
265
266
267--
268-- Name: campaigns; Type: TABLE; Schema: public; Owner: postgres
269--
270
271CREATE TABLE public.campaigns (
272 id integer NOT NULL,
273 uuid uuid DEFAULT public.uuid_generate_v4(),
274 is_active boolean DEFAULT false NOT NULL,
275 total_messages integer,
276 sent_messages integer,
277 delivered_messages integer,
278 name character varying(255),
279 send_on timestamp without time zone DEFAULT now(),
280 end_on timestamp without time zone,
281 app_id integer,
282 service_id integer,
283 inserted_at timestamp without time zone NOT NULL,
284 updated_at timestamp without time zone NOT NULL
285);
286
287
288ALTER TABLE public.campaigns OWNER TO postgres;
289
290--
291-- Name: campaigns_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
292--
293
294CREATE SEQUENCE public.campaigns_id_seq
295 START WITH 1
296 INCREMENT BY 1
297 NO MINVALUE
298 NO MAXVALUE
299 CACHE 1;
300
301
302ALTER TABLE public.campaigns_id_seq OWNER TO postgres;
303
304--
305-- Name: campaigns_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
306--
307
308ALTER SEQUENCE public.campaigns_id_seq OWNED BY public.campaigns.id;
309
310
311--
312-- Name: charges; Type: TABLE; Schema: public; Owner: postgres
313--
314
315CREATE TABLE public.charges (
316 id integer NOT NULL,
317 uuid uuid DEFAULT public.uuid_generate_v4(),
318 charge_amount integer,
319 transactioncode character varying(255),
320 charge_status character varying(64),
321 correlator character varying(64),
322 charge_code character varying(64),
323 ticket_id character varying(64),
324 webhook character varying(256),
325 webhook_response jsonb,
326 appliedprice integer,
327 retry_counter integer DEFAULT 0,
328 retry integer DEFAULT 0,
329 delay_retries integer DEFAULT 8,
330 send_on timestamp without time zone DEFAULT now(),
331 end_on timestamp without time zone,
332 cron character varying(64),
333 charge_request_datetime timestamp without time zone,
334 charge_response_datetime timestamp without time zone,
335 reason_for_charge character varying(256),
336 charge_method character varying(64),
337 responsecode integer,
338 raw_response text,
339 response jsonb,
340 is_active boolean DEFAULT true NOT NULL,
341 is_refunded boolean DEFAULT false NOT NULL,
342 service_id integer,
343 contact_id integer,
344 app_id integer,
345 inserted_at timestamp without time zone NOT NULL,
346 updated_at timestamp without time zone NOT NULL,
347 trackid character varying(64),
348 auto_charge boolean DEFAULT false,
349 auto_renewal boolean DEFAULT false,
350 auto_subscribe boolean DEFAULT false,
351 send_lock boolean,
352 section character varying(128),
353 is_strict boolean DEFAULT false,
354 if_cond jsonb
355);
356
357
358ALTER TABLE public.charges OWNER TO postgres;
359
360--
361-- Name: charges_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
362--
363
364CREATE SEQUENCE public.charges_id_seq
365 START WITH 1
366 INCREMENT BY 1
367 NO MINVALUE
368 NO MAXVALUE
369 CACHE 1;
370
371
372ALTER TABLE public.charges_id_seq OWNER TO postgres;
373
374--
375-- Name: charges_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
376--
377
378ALTER SEQUENCE public.charges_id_seq OWNED BY public.charges.id;
379
380
381--
382-- Name: configs; Type: TABLE; Schema: public; Owner: postgres
383--
384
385CREATE TABLE public.configs (
386 id integer NOT NULL,
387 uuid uuid DEFAULT public.uuid_generate_v4(),
388 name character varying(64),
389 section character varying(32) DEFAULT 'user'::character varying NOT NULL,
390 data jsonb DEFAULT '{"someconfig": null}'::jsonb,
391 inserted_at timestamp without time zone NOT NULL,
392 updated_at timestamp without time zone NOT NULL
393);
394
395
396ALTER TABLE public.configs OWNER TO postgres;
397
398--
399-- Name: configs_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
400--
401
402CREATE SEQUENCE public.configs_id_seq
403 START WITH 1
404 INCREMENT BY 1
405 NO MINVALUE
406 NO MAXVALUE
407 CACHE 1;
408
409
410ALTER TABLE public.configs_id_seq OWNER TO postgres;
411
412--
413-- Name: configs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
414--
415
416ALTER SEQUENCE public.configs_id_seq OWNED BY public.configs.id;
417
418
419--
420-- Name: contacts; Type: TABLE; Schema: public; Owner: postgres
421--
422
423CREATE TABLE public.contacts (
424 id integer NOT NULL,
425 is_active boolean DEFAULT true NOT NULL,
426 national_number bigint,
427 area_code integer DEFAULT 98,
428 can_be_charged boolean DEFAULT true NOT NULL,
429 inserted_at timestamp without time zone NOT NULL,
430 updated_at timestamp without time zone NOT NULL,
431 last_message_datetime timestamp without time zone,
432 last_charge_datetime timestamp without time zone,
433 namespace character varying(64),
434 service_id integer,
435 app_id integer,
436 subscription_id integer,
437 latest_message_md5 character varying(64),
438 is_prepaid boolean,
439 last_reaction character varying(64),
440 city character varying(64),
441 state character varying(64),
442 country character varying(64),
443 latest_mo character varying(128),
444 fake_number character varying(64)
445);
446
447
448ALTER TABLE public.contacts OWNER TO postgres;
449
450--
451-- Name: contacts_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
452--
453
454CREATE SEQUENCE public.contacts_id_seq
455 START WITH 1
456 INCREMENT BY 1
457 NO MINVALUE
458 NO MAXVALUE
459 CACHE 1;
460
461
462ALTER TABLE public.contacts_id_seq OWNER TO postgres;
463
464--
465-- Name: contacts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
466--
467
468ALTER SEQUENCE public.contacts_id_seq OWNED BY public.contacts.id;
469
470
471--
472-- Name: contacts_services; Type: TABLE; Schema: public; Owner: postgres
473--
474
475CREATE TABLE public.contacts_services (
476 contact_id integer,
477 service_id integer
478);
479
480
481ALTER TABLE public.contacts_services OWNER TO postgres;
482
483--
484-- Name: gateways; Type: TABLE; Schema: public; Owner: postgres
485--
486
487CREATE TABLE public.gateways (
488 id integer NOT NULL,
489 name character varying(64) NOT NULL,
490 uuid uuid DEFAULT public.uuid_generate_v4(),
491 operator character varying(64) NOT NULL,
492 sms_center character varying(64) NOT NULL,
493 limit_per_day integer,
494 limit_per_month integer,
495 description text,
496 approved_at timestamp without time zone,
497 expiration_date timestamp without time zone,
498 start_date timestamp without time zone DEFAULT now(),
499 user_id integer,
500 config_id integer,
501 inserted_at timestamp without time zone NOT NULL,
502 updated_at timestamp without time zone NOT NULL
503);
504
505
506ALTER TABLE public.gateways OWNER TO postgres;
507
508--
509-- Name: gateways_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
510--
511
512CREATE SEQUENCE public.gateways_id_seq
513 START WITH 1
514 INCREMENT BY 1
515 NO MINVALUE
516 NO MAXVALUE
517 CACHE 1;
518
519
520ALTER TABLE public.gateways_id_seq OWNER TO postgres;
521
522--
523-- Name: gateways_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
524--
525
526ALTER SEQUENCE public.gateways_id_seq OWNED BY public.gateways.id;
527
528
529--
530-- Name: invitations; Type: TABLE; Schema: public; Owner: postgres
531--
532
533CREATE TABLE public.invitations (
534 id integer NOT NULL,
535 name character varying(255),
536 email character varying(255),
537 token character varying(255),
538 inserted_at timestamp without time zone NOT NULL,
539 updated_at timestamp without time zone NOT NULL
540);
541
542
543ALTER TABLE public.invitations OWNER TO postgres;
544
545--
546-- Name: invitations_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
547--
548
549CREATE SEQUENCE public.invitations_id_seq
550 START WITH 1
551 INCREMENT BY 1
552 NO MINVALUE
553 NO MAXVALUE
554 CACHE 1;
555
556
557ALTER TABLE public.invitations_id_seq OWNER TO postgres;
558
559--
560-- Name: invitations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
561--
562
563ALTER SEQUENCE public.invitations_id_seq OWNED BY public.invitations.id;
564
565
566--
567-- Name: logs; Type: TABLE; Schema: public; Owner: postgres
568--
569
570CREATE TABLE public.logs (
571 id integer NOT NULL,
572 uuid uuid DEFAULT public.uuid_generate_v4(),
573 body text,
574 loglevel character varying(32) DEFAULT 'info'::character varying,
575 status character varying(32),
576 user_id integer,
577 service_id integer,
578 gateway_id integer,
579 reaction_id integer,
580 inserted_at timestamp without time zone NOT NULL,
581 updated_at timestamp without time zone NOT NULL
582);
583
584
585ALTER TABLE public.logs OWNER TO postgres;
586
587--
588-- Name: logs_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
589--
590
591CREATE SEQUENCE public.logs_id_seq
592 START WITH 1
593 INCREMENT BY 1
594 NO MINVALUE
595 NO MAXVALUE
596 CACHE 1;
597
598
599ALTER TABLE public.logs_id_seq OWNER TO postgres;
600
601--
602-- Name: logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
603--
604
605ALTER SEQUENCE public.logs_id_seq OWNED BY public.logs.id;
606
607
608--
609-- Name: messages; Type: TABLE; Schema: public; Owner: postgres
610--
611
612CREATE TABLE public.messages (
613 id integer NOT NULL,
614 uuid uuid DEFAULT public.uuid_generate_v4(),
615 is_delivered boolean DEFAULT false NOT NULL,
616 is_priodic boolean DEFAULT false NOT NULL,
617 message_type character varying(16) NOT NULL,
618 message text,
619 send_datetime timestamp without time zone,
620 delivery_status character varying(64),
621 method character varying(32),
622 cron character varying(64),
623 correlator character varying(36),
624 webhook character varying(256),
625 webhook_response jsonb,
626 is_delayed boolean DEFAULT false,
627 delivery_datetime timestamp without time zone,
628 send_on timestamp without time zone DEFAULT now(),
629 end_on timestamp without time zone,
630 delivery_body jsonb,
631 variables jsonb,
632 send_counter integer DEFAULT 0 NOT NULL,
633 ticket_id character varying(32),
634 service_id integer,
635 charge_id integer,
636 template_id integer,
637 app_id integer,
638 contact_id integer,
639 inserted_at timestamp without time zone NOT NULL,
640 updated_at timestamp without time zone NOT NULL,
641 trackid character varying(64),
642 sent boolean DEFAULT false,
643 baked_message text,
644 raw_resp text,
645 description text,
646 is_active boolean DEFAULT true,
647 campaign_id integer,
648 send_lock boolean,
649 bulk_id integer,
650 if_cond jsonb
651);
652
653
654ALTER TABLE public.messages OWNER TO postgres;
655
656--
657-- Name: messages_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
658--
659
660CREATE SEQUENCE public.messages_id_seq
661 START WITH 1
662 INCREMENT BY 1
663 NO MINVALUE
664 NO MAXVALUE
665 CACHE 1;
666
667
668ALTER TABLE public.messages_id_seq OWNER TO postgres;
669
670--
671-- Name: messages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
672--
673
674ALTER SEQUENCE public.messages_id_seq OWNED BY public.messages.id;
675
676
677--
678-- Name: msd_income; Type: VIEW; Schema: public; Owner: postgres
679--
680
681CREATE VIEW public.msd_income AS
682 SELECT sum(cr.charge_amount) AS sum,
683 (timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date AS d
684 FROM (public.charges cr
685 JOIN public.contacts c ON ((c.id = cr.contact_id)))
686 WHERE ((cr.service_id = 67) AND ((timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date > '2018-08-02'::date))
687 GROUP BY ((timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date)
688 ORDER BY ((timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date);
689
690
691ALTER TABLE public.msd_income OWNER TO postgres;
692
693--
694-- Name: msd_income_1; Type: VIEW; Schema: public; Owner: postgres
695--
696
697CREATE VIEW public.msd_income_1 AS
698 SELECT sum(cr.charge_amount) AS sum,
699 (timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date AS d
700 FROM (public.charges cr
701 JOIN public.contacts c ON ((c.id = cr.contact_id)))
702 WHERE ((cr.service_id = 85) AND ((timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date > '2018-08-02'::date))
703 GROUP BY ((timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date)
704 ORDER BY ((timezone('asia/tehran'::text, timezone('utc'::text, cr.send_on)))::date);
705
706
707ALTER TABLE public.msd_income_1 OWNER TO postgres;
708
709--
710-- Name: msids; Type: TABLE; Schema: public; Owner: postgres
711--
712
713CREATE TABLE public.msids (
714 id integer NOT NULL,
715 uuid uuid DEFAULT public.uuid_generate_v4(),
716 is_prepaid boolean DEFAULT false NOT NULL,
717 country character varying(255) NOT NULL,
718 state character varying(255),
719 city character varying(255),
720 area_code integer,
721 num character varying(255) NOT NULL,
722 inserted_at timestamp without time zone NOT NULL,
723 updated_at timestamp without time zone NOT NULL
724);
725
726
727ALTER TABLE public.msids OWNER TO postgres;
728
729--
730-- Name: msids_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
731--
732
733CREATE SEQUENCE public.msids_id_seq
734 START WITH 1
735 INCREMENT BY 1
736 NO MINVALUE
737 NO MAXVALUE
738 CACHE 1;
739
740
741ALTER TABLE public.msids_id_seq OWNER TO postgres;
742
743--
744-- Name: msids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
745--
746
747ALTER SEQUENCE public.msids_id_seq OWNED BY public.msids.id;
748
749
750--
751-- Name: profiles; Type: TABLE; Schema: public; Owner: postgres
752--
753
754CREATE TABLE public.profiles (
755 id integer NOT NULL,
756 data jsonb,
757 state character varying(255),
758 previous_state character varying(255),
759 next_state character varying(255),
760 contact_id integer,
761 inserted_at timestamp without time zone NOT NULL,
762 updated_at timestamp without time zone NOT NULL
763);
764
765
766ALTER TABLE public.profiles OWNER TO postgres;
767
768--
769-- Name: profiles_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
770--
771
772CREATE SEQUENCE public.profiles_id_seq
773 START WITH 1
774 INCREMENT BY 1
775 NO MINVALUE
776 NO MAXVALUE
777 CACHE 1;
778
779
780ALTER TABLE public.profiles_id_seq OWNER TO postgres;
781
782--
783-- Name: profiles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
784--
785
786ALTER SEQUENCE public.profiles_id_seq OWNED BY public.profiles.id;
787
788
789--
790-- Name: reactions; Type: TABLE; Schema: public; Owner: postgres
791--
792
793CREATE TABLE public.reactions (
794 id integer NOT NULL,
795 uuid uuid DEFAULT public.uuid_generate_v4(),
796 name character varying(64),
797 webhook character varying(256),
798 webhook_response jsonb,
799 targets jsonb,
800 variables jsonb,
801 service_id integer,
802 app_id integer,
803 template_id integer,
804 inserted_at timestamp without time zone NOT NULL,
805 updated_at timestamp without time zone NOT NULL,
806 slackid character varying(128),
807 slack_message character varying(128),
808 is_optin boolean DEFAULT false,
809 is_optout boolean DEFAULT false,
810 previous_reaction character varying(64),
811 exceptions jsonb,
812 previous_reaction_not character varying(128),
813 trigger_if_subscribed boolean,
814 trigger_if_not_subscribed boolean,
815 next_reaction character varying(128),
816 mute boolean DEFAULT false,
817 is_active boolean DEFAULT true
818);
819
820
821ALTER TABLE public.reactions OWNER TO postgres;
822
823--
824-- Name: reactions_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
825--
826
827CREATE SEQUENCE public.reactions_id_seq
828 START WITH 1
829 INCREMENT BY 1
830 NO MINVALUE
831 NO MAXVALUE
832 CACHE 1;
833
834
835ALTER TABLE public.reactions_id_seq OWNER TO postgres;
836
837--
838-- Name: reactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
839--
840
841ALTER SEQUENCE public.reactions_id_seq OWNED BY public.reactions.id;
842
843
844--
845-- Name: rememberables; Type: TABLE; Schema: public; Owner: postgres
846--
847
848CREATE TABLE public.rememberables (
849 id integer NOT NULL,
850 series_hash character varying(255),
851 token_hash character varying(255),
852 token_created_at timestamp without time zone,
853 user_id integer,
854 inserted_at timestamp without time zone NOT NULL,
855 updated_at timestamp without time zone NOT NULL
856);
857
858
859ALTER TABLE public.rememberables OWNER TO postgres;
860
861--
862-- Name: rememberables_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
863--
864
865CREATE SEQUENCE public.rememberables_id_seq
866 START WITH 1
867 INCREMENT BY 1
868 NO MINVALUE
869 NO MAXVALUE
870 CACHE 1;
871
872
873ALTER TABLE public.rememberables_id_seq OWNER TO postgres;
874
875--
876-- Name: rememberables_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
877--
878
879ALTER SEQUENCE public.rememberables_id_seq OWNED BY public.rememberables.id;
880
881
882--
883-- Name: reports; Type: TABLE; Schema: public; Owner: postgres
884--
885
886CREATE TABLE public.reports (
887 id integer NOT NULL,
888 body text,
889 uuid uuid DEFAULT public.uuid_generate_v4(),
890 email_to character varying(128),
891 sms_to character varying(16),
892 send_status character varying(32) DEFAULT 'pending'::character varying,
893 is_active boolean DEFAULT true NOT NULL,
894 user_id integer,
895 service_id integer,
896 app_id integer,
897 inserted_at timestamp without time zone NOT NULL,
898 updated_at timestamp without time zone NOT NULL
899);
900
901
902ALTER TABLE public.reports OWNER TO postgres;
903
904--
905-- Name: reports_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
906--
907
908CREATE SEQUENCE public.reports_id_seq
909 START WITH 1
910 INCREMENT BY 1
911 NO MINVALUE
912 NO MAXVALUE
913 CACHE 1;
914
915
916ALTER TABLE public.reports_id_seq OWNER TO postgres;
917
918--
919-- Name: reports_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
920--
921
922ALTER SEQUENCE public.reports_id_seq OWNED BY public.reports.id;
923
924
925--
926-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: postgres
927--
928
929CREATE TABLE public.schema_migrations (
930 version bigint NOT NULL,
931 inserted_at timestamp without time zone
932);
933
934
935ALTER TABLE public.schema_migrations OWNER TO postgres;
936
937--
938-- Name: service_reports; Type: TABLE; Schema: public; Owner: postgres
939--
940
941CREATE TABLE public.service_reports (
942 id integer NOT NULL,
943 total_prepaid_subscribers integer,
944 new_prepaid_subscribers integer,
945 prepaid_deactivations integer,
946 prepaid_successful_charges_count integer,
947 prepaid_failed_charges_count integer,
948 prepaid_successful_charges_amount integer,
949 prepaid_failed_charges_amount integer,
950 prepaid_revenue integer,
951 prepaid_mo_count integer,
952 prepaid_mt_count integer,
953 prepaid_delivery_count integer,
954 prepaid_bounced_subscribers integer,
955 prepaid_wap_push_count integer,
956 prepaid_group_panel_deactivations integer,
957 total_postpaid_subscribers integer,
958 new_postpaid_subscribers integer,
959 postpaid_deactivations integer,
960 postpaid_successful_charges_count integer,
961 postpaid_failed_charges_count integer,
962 postpaid_successful_charges_amount integer,
963 postpaid_failed_charges_amount integer,
964 postpaid_revenue integer,
965 postpaid_mo_count integer,
966 postpaid_mt_count integer,
967 postpaid_delivery_count integer,
968 extra_data jsonb,
969 postpaid_bounced_subscribers integer,
970 postpaid_wap_push_count integer,
971 postpaid_group_panel_deactivations integer,
972 jday character varying(255),
973 datetime timestamp without time zone,
974 service_id integer,
975 app_id integer,
976 inserted_at timestamp without time zone NOT NULL,
977 updated_at timestamp without time zone NOT NULL,
978 retention real DEFAULT 0,
979 mix_payout integer DEFAULT 0,
980 max_payout integer DEFAULT 0,
981 best_charged_item character varying(255),
982 top_prepaid_charged_cities character varying(256),
983 top_postpaid_charged_cities character varying(256),
984 top_prepaid_charged_states character varying(256),
985 top_postpaid_charged_states character varying(256),
986 total_fakenumber_subscribers integer
987);
988
989
990ALTER TABLE public.service_reports OWNER TO postgres;
991
992--
993-- Name: service_reports_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
994--
995
996CREATE SEQUENCE public.service_reports_id_seq
997 START WITH 1
998 INCREMENT BY 1
999 NO MINVALUE
1000 NO MAXVALUE
1001 CACHE 1;
1002
1003
1004ALTER TABLE public.service_reports_id_seq OWNER TO postgres;
1005
1006--
1007-- Name: service_reports_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
1008--
1009
1010ALTER SEQUENCE public.service_reports_id_seq OWNED BY public.service_reports.id;
1011
1012
1013--
1014-- Name: services; Type: TABLE; Schema: public; Owner: postgres
1015--
1016
1017CREATE TABLE public.services (
1018 id integer NOT NULL,
1019 name character varying(64) NOT NULL,
1020 uuid uuid DEFAULT public.uuid_generate_v4(),
1021 provider character varying(128) NOT NULL,
1022 description text,
1023 expiration_datetime timestamp without time zone,
1024 short_code character varying(32) NOT NULL,
1025 start_datetime timestamp without time zone DEFAULT now(),
1026 user_id integer NOT NULL,
1027 config_id integer NOT NULL,
1028 gateway_id integer NOT NULL,
1029 inserted_at timestamp without time zone NOT NULL,
1030 updated_at timestamp without time zone NOT NULL,
1031 template_id integer,
1032 sms_tpm integer DEFAULT 20,
1033 charge_tpm integer DEFAULT 20,
1034 report_key uuid DEFAULT public.uuid_generate_v4(),
1035 is_active boolean DEFAULT true
1036);
1037
1038
1039ALTER TABLE public.services OWNER TO postgres;
1040
1041--
1042-- Name: services_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
1043--
1044
1045CREATE SEQUENCE public.services_id_seq
1046 START WITH 1
1047 INCREMENT BY 1
1048 NO MINVALUE
1049 NO MAXVALUE
1050 CACHE 1;
1051
1052
1053ALTER TABLE public.services_id_seq OWNER TO postgres;
1054
1055--
1056-- Name: services_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
1057--
1058
1059ALTER SEQUENCE public.services_id_seq OWNED BY public.services.id;
1060
1061
1062--
1063-- Name: subscriptions; Type: TABLE; Schema: public; Owner: postgres
1064--
1065
1066CREATE TABLE public.subscriptions (
1067 id integer NOT NULL,
1068 duration integer NOT NULL,
1069 name character varying(256),
1070 is_active boolean DEFAULT true,
1071 service_id integer,
1072 app_id integer,
1073 inserted_at timestamp without time zone NOT NULL,
1074 updated_at timestamp without time zone NOT NULL,
1075 uuid uuid DEFAULT public.uuid_generate_v4(),
1076 contact_id integer,
1077 history jsonb,
1078 activated_on timestamp without time zone,
1079 deactivated_on timestamp without time zone,
1080 daily_charge_amount integer DEFAULT 0,
1081 otp_transaction_id character varying(255),
1082 reference_code character varying(255),
1083 content_id character varying(255),
1084 source character varying(16),
1085 sub_source character varying(16),
1086 unsub_source character varying(16)
1087);
1088
1089
1090ALTER TABLE public.subscriptions OWNER TO postgres;
1091
1092--
1093-- Name: subscriptions_contacts; Type: TABLE; Schema: public; Owner: postgres
1094--
1095
1096CREATE TABLE public.subscriptions_contacts (
1097 contact_id integer,
1098 subscription_id integer
1099);
1100
1101
1102ALTER TABLE public.subscriptions_contacts OWNER TO postgres;
1103
1104--
1105-- Name: subscriptions_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
1106--
1107
1108CREATE SEQUENCE public.subscriptions_id_seq
1109 START WITH 1
1110 INCREMENT BY 1
1111 NO MINVALUE
1112 NO MAXVALUE
1113 CACHE 1;
1114
1115
1116ALTER TABLE public.subscriptions_id_seq OWNER TO postgres;
1117
1118--
1119-- Name: subscriptions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
1120--
1121
1122ALTER SEQUENCE public.subscriptions_id_seq OWNED BY public.subscriptions.id;
1123
1124
1125--
1126-- Name: templates; Type: TABLE; Schema: public; Owner: postgres
1127--
1128
1129CREATE TABLE public.templates (
1130 id integer NOT NULL,
1131 uuid uuid DEFAULT public.uuid_generate_v4(),
1132 name character varying(64),
1133 body text NOT NULL,
1134 section character varying(32) DEFAULT 'user'::character varying NOT NULL,
1135 random_selection jsonb,
1136 user_id integer,
1137 inserted_at timestamp without time zone NOT NULL,
1138 updated_at timestamp without time zone NOT NULL,
1139 service_id bigint
1140);
1141
1142
1143ALTER TABLE public.templates OWNER TO postgres;
1144
1145--
1146-- Name: templates_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
1147--
1148
1149CREATE SEQUENCE public.templates_id_seq
1150 START WITH 1
1151 INCREMENT BY 1
1152 NO MINVALUE
1153 NO MAXVALUE
1154 CACHE 1;
1155
1156
1157ALTER TABLE public.templates_id_seq OWNER TO postgres;
1158
1159--
1160-- Name: templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
1161--
1162
1163ALTER SEQUENCE public.templates_id_seq OWNED BY public.templates.id;
1164
1165
1166--
1167-- Name: users; Type: TABLE; Schema: public; Owner: postgres
1168--
1169
1170CREATE TABLE public.users (
1171 id integer NOT NULL,
1172 name character varying(128) NOT NULL,
1173 email character varying(128) NOT NULL,
1174 uuid uuid DEFAULT public.uuid_generate_v4(),
1175 client_key uuid DEFAULT public.uuid_generate_v4(),
1176 confirmation_token character varying(64),
1177 confirmed_at timestamp without time zone,
1178 confirmation_sent_at timestamp without time zone,
1179 cell_phone character varying(16) NOT NULL,
1180 config jsonb,
1181 company character varying(255) NOT NULL,
1182 is_active boolean DEFAULT false NOT NULL,
1183 is_admin boolean DEFAULT false NOT NULL,
1184 remember_created_at timestamp without time zone,
1185 password_hash character varying(64),
1186 reset_password_token character varying(64),
1187 reset_password_sent_at timestamp without time zone,
1188 failed_attempts integer DEFAULT 0,
1189 locked_at timestamp without time zone,
1190 sign_in_count integer DEFAULT 0,
1191 current_sign_in_at timestamp without time zone,
1192 last_sign_in_at timestamp without time zone,
1193 current_sign_in_ip character varying(32),
1194 last_sign_in_ip character varying(32),
1195 unlock_token character varying(64),
1196 inserted_at timestamp without time zone NOT NULL,
1197 updated_at timestamp without time zone NOT NULL,
1198 report_key uuid DEFAULT public.uuid_generate_v4(),
1199 can_create_service boolean DEFAULT false
1200);
1201
1202
1203ALTER TABLE public.users OWNER TO postgres;
1204
1205--
1206-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
1207--
1208
1209CREATE SEQUENCE public.users_id_seq
1210 START WITH 1
1211 INCREMENT BY 1
1212 NO MINVALUE
1213 NO MAXVALUE
1214 CACHE 1;
1215
1216
1217ALTER TABLE public.users_id_seq OWNER TO postgres;
1218
1219--
1220-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
1221--
1222
1223ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
1224
1225
1226--
1227-- Name: apikeys id; Type: DEFAULT; Schema: public; Owner: postgres
1228--
1229
1230ALTER TABLE ONLY public.apikeys ALTER COLUMN id SET DEFAULT nextval('public.apikeys_id_seq'::regclass);
1231
1232
1233--
1234-- Name: apps id; Type: DEFAULT; Schema: public; Owner: postgres
1235--
1236
1237ALTER TABLE ONLY public.apps ALTER COLUMN id SET DEFAULT nextval('public.apps_id_seq'::regclass);
1238
1239
1240--
1241-- Name: bulks id; Type: DEFAULT; Schema: public; Owner: postgres
1242--
1243
1244ALTER TABLE ONLY public.bulks ALTER COLUMN id SET DEFAULT nextval('public.bulks_id_seq'::regclass);
1245
1246
1247--
1248-- Name: campaigns id; Type: DEFAULT; Schema: public; Owner: postgres
1249--
1250
1251ALTER TABLE ONLY public.campaigns ALTER COLUMN id SET DEFAULT nextval('public.campaigns_id_seq'::regclass);
1252
1253
1254--
1255-- Name: charges id; Type: DEFAULT; Schema: public; Owner: postgres
1256--
1257
1258ALTER TABLE ONLY public.charges ALTER COLUMN id SET DEFAULT nextval('public.charges_id_seq'::regclass);
1259
1260
1261--
1262-- Name: configs id; Type: DEFAULT; Schema: public; Owner: postgres
1263--
1264
1265ALTER TABLE ONLY public.configs ALTER COLUMN id SET DEFAULT nextval('public.configs_id_seq'::regclass);
1266
1267
1268--
1269-- Name: contacts id; Type: DEFAULT; Schema: public; Owner: postgres
1270--
1271
1272ALTER TABLE ONLY public.contacts ALTER COLUMN id SET DEFAULT nextval('public.contacts_id_seq'::regclass);
1273
1274
1275--
1276-- Name: gateways id; Type: DEFAULT; Schema: public; Owner: postgres
1277--
1278
1279ALTER TABLE ONLY public.gateways ALTER COLUMN id SET DEFAULT nextval('public.gateways_id_seq'::regclass);
1280
1281
1282--
1283-- Name: invitations id; Type: DEFAULT; Schema: public; Owner: postgres
1284--
1285
1286ALTER TABLE ONLY public.invitations ALTER COLUMN id SET DEFAULT nextval('public.invitations_id_seq'::regclass);
1287
1288
1289--
1290-- Name: logs id; Type: DEFAULT; Schema: public; Owner: postgres
1291--
1292
1293ALTER TABLE ONLY public.logs ALTER COLUMN id SET DEFAULT nextval('public.logs_id_seq'::regclass);
1294
1295
1296--
1297-- Name: messages id; Type: DEFAULT; Schema: public; Owner: postgres
1298--
1299
1300ALTER TABLE ONLY public.messages ALTER COLUMN id SET DEFAULT nextval('public.messages_id_seq'::regclass);
1301
1302
1303--
1304-- Name: msids id; Type: DEFAULT; Schema: public; Owner: postgres
1305--
1306
1307ALTER TABLE ONLY public.msids ALTER COLUMN id SET DEFAULT nextval('public.msids_id_seq'::regclass);
1308
1309
1310--
1311-- Name: profiles id; Type: DEFAULT; Schema: public; Owner: postgres
1312--
1313
1314ALTER TABLE ONLY public.profiles ALTER COLUMN id SET DEFAULT nextval('public.profiles_id_seq'::regclass);
1315
1316
1317--
1318-- Name: reactions id; Type: DEFAULT; Schema: public; Owner: postgres
1319--
1320
1321ALTER TABLE ONLY public.reactions ALTER COLUMN id SET DEFAULT nextval('public.reactions_id_seq'::regclass);
1322
1323
1324--
1325-- Name: rememberables id; Type: DEFAULT; Schema: public; Owner: postgres
1326--
1327
1328ALTER TABLE ONLY public.rememberables ALTER COLUMN id SET DEFAULT nextval('public.rememberables_id_seq'::regclass);
1329
1330
1331--
1332-- Name: reports id; Type: DEFAULT; Schema: public; Owner: postgres
1333--
1334
1335ALTER TABLE ONLY public.reports ALTER COLUMN id SET DEFAULT nextval('public.reports_id_seq'::regclass);
1336
1337
1338--
1339-- Name: service_reports id; Type: DEFAULT; Schema: public; Owner: postgres
1340--
1341
1342ALTER TABLE ONLY public.service_reports ALTER COLUMN id SET DEFAULT nextval('public.service_reports_id_seq'::regclass);
1343
1344
1345--
1346-- Name: services id; Type: DEFAULT; Schema: public; Owner: postgres
1347--
1348
1349ALTER TABLE ONLY public.services ALTER COLUMN id SET DEFAULT nextval('public.services_id_seq'::regclass);
1350
1351
1352--
1353-- Name: subscriptions id; Type: DEFAULT; Schema: public; Owner: postgres
1354--
1355
1356ALTER TABLE ONLY public.subscriptions ALTER COLUMN id SET DEFAULT nextval('public.subscriptions_id_seq'::regclass);
1357
1358
1359--
1360-- Name: templates id; Type: DEFAULT; Schema: public; Owner: postgres
1361--
1362
1363ALTER TABLE ONLY public.templates ALTER COLUMN id SET DEFAULT nextval('public.templates_id_seq'::regclass);
1364
1365
1366--
1367-- Name: users id; Type: DEFAULT; Schema: public; Owner: postgres
1368--
1369
1370ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
1371
1372
1373--
1374-- Name: apikeys apikeys_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1375--
1376
1377ALTER TABLE ONLY public.apikeys
1378 ADD CONSTRAINT apikeys_pkey PRIMARY KEY (id);
1379
1380
1381--
1382-- Name: apps apps_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1383--
1384
1385ALTER TABLE ONLY public.apps
1386 ADD CONSTRAINT apps_pkey PRIMARY KEY (id);
1387
1388
1389--
1390-- Name: bulks bulks_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1391--
1392
1393ALTER TABLE ONLY public.bulks
1394 ADD CONSTRAINT bulks_pkey PRIMARY KEY (id);
1395
1396
1397--
1398-- Name: campaigns campaigns_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1399--
1400
1401ALTER TABLE ONLY public.campaigns
1402 ADD CONSTRAINT campaigns_pkey PRIMARY KEY (id);
1403
1404
1405--
1406-- Name: charges charges_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1407--
1408
1409ALTER TABLE ONLY public.charges
1410 ADD CONSTRAINT charges_pkey PRIMARY KEY (id);
1411
1412
1413--
1414-- Name: configs configs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1415--
1416
1417ALTER TABLE ONLY public.configs
1418 ADD CONSTRAINT configs_pkey PRIMARY KEY (id);
1419
1420
1421--
1422-- Name: contacts contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1423--
1424
1425ALTER TABLE ONLY public.contacts
1426 ADD CONSTRAINT contacts_pkey PRIMARY KEY (id);
1427
1428
1429--
1430-- Name: gateways gateways_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1431--
1432
1433ALTER TABLE ONLY public.gateways
1434 ADD CONSTRAINT gateways_pkey PRIMARY KEY (id);
1435
1436
1437--
1438-- Name: invitations invitations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1439--
1440
1441ALTER TABLE ONLY public.invitations
1442 ADD CONSTRAINT invitations_pkey PRIMARY KEY (id);
1443
1444
1445--
1446-- Name: logs logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1447--
1448
1449ALTER TABLE ONLY public.logs
1450 ADD CONSTRAINT logs_pkey PRIMARY KEY (id);
1451
1452
1453--
1454-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1455--
1456
1457ALTER TABLE ONLY public.messages
1458 ADD CONSTRAINT messages_pkey PRIMARY KEY (id);
1459
1460
1461--
1462-- Name: msids msids_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1463--
1464
1465ALTER TABLE ONLY public.msids
1466 ADD CONSTRAINT msids_pkey PRIMARY KEY (id);
1467
1468
1469--
1470-- Name: profiles profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1471--
1472
1473ALTER TABLE ONLY public.profiles
1474 ADD CONSTRAINT profiles_pkey PRIMARY KEY (id);
1475
1476
1477--
1478-- Name: reactions reactions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1479--
1480
1481ALTER TABLE ONLY public.reactions
1482 ADD CONSTRAINT reactions_pkey PRIMARY KEY (id);
1483
1484
1485--
1486-- Name: rememberables rememberables_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1487--
1488
1489ALTER TABLE ONLY public.rememberables
1490 ADD CONSTRAINT rememberables_pkey PRIMARY KEY (id);
1491
1492
1493--
1494-- Name: reports reports_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1495--
1496
1497ALTER TABLE ONLY public.reports
1498 ADD CONSTRAINT reports_pkey PRIMARY KEY (id);
1499
1500
1501--
1502-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1503--
1504
1505ALTER TABLE ONLY public.schema_migrations
1506 ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
1507
1508
1509--
1510-- Name: service_reports service_reports_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1511--
1512
1513ALTER TABLE ONLY public.service_reports
1514 ADD CONSTRAINT service_reports_pkey PRIMARY KEY (id);
1515
1516
1517--
1518-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1519--
1520
1521ALTER TABLE ONLY public.services
1522 ADD CONSTRAINT services_pkey PRIMARY KEY (id);
1523
1524
1525--
1526-- Name: subscriptions subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1527--
1528
1529ALTER TABLE ONLY public.subscriptions
1530 ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (id);
1531
1532
1533--
1534-- Name: templates templates_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1535--
1536
1537ALTER TABLE ONLY public.templates
1538 ADD CONSTRAINT templates_pkey PRIMARY KEY (id);
1539
1540
1541--
1542-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
1543--
1544
1545ALTER TABLE ONLY public.users
1546 ADD CONSTRAINT users_pkey PRIMARY KEY (id);
1547
1548
1549--
1550-- Name: apikeys_app_id_index; Type: INDEX; Schema: public; Owner: postgres
1551--
1552
1553CREATE INDEX apikeys_app_id_index ON public.apikeys USING btree (app_id);
1554
1555
1556--
1557-- Name: apikeys_name_app_id_index; Type: INDEX; Schema: public; Owner: postgres
1558--
1559
1560CREATE UNIQUE INDEX apikeys_name_app_id_index ON public.apikeys USING btree (name, app_id);
1561
1562
1563--
1564-- Name: apps_name_index; Type: INDEX; Schema: public; Owner: postgres
1565--
1566
1567CREATE INDEX apps_name_index ON public.apps USING btree (name);
1568
1569
1570--
1571-- Name: apps_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1572--
1573
1574CREATE INDEX apps_service_id_index ON public.apps USING btree (service_id);
1575
1576
1577--
1578-- Name: apps_service_id_name_index; Type: INDEX; Schema: public; Owner: postgres
1579--
1580
1581CREATE UNIQUE INDEX apps_service_id_name_index ON public.apps USING btree (service_id, name);
1582
1583
1584--
1585-- Name: apps_user_id_index; Type: INDEX; Schema: public; Owner: postgres
1586--
1587
1588CREATE INDEX apps_user_id_index ON public.apps USING btree (user_id);
1589
1590
1591--
1592-- Name: apps_user_id_name_index; Type: INDEX; Schema: public; Owner: postgres
1593--
1594
1595CREATE UNIQUE INDEX apps_user_id_name_index ON public.apps USING btree (user_id, name);
1596
1597
1598--
1599-- Name: apps_uuid_index; Type: INDEX; Schema: public; Owner: postgres
1600--
1601
1602CREATE INDEX apps_uuid_index ON public.apps USING btree (uuid);
1603
1604
1605--
1606-- Name: bulks_contacts_bulk_id_index; Type: INDEX; Schema: public; Owner: postgres
1607--
1608
1609CREATE INDEX bulks_contacts_bulk_id_index ON public.bulks_contacts USING btree (bulk_id);
1610
1611
1612--
1613-- Name: bulks_contacts_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
1614--
1615
1616CREATE INDEX bulks_contacts_contact_id_index ON public.bulks_contacts USING btree (contact_id);
1617
1618
1619--
1620-- Name: bulks_expected_reaction_id_index; Type: INDEX; Schema: public; Owner: postgres
1621--
1622
1623CREATE INDEX bulks_expected_reaction_id_index ON public.bulks USING btree (expected_reaction_id);
1624
1625
1626--
1627-- Name: bulks_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1628--
1629
1630CREATE INDEX bulks_service_id_index ON public.bulks USING btree (service_id);
1631
1632
1633--
1634-- Name: bulks_service_id_name_index; Type: INDEX; Schema: public; Owner: postgres
1635--
1636
1637CREATE UNIQUE INDEX bulks_service_id_name_index ON public.bulks USING btree (service_id, name);
1638
1639
1640--
1641-- Name: bulks_slack_id_index; Type: INDEX; Schema: public; Owner: postgres
1642--
1643
1644CREATE INDEX bulks_slack_id_index ON public.bulks USING btree (slack_id);
1645
1646
1647--
1648-- Name: bulks_start_on_end_on_index; Type: INDEX; Schema: public; Owner: postgres
1649--
1650
1651CREATE INDEX bulks_start_on_end_on_index ON public.bulks USING btree (start_on, end_on);
1652
1653
1654--
1655-- Name: campaigns_app_id_index; Type: INDEX; Schema: public; Owner: postgres
1656--
1657
1658CREATE INDEX campaigns_app_id_index ON public.campaigns USING btree (app_id);
1659
1660
1661--
1662-- Name: campaigns_app_id_name_index; Type: INDEX; Schema: public; Owner: postgres
1663--
1664
1665CREATE UNIQUE INDEX campaigns_app_id_name_index ON public.campaigns USING btree (app_id, name);
1666
1667
1668--
1669-- Name: campaigns_is_active_index; Type: INDEX; Schema: public; Owner: postgres
1670--
1671
1672CREATE INDEX campaigns_is_active_index ON public.campaigns USING btree (is_active);
1673
1674
1675--
1676-- Name: campaigns_name_index; Type: INDEX; Schema: public; Owner: postgres
1677--
1678
1679CREATE INDEX campaigns_name_index ON public.campaigns USING btree (name);
1680
1681
1682--
1683-- Name: campaigns_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1684--
1685
1686CREATE INDEX campaigns_service_id_index ON public.campaigns USING btree (service_id);
1687
1688
1689--
1690-- Name: campaigns_service_id_name_index; Type: INDEX; Schema: public; Owner: postgres
1691--
1692
1693CREATE UNIQUE INDEX campaigns_service_id_name_index ON public.campaigns USING btree (service_id, name);
1694
1695
1696--
1697-- Name: charges_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
1698--
1699
1700CREATE INDEX charges_contact_id_index ON public.charges USING btree (contact_id);
1701
1702
1703--
1704-- Name: charges_send_on_service_idx; Type: INDEX; Schema: public; Owner: postgres
1705--
1706
1707CREATE INDEX charges_send_on_service_idx ON public.charges USING btree (send_on, service_id);
1708
1709
1710--
1711-- Name: charges_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1712--
1713
1714CREATE INDEX charges_service_id_index ON public.charges USING btree (service_id);
1715
1716
1717--
1718-- Name: configs_name_section_index; Type: INDEX; Schema: public; Owner: postgres
1719--
1720
1721CREATE UNIQUE INDEX configs_name_section_index ON public.configs USING btree (name, section);
1722
1723
1724--
1725-- Name: contacts_area_code_national_number_fake_number_app_id_index; Type: INDEX; Schema: public; Owner: postgres
1726--
1727
1728CREATE UNIQUE INDEX contacts_area_code_national_number_fake_number_app_id_index ON public.contacts USING btree (area_code, national_number, fake_number, app_id);
1729
1730
1731--
1732-- Name: contacts_services_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
1733--
1734
1735CREATE INDEX contacts_services_contact_id_index ON public.contacts_services USING btree (contact_id);
1736
1737
1738--
1739-- Name: contacts_services_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1740--
1741
1742CREATE INDEX contacts_services_service_id_index ON public.contacts_services USING btree (service_id);
1743
1744
1745--
1746-- Name: gateways_name_index; Type: INDEX; Schema: public; Owner: postgres
1747--
1748
1749CREATE INDEX gateways_name_index ON public.gateways USING btree (name);
1750
1751
1752--
1753-- Name: gateways_name_user_id_index; Type: INDEX; Schema: public; Owner: postgres
1754--
1755
1756CREATE UNIQUE INDEX gateways_name_user_id_index ON public.gateways USING btree (name, user_id);
1757
1758
1759--
1760-- Name: gateways_sms_center_user_id_index; Type: INDEX; Schema: public; Owner: postgres
1761--
1762
1763CREATE UNIQUE INDEX gateways_sms_center_user_id_index ON public.gateways USING btree (sms_center, user_id);
1764
1765
1766--
1767-- Name: gateways_user_id_index; Type: INDEX; Schema: public; Owner: postgres
1768--
1769
1770CREATE INDEX gateways_user_id_index ON public.gateways USING btree (user_id);
1771
1772
1773--
1774-- Name: idx_correlator; Type: INDEX; Schema: public; Owner: postgres
1775--
1776
1777CREATE INDEX idx_correlator ON public.messages USING btree (correlator);
1778
1779
1780--
1781-- Name: idx_get_charge_1; Type: INDEX; Schema: public; Owner: postgres
1782--
1783
1784CREATE INDEX idx_get_charge_1 ON public.charges USING btree (correlator, service_id, contact_id);
1785
1786
1787--
1788-- Name: idx_get_message_1; Type: INDEX; Schema: public; Owner: postgres
1789--
1790
1791CREATE INDEX idx_get_message_1 ON public.messages USING btree (correlator, service_id, contact_id);
1792
1793
1794--
1795-- Name: idx_messages_inserted_at; Type: INDEX; Schema: public; Owner: postgres
1796--
1797
1798CREATE INDEX idx_messages_inserted_at ON public.messages USING btree (inserted_at);
1799
1800
1801--
1802-- Name: idx_select_due_messages; Type: INDEX; Schema: public; Owner: postgres
1803--
1804
1805CREATE INDEX idx_select_due_messages ON public.messages USING btree (is_active, sent, send_lock, method, cron, is_delivered, service_id, send_on, end_on);
1806
1807
1808--
1809-- Name: invitations_email_index; Type: INDEX; Schema: public; Owner: postgres
1810--
1811
1812CREATE UNIQUE INDEX invitations_email_index ON public.invitations USING btree (email);
1813
1814
1815--
1816-- Name: invitations_token_index; Type: INDEX; Schema: public; Owner: postgres
1817--
1818
1819CREATE INDEX invitations_token_index ON public.invitations USING btree (token);
1820
1821
1822--
1823-- Name: logs_gateway_id_index; Type: INDEX; Schema: public; Owner: postgres
1824--
1825
1826CREATE INDEX logs_gateway_id_index ON public.logs USING btree (gateway_id);
1827
1828
1829--
1830-- Name: logs_reaction_id_index; Type: INDEX; Schema: public; Owner: postgres
1831--
1832
1833CREATE INDEX logs_reaction_id_index ON public.logs USING btree (reaction_id);
1834
1835
1836--
1837-- Name: logs_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1838--
1839
1840CREATE INDEX logs_service_id_index ON public.logs USING btree (service_id);
1841
1842
1843--
1844-- Name: logs_user_id_index; Type: INDEX; Schema: public; Owner: postgres
1845--
1846
1847CREATE INDEX logs_user_id_index ON public.logs USING btree (user_id);
1848
1849
1850--
1851-- Name: messages_charge_id_index; Type: INDEX; Schema: public; Owner: postgres
1852--
1853
1854CREATE INDEX messages_charge_id_index ON public.messages USING btree (charge_id);
1855
1856
1857--
1858-- Name: messages_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
1859--
1860
1861CREATE INDEX messages_contact_id_index ON public.messages USING btree (contact_id);
1862
1863
1864--
1865-- Name: messages_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1866--
1867
1868CREATE INDEX messages_service_id_index ON public.messages USING btree (service_id);
1869
1870
1871--
1872-- Name: messages_template_id_index; Type: INDEX; Schema: public; Owner: postgres
1873--
1874
1875CREATE INDEX messages_template_id_index ON public.messages USING btree (template_id);
1876
1877
1878--
1879-- Name: msids_area_code_index; Type: INDEX; Schema: public; Owner: postgres
1880--
1881
1882CREATE INDEX msids_area_code_index ON public.msids USING btree (area_code);
1883
1884
1885--
1886-- Name: msids_area_code_num_index; Type: INDEX; Schema: public; Owner: postgres
1887--
1888
1889CREATE UNIQUE INDEX msids_area_code_num_index ON public.msids USING btree (area_code, num);
1890
1891
1892--
1893-- Name: msids_city_index; Type: INDEX; Schema: public; Owner: postgres
1894--
1895
1896CREATE INDEX msids_city_index ON public.msids USING btree (city);
1897
1898
1899--
1900-- Name: msids_country_index; Type: INDEX; Schema: public; Owner: postgres
1901--
1902
1903CREATE INDEX msids_country_index ON public.msids USING btree (country);
1904
1905
1906--
1907-- Name: msids_is_prepaid_index; Type: INDEX; Schema: public; Owner: postgres
1908--
1909
1910CREATE INDEX msids_is_prepaid_index ON public.msids USING btree (is_prepaid);
1911
1912
1913--
1914-- Name: msids_num_index; Type: INDEX; Schema: public; Owner: postgres
1915--
1916
1917CREATE INDEX msids_num_index ON public.msids USING btree (num);
1918
1919
1920--
1921-- Name: msids_state_index; Type: INDEX; Schema: public; Owner: postgres
1922--
1923
1924CREATE INDEX msids_state_index ON public.msids USING btree (state);
1925
1926
1927--
1928-- Name: profiles_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
1929--
1930
1931CREATE INDEX profiles_contact_id_index ON public.profiles USING btree (contact_id);
1932
1933
1934--
1935-- Name: profiles_next_state_index; Type: INDEX; Schema: public; Owner: postgres
1936--
1937
1938CREATE INDEX profiles_next_state_index ON public.profiles USING btree (next_state);
1939
1940
1941--
1942-- Name: profiles_previous_state_index; Type: INDEX; Schema: public; Owner: postgres
1943--
1944
1945CREATE INDEX profiles_previous_state_index ON public.profiles USING btree (previous_state);
1946
1947
1948--
1949-- Name: profiles_state_index; Type: INDEX; Schema: public; Owner: postgres
1950--
1951
1952CREATE INDEX profiles_state_index ON public.profiles USING btree (state);
1953
1954
1955--
1956-- Name: reactions_app_id_index; Type: INDEX; Schema: public; Owner: postgres
1957--
1958
1959CREATE INDEX reactions_app_id_index ON public.reactions USING btree (app_id);
1960
1961
1962--
1963-- Name: reactions_app_id_name_index; Type: INDEX; Schema: public; Owner: postgres
1964--
1965
1966CREATE UNIQUE INDEX reactions_app_id_name_index ON public.reactions USING btree (app_id, name);
1967
1968
1969--
1970-- Name: reactions_is_optin_index; Type: INDEX; Schema: public; Owner: postgres
1971--
1972
1973CREATE INDEX reactions_is_optin_index ON public.reactions USING btree (is_optin);
1974
1975
1976--
1977-- Name: reactions_is_optout_index; Type: INDEX; Schema: public; Owner: postgres
1978--
1979
1980CREATE INDEX reactions_is_optout_index ON public.reactions USING btree (is_optout);
1981
1982
1983--
1984-- Name: reactions_mute_index; Type: INDEX; Schema: public; Owner: postgres
1985--
1986
1987CREATE INDEX reactions_mute_index ON public.reactions USING btree (mute);
1988
1989
1990--
1991-- Name: reactions_previous_reaction_index; Type: INDEX; Schema: public; Owner: postgres
1992--
1993
1994CREATE INDEX reactions_previous_reaction_index ON public.reactions USING btree (previous_reaction);
1995
1996
1997--
1998-- Name: reactions_service_id_index; Type: INDEX; Schema: public; Owner: postgres
1999--
2000
2001CREATE INDEX reactions_service_id_index ON public.reactions USING btree (service_id);
2002
2003
2004--
2005-- Name: reactions_targets_index; Type: INDEX; Schema: public; Owner: postgres
2006--
2007
2008CREATE INDEX reactions_targets_index ON public.reactions USING btree (targets);
2009
2010
2011--
2012-- Name: reactions_template_id_index; Type: INDEX; Schema: public; Owner: postgres
2013--
2014
2015CREATE INDEX reactions_template_id_index ON public.reactions USING btree (template_id);
2016
2017
2018--
2019-- Name: rememberables_series_hash_index; Type: INDEX; Schema: public; Owner: postgres
2020--
2021
2022CREATE INDEX rememberables_series_hash_index ON public.rememberables USING btree (series_hash);
2023
2024
2025--
2026-- Name: rememberables_token_hash_index; Type: INDEX; Schema: public; Owner: postgres
2027--
2028
2029CREATE INDEX rememberables_token_hash_index ON public.rememberables USING btree (token_hash);
2030
2031
2032--
2033-- Name: rememberables_user_id_index; Type: INDEX; Schema: public; Owner: postgres
2034--
2035
2036CREATE INDEX rememberables_user_id_index ON public.rememberables USING btree (user_id);
2037
2038
2039--
2040-- Name: rememberables_user_id_series_hash_token_hash_index; Type: INDEX; Schema: public; Owner: postgres
2041--
2042
2043CREATE UNIQUE INDEX rememberables_user_id_series_hash_token_hash_index ON public.rememberables USING btree (user_id, series_hash, token_hash);
2044
2045
2046--
2047-- Name: reports_app_id_index; Type: INDEX; Schema: public; Owner: postgres
2048--
2049
2050CREATE INDEX reports_app_id_index ON public.reports USING btree (app_id);
2051
2052
2053--
2054-- Name: reports_service_id_index; Type: INDEX; Schema: public; Owner: postgres
2055--
2056
2057CREATE INDEX reports_service_id_index ON public.reports USING btree (service_id);
2058
2059
2060--
2061-- Name: reports_user_id_index; Type: INDEX; Schema: public; Owner: postgres
2062--
2063
2064CREATE INDEX reports_user_id_index ON public.reports USING btree (user_id);
2065
2066
2067--
2068-- Name: service_id_charge_amount_irdt_send_on_idx; Type: INDEX; Schema: public; Owner: postgres
2069--
2070
2071CREATE INDEX service_id_charge_amount_irdt_send_on_idx ON public.charges USING btree (service_id, charge_amount, ((public.utc2ir_dt(send_on))::date));
2072
2073
2074--
2075-- Name: service_reports_app_id_index; Type: INDEX; Schema: public; Owner: postgres
2076--
2077
2078CREATE INDEX service_reports_app_id_index ON public.service_reports USING btree (app_id);
2079
2080
2081--
2082-- Name: service_reports_jday_index; Type: INDEX; Schema: public; Owner: postgres
2083--
2084
2085CREATE INDEX service_reports_jday_index ON public.service_reports USING btree (jday);
2086
2087
2088--
2089-- Name: service_reports_service_id_index; Type: INDEX; Schema: public; Owner: postgres
2090--
2091
2092CREATE INDEX service_reports_service_id_index ON public.service_reports USING btree (service_id);
2093
2094
2095--
2096-- Name: services_charge_tpm_index; Type: INDEX; Schema: public; Owner: postgres
2097--
2098
2099CREATE INDEX services_charge_tpm_index ON public.services USING btree (charge_tpm);
2100
2101
2102--
2103-- Name: services_config_id_index; Type: INDEX; Schema: public; Owner: postgres
2104--
2105
2106CREATE INDEX services_config_id_index ON public.services USING btree (config_id);
2107
2108
2109--
2110-- Name: services_gateway_id_index; Type: INDEX; Schema: public; Owner: postgres
2111--
2112
2113CREATE INDEX services_gateway_id_index ON public.services USING btree (gateway_id);
2114
2115
2116--
2117-- Name: services_is_active_index; Type: INDEX; Schema: public; Owner: postgres
2118--
2119
2120CREATE INDEX services_is_active_index ON public.services USING btree (is_active);
2121
2122
2123--
2124-- Name: services_name_gateway_id_index; Type: INDEX; Schema: public; Owner: postgres
2125--
2126
2127CREATE UNIQUE INDEX services_name_gateway_id_index ON public.services USING btree (name, gateway_id);
2128
2129
2130--
2131-- Name: services_name_user_id_index; Type: INDEX; Schema: public; Owner: postgres
2132--
2133
2134CREATE UNIQUE INDEX services_name_user_id_index ON public.services USING btree (name, user_id);
2135
2136
2137--
2138-- Name: services_report_key_index; Type: INDEX; Schema: public; Owner: postgres
2139--
2140
2141CREATE UNIQUE INDEX services_report_key_index ON public.services USING btree (report_key);
2142
2143
2144--
2145-- Name: services_sms_tpm_index; Type: INDEX; Schema: public; Owner: postgres
2146--
2147
2148CREATE INDEX services_sms_tpm_index ON public.services USING btree (sms_tpm);
2149
2150
2151--
2152-- Name: services_template_id_index; Type: INDEX; Schema: public; Owner: postgres
2153--
2154
2155CREATE INDEX services_template_id_index ON public.services USING btree (template_id);
2156
2157
2158--
2159-- Name: services_user_id_index; Type: INDEX; Schema: public; Owner: postgres
2160--
2161
2162CREATE INDEX services_user_id_index ON public.services USING btree (user_id);
2163
2164
2165--
2166-- Name: subscriptions_activated_on_index; Type: INDEX; Schema: public; Owner: postgres
2167--
2168
2169CREATE INDEX subscriptions_activated_on_index ON public.subscriptions USING btree (activated_on);
2170
2171
2172--
2173-- Name: subscriptions_app_id_index; Type: INDEX; Schema: public; Owner: postgres
2174--
2175
2176CREATE INDEX subscriptions_app_id_index ON public.subscriptions USING btree (app_id);
2177
2178
2179--
2180-- Name: subscriptions_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
2181--
2182
2183CREATE INDEX subscriptions_contact_id_index ON public.subscriptions USING btree (contact_id);
2184
2185
2186--
2187-- Name: subscriptions_contacts_contact_id_index; Type: INDEX; Schema: public; Owner: postgres
2188--
2189
2190CREATE INDEX subscriptions_contacts_contact_id_index ON public.subscriptions_contacts USING btree (contact_id);
2191
2192
2193--
2194-- Name: subscriptions_contacts_subscription_id_index; Type: INDEX; Schema: public; Owner: postgres
2195--
2196
2197CREATE INDEX subscriptions_contacts_subscription_id_index ON public.subscriptions_contacts USING btree (subscription_id);
2198
2199
2200--
2201-- Name: subscriptions_deactivated_on_index; Type: INDEX; Schema: public; Owner: postgres
2202--
2203
2204CREATE INDEX subscriptions_deactivated_on_index ON public.subscriptions USING btree (deactivated_on);
2205
2206
2207--
2208-- Name: subscriptions_name_service_id_index; Type: INDEX; Schema: public; Owner: postgres
2209--
2210
2211CREATE UNIQUE INDEX subscriptions_name_service_id_index ON public.subscriptions USING btree (name, service_id);
2212
2213
2214--
2215-- Name: subscriptions_otp_transaction_id_reference_code_index; Type: INDEX; Schema: public; Owner: postgres
2216--
2217
2218CREATE INDEX subscriptions_otp_transaction_id_reference_code_index ON public.subscriptions USING btree (otp_transaction_id, reference_code);
2219
2220
2221--
2222-- Name: subscriptions_service_active_number_idx; Type: INDEX; Schema: public; Owner: postgres
2223--
2224
2225CREATE INDEX subscriptions_service_active_number_idx ON public.subscriptions USING btree (contact_id, is_active, service_id);
2226
2227
2228--
2229-- Name: subscriptions_service_id_index; Type: INDEX; Schema: public; Owner: postgres
2230--
2231
2232CREATE INDEX subscriptions_service_id_index ON public.subscriptions USING btree (service_id);
2233
2234
2235--
2236-- Name: templates_name_index; Type: INDEX; Schema: public; Owner: postgres
2237--
2238
2239CREATE INDEX templates_name_index ON public.templates USING btree (name);
2240
2241
2242--
2243-- Name: templates_section_index; Type: INDEX; Schema: public; Owner: postgres
2244--
2245
2246CREATE INDEX templates_section_index ON public.templates USING btree (section);
2247
2248
2249--
2250-- Name: templates_user_id_index; Type: INDEX; Schema: public; Owner: postgres
2251--
2252
2253CREATE INDEX templates_user_id_index ON public.templates USING btree (user_id);
2254
2255
2256--
2257-- Name: templates_user_id_name_index; Type: INDEX; Schema: public; Owner: postgres
2258--
2259
2260CREATE UNIQUE INDEX templates_user_id_name_index ON public.templates USING btree (user_id, name);
2261
2262
2263--
2264-- Name: users_cell_phone_index; Type: INDEX; Schema: public; Owner: postgres
2265--
2266
2267CREATE UNIQUE INDEX users_cell_phone_index ON public.users USING btree (cell_phone);
2268
2269
2270--
2271-- Name: users_client_key_index; Type: INDEX; Schema: public; Owner: postgres
2272--
2273
2274CREATE UNIQUE INDEX users_client_key_index ON public.users USING btree (client_key);
2275
2276
2277--
2278-- Name: users_email_index; Type: INDEX; Schema: public; Owner: postgres
2279--
2280
2281CREATE UNIQUE INDEX users_email_index ON public.users USING btree (email);
2282
2283
2284--
2285-- Name: users_is_active_index; Type: INDEX; Schema: public; Owner: postgres
2286--
2287
2288CREATE INDEX users_is_active_index ON public.users USING btree (is_active);
2289
2290
2291--
2292-- Name: users_is_admin_index; Type: INDEX; Schema: public; Owner: postgres
2293--
2294
2295CREATE INDEX users_is_admin_index ON public.users USING btree (is_admin);
2296
2297
2298--
2299-- Name: users_report_key_index; Type: INDEX; Schema: public; Owner: postgres
2300--
2301
2302CREATE UNIQUE INDEX users_report_key_index ON public.users USING btree (report_key);
2303
2304
2305--
2306-- Name: apikeys apikeys_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2307--
2308
2309ALTER TABLE ONLY public.apikeys
2310 ADD CONSTRAINT apikeys_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2311
2312
2313--
2314-- Name: apps apps_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2315--
2316
2317ALTER TABLE ONLY public.apps
2318 ADD CONSTRAINT apps_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2319
2320
2321--
2322-- Name: apps apps_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2323--
2324
2325ALTER TABLE ONLY public.apps
2326 ADD CONSTRAINT apps_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
2327
2328
2329--
2330-- Name: bulks_contacts bulks_contacts_bulk_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2331--
2332
2333ALTER TABLE ONLY public.bulks_contacts
2334 ADD CONSTRAINT bulks_contacts_bulk_id_fkey FOREIGN KEY (bulk_id) REFERENCES public.bulks(id);
2335
2336
2337--
2338-- Name: bulks_contacts bulks_contacts_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2339--
2340
2341ALTER TABLE ONLY public.bulks_contacts
2342 ADD CONSTRAINT bulks_contacts_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2343
2344
2345--
2346-- Name: bulks bulks_expected_reaction_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2347--
2348
2349ALTER TABLE ONLY public.bulks
2350 ADD CONSTRAINT bulks_expected_reaction_id_fkey FOREIGN KEY (expected_reaction_id) REFERENCES public.reactions(id);
2351
2352
2353--
2354-- Name: bulks bulks_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2355--
2356
2357ALTER TABLE ONLY public.bulks
2358 ADD CONSTRAINT bulks_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2359
2360
2361--
2362-- Name: campaigns campaigns_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2363--
2364
2365ALTER TABLE ONLY public.campaigns
2366 ADD CONSTRAINT campaigns_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2367
2368
2369--
2370-- Name: campaigns campaigns_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2371--
2372
2373ALTER TABLE ONLY public.campaigns
2374 ADD CONSTRAINT campaigns_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2375
2376
2377--
2378-- Name: charges charges_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2379--
2380
2381ALTER TABLE ONLY public.charges
2382 ADD CONSTRAINT charges_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2383
2384
2385--
2386-- Name: charges charges_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2387--
2388
2389ALTER TABLE ONLY public.charges
2390 ADD CONSTRAINT charges_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2391
2392
2393--
2394-- Name: charges charges_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2395--
2396
2397ALTER TABLE ONLY public.charges
2398 ADD CONSTRAINT charges_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2399
2400
2401--
2402-- Name: contacts contacts_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2403--
2404
2405ALTER TABLE ONLY public.contacts
2406 ADD CONSTRAINT contacts_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2407
2408
2409--
2410-- Name: contacts contacts_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2411--
2412
2413ALTER TABLE ONLY public.contacts
2414 ADD CONSTRAINT contacts_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2415
2416
2417--
2418-- Name: contacts_services contacts_services_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2419--
2420
2421ALTER TABLE ONLY public.contacts_services
2422 ADD CONSTRAINT contacts_services_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2423
2424
2425--
2426-- Name: contacts_services contacts_services_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2427--
2428
2429ALTER TABLE ONLY public.contacts_services
2430 ADD CONSTRAINT contacts_services_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2431
2432
2433--
2434-- Name: contacts contacts_subscription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2435--
2436
2437ALTER TABLE ONLY public.contacts
2438 ADD CONSTRAINT contacts_subscription_id_fkey FOREIGN KEY (subscription_id) REFERENCES public.subscriptions(id);
2439
2440
2441--
2442-- Name: gateways gateways_config_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2443--
2444
2445ALTER TABLE ONLY public.gateways
2446 ADD CONSTRAINT gateways_config_id_fkey FOREIGN KEY (config_id) REFERENCES public.configs(id);
2447
2448
2449--
2450-- Name: gateways gateways_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2451--
2452
2453ALTER TABLE ONLY public.gateways
2454 ADD CONSTRAINT gateways_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
2455
2456
2457--
2458-- Name: logs logs_gateway_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2459--
2460
2461ALTER TABLE ONLY public.logs
2462 ADD CONSTRAINT logs_gateway_id_fkey FOREIGN KEY (gateway_id) REFERENCES public.gateways(id);
2463
2464
2465--
2466-- Name: logs logs_reaction_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2467--
2468
2469ALTER TABLE ONLY public.logs
2470 ADD CONSTRAINT logs_reaction_id_fkey FOREIGN KEY (reaction_id) REFERENCES public.reactions(id);
2471
2472
2473--
2474-- Name: logs logs_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2475--
2476
2477ALTER TABLE ONLY public.logs
2478 ADD CONSTRAINT logs_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2479
2480
2481--
2482-- Name: logs logs_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2483--
2484
2485ALTER TABLE ONLY public.logs
2486 ADD CONSTRAINT logs_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
2487
2488
2489--
2490-- Name: messages messages_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2491--
2492
2493ALTER TABLE ONLY public.messages
2494 ADD CONSTRAINT messages_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2495
2496
2497--
2498-- Name: messages messages_bulk_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2499--
2500
2501ALTER TABLE ONLY public.messages
2502 ADD CONSTRAINT messages_bulk_id_fkey FOREIGN KEY (bulk_id) REFERENCES public.bulks(id);
2503
2504
2505--
2506-- Name: messages messages_campaign_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2507--
2508
2509ALTER TABLE ONLY public.messages
2510 ADD CONSTRAINT messages_campaign_id_fkey FOREIGN KEY (campaign_id) REFERENCES public.campaigns(id);
2511
2512
2513--
2514-- Name: messages messages_charge_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2515--
2516
2517ALTER TABLE ONLY public.messages
2518 ADD CONSTRAINT messages_charge_id_fkey FOREIGN KEY (charge_id) REFERENCES public.charges(id);
2519
2520
2521--
2522-- Name: messages messages_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2523--
2524
2525ALTER TABLE ONLY public.messages
2526 ADD CONSTRAINT messages_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2527
2528
2529--
2530-- Name: messages messages_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2531--
2532
2533ALTER TABLE ONLY public.messages
2534 ADD CONSTRAINT messages_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2535
2536
2537--
2538-- Name: messages messages_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2539--
2540
2541ALTER TABLE ONLY public.messages
2542 ADD CONSTRAINT messages_template_id_fkey FOREIGN KEY (template_id) REFERENCES public.templates(id);
2543
2544
2545--
2546-- Name: profiles profiles_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2547--
2548
2549ALTER TABLE ONLY public.profiles
2550 ADD CONSTRAINT profiles_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2551
2552
2553--
2554-- Name: reactions reactions_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2555--
2556
2557ALTER TABLE ONLY public.reactions
2558 ADD CONSTRAINT reactions_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2559
2560
2561--
2562-- Name: reactions reactions_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2563--
2564
2565ALTER TABLE ONLY public.reactions
2566 ADD CONSTRAINT reactions_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2567
2568
2569--
2570-- Name: reactions reactions_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2571--
2572
2573ALTER TABLE ONLY public.reactions
2574 ADD CONSTRAINT reactions_template_id_fkey FOREIGN KEY (template_id) REFERENCES public.templates(id);
2575
2576
2577--
2578-- Name: rememberables rememberables_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2579--
2580
2581ALTER TABLE ONLY public.rememberables
2582 ADD CONSTRAINT rememberables_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
2583
2584
2585--
2586-- Name: reports reports_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2587--
2588
2589ALTER TABLE ONLY public.reports
2590 ADD CONSTRAINT reports_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2591
2592
2593--
2594-- Name: reports reports_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2595--
2596
2597ALTER TABLE ONLY public.reports
2598 ADD CONSTRAINT reports_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2599
2600
2601--
2602-- Name: reports reports_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2603--
2604
2605ALTER TABLE ONLY public.reports
2606 ADD CONSTRAINT reports_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
2607
2608
2609--
2610-- Name: service_reports service_reports_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2611--
2612
2613ALTER TABLE ONLY public.service_reports
2614 ADD CONSTRAINT service_reports_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.apps(id);
2615
2616
2617--
2618-- Name: service_reports service_reports_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2619--
2620
2621ALTER TABLE ONLY public.service_reports
2622 ADD CONSTRAINT service_reports_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2623
2624
2625--
2626-- Name: services services_config_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2627--
2628
2629ALTER TABLE ONLY public.services
2630 ADD CONSTRAINT services_config_id_fkey FOREIGN KEY (config_id) REFERENCES public.configs(id);
2631
2632
2633--
2634-- Name: services services_gateway_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2635--
2636
2637ALTER TABLE ONLY public.services
2638 ADD CONSTRAINT services_gateway_id_fkey FOREIGN KEY (gateway_id) REFERENCES public.gateways(id);
2639
2640
2641--
2642-- Name: services services_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2643--
2644
2645ALTER TABLE ONLY public.services
2646 ADD CONSTRAINT services_template_id_fkey FOREIGN KEY (template_id) REFERENCES public.templates(id);
2647
2648
2649--
2650-- Name: services services_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2651--
2652
2653ALTER TABLE ONLY public.services
2654 ADD CONSTRAINT services_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
2655
2656
2657--
2658-- Name: subscriptions subscriptions_app_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2659--
2660
2661ALTER TABLE ONLY public.subscriptions
2662 ADD CONSTRAINT subscriptions_app_id_fkey FOREIGN KEY (app_id) REFERENCES public.services(id);
2663
2664
2665--
2666-- Name: subscriptions subscriptions_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2667--
2668
2669ALTER TABLE ONLY public.subscriptions
2670 ADD CONSTRAINT subscriptions_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2671
2672
2673--
2674-- Name: subscriptions_contacts subscriptions_contacts_contact_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2675--
2676
2677ALTER TABLE ONLY public.subscriptions_contacts
2678 ADD CONSTRAINT subscriptions_contacts_contact_id_fkey FOREIGN KEY (contact_id) REFERENCES public.contacts(id);
2679
2680
2681--
2682-- Name: subscriptions_contacts subscriptions_contacts_subscription_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2683--
2684
2685ALTER TABLE ONLY public.subscriptions_contacts
2686 ADD CONSTRAINT subscriptions_contacts_subscription_id_fkey FOREIGN KEY (subscription_id) REFERENCES public.subscriptions(id);
2687
2688
2689--
2690-- Name: subscriptions subscriptions_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2691--
2692
2693ALTER TABLE ONLY public.subscriptions
2694 ADD CONSTRAINT subscriptions_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id);
2695
2696
2697--
2698-- Name: templates templates_service_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2699--
2700
2701ALTER TABLE ONLY public.templates
2702 ADD CONSTRAINT templates_service_id_fkey FOREIGN KEY (service_id) REFERENCES public.services(id) ON DELETE CASCADE;
2703
2704
2705--
2706-- Name: templates templates_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2707--
2708
2709ALTER TABLE ONLY public.templates
2710 ADD CONSTRAINT templates_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);
2711
2712
2713--
2714-- Name: TABLE apikeys; Type: ACL; Schema: public; Owner: postgres
2715--
2716
2717
2718--
2719-- PostgreSQL database dump complete
2720--