#!/usr/bin/python3

import random
import datetime

secs_in_day = 24*60*60

longstr = """iufdpoaiusoto3u5034534i5j345k345lku09s80s9dfjwer.,newrwwerwerwerlwerjlwejrlkewjr""" * 10

print("""

drop table if exists test_orders;
drop sequence if exists test_orders_id_seq;

CREATE SEQUENCE test_orders_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;

CREATE TABLE test_orders (
    id integer DEFAULT nextval('test_orders_id_seq'::regclass) NOT NULL,
    o_date timestamp with time zone NOT NULL,
    customer_id integer,
    str1 text,
    num1 integer,
    long1 text,
    long2 text,
    long3 text,
    long4 text
);

COPY test_orders(o_date, customer_id, str1, num1, long1, long2, long3, long4) FROM stdin;""")

for day in range(5000):
    orders = [(secs_in_day * day + random.randrange(secs_in_day), customer) for customer in range(day, day+1000)]
    for o_date, customer_id in sorted(orders):
        print(datetime.datetime.fromtimestamp(1234234234 + o_date).isoformat(),
            customer_id,
            "blah",
            random.randrange(1000000),
            longstr,
            longstr,
            longstr,
            longstr,
        sep="\t")

print("""\\.

create index test_orders_o_date_idx on test_orders using btree(o_date);
create index test_orders_customer_id_o_date_idx on test_orders using btree(customer_id, o_date);

analyze test_orders;
""")
