· 8 years ago · Mar 07, 2018, 04:02 PM
1DROP TABLE IF EXISTS payment_transaction;
2 DROP TABLE IF EXISTS hull_list, hull_list_user;
3 DROP TABLE IF EXISTS gift_card, discount, gift_card_tag, discount_tag;
4 DROP TABLE IF EXISTS frichticustomer;
5 CREATE TABLE gift_card_tag (
6 id serial NOT NULL,
7 name character varying(32) NOT NULL,
8 created_at timestamp with time zone NOT NULL,
9 updated_at timestamp with time zone NOT NULL,
10 CONSTRAINT gift_card_tag_pkey PRIMARY KEY (id)
11 );
12 CREATE UNIQUE INDEX gift_card_tag_name_idx ON gift_card_tag USING btree (name);
13 CREATE TABLE discount_tag (
14 id serial NOT NULL,
15 name character varying(32) NOT NULL,
16 created_at timestamp with time zone NOT NULL,
17 updated_at timestamp with time zone NOT NULL,
18 CONSTRAINT discount_tag_pkey PRIMARY KEY (id)
19 );
20 CREATE UNIQUE INDEX discount_tag_name_idx ON discount_tag USING btree (name);
21 CREATE TABLE gift_card (
22 id serial NOT NULL,
23 shopify_id bigint,
24 code text NOT NULL,
25 customer_id integer,
26 balance numeric NOT NULL,
27 initial_value numeric NOT NULL,
28 note text,
29 expires_on timestamp with time zone,
30 created_at timestamp with time zone NOT NULL,
31 updated_at timestamp with time zone NOT NULL,
32 enabled boolean DEFAULT true,
33 free boolean DEFAULT true,
34 per_use_value numeric,
35 once_per_day_per_user boolean DEFAULT false,
36 tag_id integer NOT NULL REFERENCES "gift_card_tag" ("id"),
37 CONSTRAINT gift_card_pkey PRIMARY KEY (id)
38 );
39 CREATE UNIQUE INDEX gift_card_code_idx ON gift_card USING btree (code);
40 CREATE TABLE discount (
41 id serial NOT NULL,
42 shopify_id bigint,
43 code text,
44 value numeric,
45 starts_at timestamp with time zone,
46 ends_at timestamp with time zone,
47 status text,
48 minimum_order_amount numeric,
49 usage_limit integer,
50 applies_once boolean,
51 limit_per_customer integer,
52 type text,
53 times_used integer,
54 created_at timestamp with time zone,
55 updated_at timestamp with time zone,
56 times_used_shopify integer,
57 applies_to_list_id bigint,
58 applies_to_variant_id bigint,
59 applies_to_product_id bigint,
60 applies_to_hull_list_id integer,
61 applies_to_customer_id bigint,
62 tag_id integer NOT NULL REFERENCES "discount_tag" ("id")
63 );
64 CREATE UNIQUE INDEX discount_code_idx ON discount USING btree (code);
65 CREATE TABLE frichticustomer (
66 shopify_id character varying(64),
67 stripe_id character varying(64),
68 first_name character varying(64),
69 last_name character varying(64),
70 referrer_id character varying(64),
71 referral_code character varying(32),
72 assigned_kitchen character varying(64),
73 default_payment_method_id character varying(32),
74 realm text,
75 username text,
76 password text,
77 cresentials text,
78 challenges text,
79 email text NOT NULL,
80 emailverified boolean,
81 verificationtoken text,
82 status text,
83 created timestamp with time zone,
84 lastupdated timestamp with time zone,
85 id serial NOT NULL,
86 createdat timestamp with time zone NOT NULL,
87 updatedat timestamp with time zone NOT NULL,
88 phone character varying(20),
89 ios_pn_token character varying(64),
90 CONSTRAINT frichticustomer_pkey PRIMARY KEY (id)
91 );
92 CREATE TABLE hull_list (
93 id SERIAL UNIQUE PRIMARY KEY,
94 name VARCHAR(255) NOT NULL,
95 external_id VARCHAR(255) NOT NULL UNIQUE, -- hull list id
96 created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
97 updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
98 );
99 CREATE TABLE hull_list_user (
100 external_id VARCHAR(255) REFERENCES hull_list (external_id),
101 customer_id INTEGER REFERENCES frichticustomer (id)
102 );
103 CREATE TABLE payment_transaction (
104 id serial NOT NULL,
105 checkout_id integer,
106 customer_id integer,
107 payment_method_id integer,
108 payment_method_type character varying(255),
109 amount integer,
110 kind character varying(255),
111 "authorization" character varying(255),
112 status character varying(255),
113 error character varying(255),
114 currency character varying(255),
115 created_at timestamp with time zone NOT NULL,
116 updated_at timestamp with time zone NOT NULL
117 );