import sys

class PositionsRecord:
    def __init__(self, position_id, name):
        self.position_id = position_id
        self.name = name

f = open(sys.argv[1], mode="r")

dump_file = open(sys.argv[2], mode="w")

rows = f.read().split("\n")

dump_file.write("""
CREATE TABLE IF NOT EXISTS evi."position"
(
    position_id text COLLATE pg_catalog."default" NOT NULL,
    name text COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT position_pkey PRIMARY KEY (position_id),
    CONSTRAINT position_unique_name_cnt UNIQUE (name)
);
\n""")

for row in rows:
    if len(row) == 0:
        continue

    cols = row.split(",")
    record = PositionsRecord(cols[0], cols[1])

    dump_file.write(f"""INSERT INTO evi."position" (position_id, name)
                    VALUES ('{record.position_id}', '{record.name}');\n""")
