import pandas as pd
import util


def run(cfg: dict) -> None:
    """ loads the merged raw file into the database """
    # open a connection
    engine = util.sqlalchemy_connection()

    # get config parameters
    directory = '{0}/{1}'.format(cfg['FILES']['cwd'],
                                 cfg['DATA_INPUT']['outputfiledirectory'])
    filename = cfg['DATA_INPUT']['outputfilename']

    # read in the raw file
    raw_data = pd.DataFrame()

    raw_data = pd.read_csv('{0}/{1}'.format(directory, filename))

    # export file to DB
    raw_data.to_sql('merged', engine, if_exists='replace',
                    index=False, chunksize=50000)

    # add an integer primary key to the merged table
    util.exec_query(cfg['UPDATES']['add_pk'])
