CREATE TABLE public.partitioned_purchases (
id bigint NOT NULL,
project character varying NOT NULL,
title character varying NOT NULL,
purchased_at timestamp without time zone NOT NULL,
quantity integer NOT NULL,
price double precision NOT NULL,
sum double precision NOT NULL,
auto_category character varying,
manual_category character varying,
link_item_id character varying,
item_id character varying,
age integer,
city character varying,
shop character varying,
address character varying,
user_id character varying,
user_date_of_birth date,
user_gender character varying,
user_phone character varying,
user_email character varying,
user_city character varying,
user_vk_uid character varying,
user_ok_uid character varying,
user_fb_uid character varying,
receipt_id character varying NOT NULL,
receipt_total double precision NOT NULL,
receipt_fn character varying NOT NULL,
receipt_fd character varying NOT NULL,
receipt_fpd character varying NOT NULL,
receipt_inn character varying,
receipt_qr_string character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
promotion_title character varying,
receipt_created_at timestamp without time zone,
cashback_currency public.citext,
cashback_value integer
) PARTITION BY RANGE (receipt_created_at);
-- CREATE TABLE partitioned_purchases_y2022m03 PARTITION OF partitioned_purchases
-- FOR VALUES FROM ('2022-03-01') TO ('2022-04-01');
-- CREATE TABLE partitioned_purchases_y2022m04 PARTITION OF partitioned_purchases
-- FOR VALUES FROM ('2022-04-01') TO ('2022-05-01');
CREATE SEQUENCE public.partitioned_purchases_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE public.partitioned_purchases_id_seq OWNED BY public.partitioned_purchases.id;
ALTER TABLE public.partitioned_purchases ADD CONSTRAINT partitioned_purchases_pkey PRIMARY KEY (id, receipt_created_at);
ALTER TABLE ONLY public.partitioned_purchases ALTER COLUMN id SET DEFAULT nextval('public.partitioned_purchases_id_seq'::regclass);
CREATE INDEX index_partitioned_purchases_on_receipt_created_at ON public.partitioned_purchases USING btree (receipt_created_at);
CREATE INDEX index_partitioned_purchases_on_created_at ON public.partitioned_purchases USING btree (created_at);
CREATE INDEX index_partitioned_purchases_on_link_item_id ON public.partitioned_purchases USING btree (link_item_id);
CREATE INDEX index_partitioned_purchases_on_manual_category ON public.partitioned_purchases USING btree (manual_category);
CREATE INDEX index_partitioned_purchases_on_manual_category_and_receipt_id ON public.partitioned_purchases USING btree (manual_category, receipt_id);
CREATE INDEX index_partitioned_purchases_on_project ON public.partitioned_purchases USING btree (project);
CREATE UNIQUE INDEX index_partitioned_purchases_on_project_and_link_item_id ON public.partitioned_purchases USING btree (project, link_item_id, receipt_created_at);
CREATE INDEX index_partitioned_purchases_on_receipt_id ON public.partitioned_purchases USING btree (receipt_id);
CREATE INDEX index_partitioned_purchases_on_updated_at ON public.partitioned_purchases USING btree (updated_at);