<commit_before>import subprocess
from contextlib import contextmanager

from sqlalchemy import create_engine
from sqlalchemy.engine.base import Engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session

from plenario.settings import DATABASE_CONN, REDSHIFT_CONN


postgres_engine = create_engine(DATABASE_CONN)
postgres_session = scoped_session(sessionmaker(bind=postgres_engine))
postgres_base = declarative_base(bind=postgres_engine)
postgres_base.query = postgres_session.query_property()

redshift_engine = create_engine(REDSHIFT_CONN)
redshift_session = scoped_session(sessionmaker(bind=redshift_engine))
redshift_base = declarative_base(bind=redshift_engine)
redshift_base.query = redshift_session.query_property()


def create_database(bind: Engine, database: str) -> None:
    """Setup a database (schema) in postgresql."""

    print('[plenario] Create database %s' % database)
    connection = bind.connect()
    connection.execute("commit")
    connection.execute("create database %s" % database)
    connection.close()


def create_extension(bind: Engine, extension: str) -> None:
    """Setup an extension in postgresql."""

    print('[plenario] Create extension %s' % extension)
    connection = bind.connect()
    connection.execute("create extension %s" % extension)<commit_msg>Re-enable autocommit on the redshift session<commit_after>import subprocess
from contextlib import contextmanager

from sqlalchemy import create_engine
from sqlalchemy.engine.base import Engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session

from plenario.settings import DATABASE_CONN, REDSHIFT_CONN


postgres_engine = create_engine(DATABASE_CONN)
postgres_session = scoped_session(sessionmaker(bind=postgres_engine))
postgres_base = declarative_base(bind=postgres_engine)
postgres_base.query = postgres_session.query_property()

redshift_engine = create_engine(REDSHIFT_CONN)
redshift_session = scoped_session(sessionmaker(bind=redshift_engine, autocommit=True))
redshift_base = declarative_base(bind=redshift_engine)
redshift_base.query = redshift_session.query_property()


def create_database(bind: Engine, database: str) -> None:
    """Setup a database (schema) in postgresql."""

    print('[plenario] Create database %s' % database)
    connection = bind.connect()
    connection.execute("commit")
    connection.execute("create database %s" % database)
    connection.close()


def create_extension(bind: Engine, extension: str) -> None:
    """Setup an extension in postgresql."""

    print('[plenario] Create extension %s' % extension)
    connection = bind.connect()
    connection.execute("create extension %s" % extension)
{'fraction_non_alphanumeric': 0.09166666666666666, 'fraction_numerical': 0.0, 'mean_word_length': 6.62707182320442, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1264430', 'n_tokens_mistral': 815, 'n_tokens_neox': 788, 'n_words': 187}