-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
119 lines (83 loc) · 3.49 KB
/
db.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
--
-- Name: plans; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.plans (
id integer NOT NULL,
plan_name character varying(255),
plan_amount integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: plans_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.plans ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.plans_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: user_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.user_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: user_plans; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.user_plans (
id integer NOT NULL,
user_id integer,
plan_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: user_plans_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.user_plans ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.user_plans_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
CREATE TABLE public.users (
id integer DEFAULT nextval('public.user_id_seq'::regclass) NOT NULL,
email character varying(255),
first_name character varying(255),
last_name character varying(255),
password character varying(60),
user_active integer DEFAULT 0,
is_admin integer default 0,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
INSERT INTO "public"."users"("email","first_name","last_name","password","user_active", "is_admin", "created_at","updated_at")
VALUES
(E'[email protected]',E'Admin',E'User',E'$2a$12$1zGLuYDDNvATh4RA4avbKuheAMpb1svexSzrQm7up.bnpwQHs0jNe',1,1,E'2022-03-14 00:00:00',E'2022-03-14 00:00:00');
SELECT pg_catalog.setval('public.plans_id_seq', 1, false);
SELECT pg_catalog.setval('public.user_id_seq', 2, true);
SELECT pg_catalog.setval('public.user_plans_id_seq', 1, false);
INSERT INTO "public"."plans"("plan_name","plan_amount","created_at","updated_at")
VALUES
(E'Bronze Plan',1000,E'2022-05-12 00:00:00',E'2022-05-12 00:00:00'),
(E'Silver Plan',2000,E'2022-05-12 00:00:00',E'2022-05-12 00:00:00'),
(E'Gold Plan',3000,E'2022-05-12 00:00:00',E'2022-05-12 00:00:00');
ALTER TABLE ONLY public.plans
ADD CONSTRAINT plans_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.user_plans
ADD CONSTRAINT user_plans_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.user_plans
ADD CONSTRAINT user_plans_plan_id_fkey FOREIGN KEY (plan_id) REFERENCES public.plans(id) ON UPDATE RESTRICT ON DELETE CASCADE;
ALTER TABLE ONLY public.user_plans
ADD CONSTRAINT user_plans_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON UPDATE RESTRICT ON DELETE CASCADE;