ENH: modifying seed.sql generation script so filename matches the

model.json
This commit is contained in:
zainakh committed 2020-03-06 10:55:44 -06:00
1 parent ff89e49558
commit 2ecbff1def
2 files changed
+13 -13

No files matched your search

@@ -8,13 +8,12 @@ from fmp import FMP
db_json = dict()
fmp_model = FMP()
CURR_DAY = datetime.now().strftime("%Y%m%d_%H%M")
# 1st (sql file)
# 2nd (write to sql connection)
def write_command(string):
with open("./init/{curr_day}_init_db.sql".format(curr_day=CURR_DAY), "w") as f:
def write_command(string, date_time):
with open("./init/{date_time}_init_db.sql".format(date_time=date_time), "w") as f:
f.write(string)
@@ -33,7 +32,8 @@ def main(argv):
with open(model_file, "r") as f:
data_model = json.load(f)
schema = "chi_{day}".format(day=CURR_DAY)
date_time = '_'.join(os.path.split(os.path.abspath(model_file))[-1].split('_')[:2])
schema = "chi_{date_time}".format(date_time=date_time)
command = "create schema {schema};\n".format(schema=schema)
for table_name, attribute_dict in data_model.items():
command += "create table {schema}.{table_name} (\n".format(
@@ -65,7 +65,7 @@ def main(argv):
command += ");\n\n"
write_command(command)
write_command(command, date_time)
if __name__ == "__main__":
@@ -1,5 +1,5 @@
create schema chi_20200306_1047;
create table chi_20200306_1047.clinics (
create schema chi_20200305_2357;
create table chi_20200305_2357.clinics (
pk_clinic_id FLOAT primary key,
clinic_name VARCHAR ,
creation_date TIMESTAMP ,
@@ -8,7 +8,7 @@ create table chi_20200306_1047.clinics (
modified_acct VARCHAR
);
create table chi_20200306_1047.patients (
create table chi_20200305_2357.patients (
pk_patient_id FLOAT primary key,
creation_date TIMESTAMP ,
creation_acct VARCHAR ,
@@ -29,7 +29,7 @@ create table chi_20200306_1047.patients (
fk_geonameid VARCHAR
);
create table chi_20200306_1047.visits (
create table chi_20200305_2357.visits (
pk_visit_id FLOAT primary key,
creation_date TIMESTAMP ,
creation_acct VARCHAR ,
@@ -235,7 +235,7 @@ create table chi_20200306_1047.visits (
notes_modification_status VARCHAR
);
create table chi_20200306_1047.diagnoses (
create table chi_20200305_2357.diagnoses (
pk_diagnosis_id FLOAT primary key,
diagnosis_name VARCHAR ,
pk_diagnosis_key VARCHAR primary key,
@@ -245,7 +245,7 @@ create table chi_20200306_1047.diagnoses (
modified_acct VARCHAR
);
create table chi_20200306_1047.diagnoses_made (
create table chi_20200305_2357.diagnoses_made (
pk_diagnoses_made FLOAT primary key,
fk_visit_id FLOAT ,
fk_diagnosis_key VARCHAR ,
@@ -255,7 +255,7 @@ create table chi_20200306_1047.diagnoses_made (
modified_acct VARCHAR
);
create table chi_20200306_1047.meds (
create table chi_20200305_2357.meds (
pk_med_id FLOAT primary key,
med_name VARCHAR ,
creation_date TIMESTAMP ,
@@ -266,7 +266,7 @@ create table chi_20200306_1047.meds (
med_type VARCHAR
);
create table chi_20200306_1047.meds_dispensed (
create table chi_20200305_2357.meds_dispensed (
pk_meds_dispensed FLOAT primary key,
fk_visit_id FLOAT ,
fk_med_key VARCHAR ,