Skip to content

Commit

Permalink
added survey id changing for updated surveys (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
saravanpa-aot authored Nov 9, 2023
1 parent f60be68 commit 4b52aa1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion met-etl/src/etl_project/services/ops/survey_etl_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def load_survey(context, new_survey, updated_survey, survey_new_runcycleid):

_do_etl_survey_data(session, survey, survey_new_runcycleid)

_update_survey_responses_with_active_survey_id(session, survey)

if survey.form_json is None:
context.log.info('Survey Found without form_json: %s. Skipping it', survey.id)
continue
Expand Down Expand Up @@ -241,4 +243,20 @@ def survey_end_run_cycle(context, survey_new_runcycleid):

met_etl_db_session.close()

yield Output("survey", "flag_to_run_step_after_survey")
yield Output("survey", "flag_to_run_step_after_survey")


def _update_survey_responses_with_active_survey_id(session, survey):
etl_active_survey_id = session.query(EtlSurveyModel.id).filter(EtlSurveyModel.source_survey_id == survey.id,
EtlSurveyModel.is_active == True)

subquery = (
session.query(EtlSurveyModel.id)
.filter(EtlSurveyModel.source_survey_id == survey.id)
.subquery()
)

session.query(EtlResponseTypeOptionModel).filter(EtlResponseTypeOptionModel.survey_id.in_(subquery)).update(
{'survey_id': etl_active_survey_id}, synchronize_session=False)

session.commit()

0 comments on commit 4b52aa1

Please sign in to comment.