import psycopg2

from park_api import env

def main():
    with psycopg2.connect(**env.DATABASE) as conn:
        cursor = conn.cursor()
        cursor.execute('CREATE TABLE "public"."parkapi" ('
                       '"id" SERIAL,'
                       '"timestamp_updated" TIMESTAMP NOT NULL,'
                       '"timestamp_downloaded" TIMESTAMP NOT NULL,'
                       '"city" TEXT NOT NULL,"data" JSON NOT NULL,'
                       'PRIMARY KEY ("id"))'
                       'TABLESPACE "pg_default";')
        conn.commit()

if __name__ == "__main__":
    main()

@@ -522,16 +522,120 @@
 fault%22;'
+%0A                       'create index latest_scrape_index on parkapi (city, timestamp_downloaded DESC);'
 )%0A      

add index for sorting to parkapi table