<commit_before>"""Database provisioning."""
import os
import psycopg2
import urlparse


def setup(cursor):
    """Bootstrap the database on import.

    Assumes no existing database.
    """
    print 'Setting up hstore'
    cursor.execute("""CREATE EXTENSION hstore;""")

    print 'Creating "stored" table.'
    cursor.execute("""
        CREATE TABLE stored
            (domain varchar PRIMARY KEY, result hstore);
    """)

    # Subscriptions
    print 'Creating "subscriptions" table.'
    cursor.execute("""
        CREATE TABLE subscriptions
            (auth_hash bytea PRIMARY KEY, domain varchar, expires timestamp);
    """)


def migrate(conn_new, conn_old):
    """This is where I'd load in the previous database's data.
    """
    pass


if __name__ == '__main__':

    urlparse.uses_netloc.append("postgres")
    new_url = urlparse.urlparse(os.environ["DATABASE_URL"])

    new_conn = psycopg2.connect(
        database=new_url.path[1:],
        user=new_url.username,
        password=new_url.password,
        host=new_url.hostname,
        port=new_url.port
    )

    new_cursor = new_conn.cursor()

    setup(new_cursor)

    new_conn.commit()
    new_cursor.close()
    new_conn.close()
<commit_msg>Made the provision command take an explicity path for the database<commit_after>"""Database provisioning."""
import psycopg2
import sys
import urlparse


def setup(cursor):
    """Bootstrap the database on import.

    Assumes no existing database.
    """
    print 'Setting up hstore'
    cursor.execute("""CREATE EXTENSION hstore;""")

    print 'Creating "stored" table.'
    cursor.execute("""
        CREATE TABLE stored
            (domain varchar PRIMARY KEY, result hstore, updated timestamp);
    """)

    # Subscriptions
    print 'Creating "subscriptions" table.'
    cursor.execute("""
        CREATE TABLE subscriptions
            (auth_hash bytea PRIMARY KEY, domain varchar, expires timestamp);
    """)


def migrate(conn_new, conn_old):
    """This is where I'd load in the previous database's data.
    """
    pass


if __name__ == '__main__':

    db_url = sys.argv[-1]
    if not db_url.startswith('postgres'):
        raise Exception('Missing database url')

    urlparse.uses_netloc.append("postgres")
    new_url = urlparse.urlparse(db_url)

    new_conn = psycopg2.connect(
        database=new_url.path[1:],
        user=new_url.username,
        password=<PASSWORD>,
        host=new_url.hostname,
        port=new_url.port
    )

    new_cursor = new_conn.cursor()

    setup(new_cursor)

    new_conn.commit()
    new_cursor.close()
    new_conn.close()

{'fraction_non_alphanumeric': 0.11196319018404909, 'fraction_numerical': 0.0026840490797546013, 'mean_word_length': 2.911544227886057, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '771919', 'n_tokens_mistral': 831, 'n_tokens_neox': 781, 'n_words': 201}