<commit_before>import os
import sys

from sqlalchemy import engine_from_config, text

from pyramid.paster import (
    get_appsettings,
    setup_logging,
)

from pyramid.scripts.common import parse_vars

from gitbyatruck.models import (
    DBSession,
    Base,
)


def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> [var=value]\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)


def main(argv=None):
    if argv is None:
        argv = sys.argv

    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(engine)

    # load procedures
    for path, _, files in os.walk(
        os.path.join(
            os.path.split(__file__)[0],
            '..',
            'backend',
            'procedures'
        )
    ):
        for f in files:
            with open(os.path.join(path, f), 'r') as p:
                procedure = text(p.read())
                engine.execute(procedure)<commit_msg>order matters for loading procedures, use a list<commit_after>import os
import sys

from sqlalchemy import engine_from_config, text

from pyramid.paster import (
    get_appsettings,
    setup_logging,
)

from pyramid.scripts.common import parse_vars

from gitbyatruck.models import (
    DBSession,
    Base,
)


def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> [var=value]\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)


def main(argv=None):
    if argv is None:
        argv = sys.argv

    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    options = parse_vars(argv[2:])
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(engine)

    # load procedures
    prefix = os.path.join(
        os.path.split(__file__)[0],
        '..',
        'backend',
        'procedures'
    )
    files = ['churn_knowledge.sql', 'calculate_knowledge.sql']
    for f in files:
        with open(os.path.join(prefix, f), 'r') as p:
            procedure = text(p.read())
            engine.execute(procedure)
{'fraction_non_alphanumeric': 0.1222879684418146, 'fraction_numerical': 0.004733727810650888, 'mean_word_length': 2.6753623188405795, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1193920', 'n_tokens_mistral': 856, 'n_tokens_neox': 826, 'n_words': 179}