Skip to content

Commit

Permalink
make staging schema name passable
Browse files Browse the repository at this point in the history
  • Loading branch information
OpsWorks user bkuester committed Mar 31, 2017
1 parent 7699374 commit 1211a45
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions schemas/populate_tables/lookup/populate_lookup_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import psycopg2
import sqlalchemy

# TODO: put schema in the yaml file
SCHEMA_NAME = 'staging'

parser = argparse.ArgumentParser()
parser.add_argument("-c", "--credentials", help="the credential file")
parser.add_argument("-t", "--tablefile", help="the yaml table definition file")
parser.add_argument("-s", "--schema", help="name of the staging schema", default="staging")
args = parser.parse_args()

# read the credentials file
Expand All @@ -36,9 +34,9 @@
for table_name, contents in table_dict.items():

# remove all rows from the table, if any are already present
sql_query = """DELETE FROM {}.{}""".format(SCHEMA_NAME, table_name)
sql_query = """DELETE FROM {}.{}""".format(args.schema, table_name)
db_conn.execute(sql_query)

table_df = pd.DataFrame(contents['rows'], columns=contents['columns'])
table_df.to_sql(table_name, db_conn, index=False, schema=SCHEMA_NAME, if_exists='append')
table_df.to_sql(table_name, db_conn, index=False, schema=args.schema, if_exists='append')
print('done with {}'.format(table_name))

0 comments on commit 1211a45

Please sign in to comment.