From fc7466f94f24f2bef5d222059582926c4b119662 Mon Sep 17 00:00:00 2001 From: RamuniN Date: Tue, 16 May 2023 17:51:20 +0000 Subject: [PATCH 1/8] added psql client in dockerfile & updated tasks file --- Dockerfile | 1 + db/README | 13 ++++++++++++- tasks.py | 36 +++++++++++++++++++++++------------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8ca2a574..36db1915 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ WORKDIR /app COPY requirements-dev.txt requirements-dev.txt RUN pip --no-cache-dir install --ignore-installed distlib -r requirements-dev.txt RUN pip install gunicorn +RUN apt-get update && apt-get install -y postgresql-client COPY . . EXPOSE 8080 diff --git a/db/README b/db/README index a07b5edf..84a6b3ba 100644 --- a/db/README +++ b/db/README @@ -2,7 +2,18 @@ Tasks to help with dropping and recreating, then repopulating the db during development are in `tasks.py` -1. Set local DATABASE_URL in environment (default in config is `postgresql://postgres:postgres@127.0.0.1:5432/fsd_fund_store_1`) +Tasks can be run localy or in the conatiner. + +- To run locally set the environment variable `DATABASE_URL`, +```bash +export DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/fsd_fund_store_1 +``` + +- To run the tasks in the container, bash into the container +```bash +docker exec -it bash +``` + 1. To recreate the db instance, run inv recreate-local-db diff --git a/tasks.py b/tasks.py index 87d96822..527a0364 100644 --- a/tasks.py +++ b/tasks.py @@ -2,6 +2,7 @@ from colored import fg from colored import stylize from invoke import task +import os ECHO_STYLE = fg("light_gray") + attr("bold") @@ -9,16 +10,24 @@ @task def recreate_local_db(c, database_host="localhost", db_name="fsd_fund_store_1"): """Create a clean database for testing""" - c.run(f"dropdb -h {database_host} --if-exists {db_name} --force") + database_url = os.environ.get("DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}") + + # As we assume "db_name" is not yet created. First we need to connect to psql with a database + # Replace database in database_url with "postgres" db + parts = database_url.split('/', 3) + parts[3] = "postgres" + database_url = '/'.join(parts) + + c.run(f"psql {database_url} -c \"DROP DATABASE IF EXISTS {db_name} WITH (FORCE);\"") print( stylize( f"{db_name} db dropped from {database_host}...", ECHO_STYLE, ) ) - c.run(f"createdb -h {database_host} {db_name}") + c.run(f"psql {database_url} -c \"CREATE DATABASE {db_name};\"") c.run( - f'psql -h {database_host} -d {db_name} -c "create extension if not' + f'psql {database_url} -c "create extension if not' ' exists ltree;"' ) print(stylize(f"{db_name} db created on {database_host}...", ECHO_STYLE)) @@ -46,6 +55,7 @@ def init_migr(c, database_host="localhost", db_name="fsd_fund_store_1"): @task def seed_db(c, database_host="localhost", db_name="fsd_fund_store_1"): + database_url = os.environ.get("DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}") c.run("flask db upgrade") print( stylize( @@ -53,32 +63,32 @@ def seed_db(c, database_host="localhost", db_name="fsd_fund_store_1"): ECHO_STYLE, ) ) - c.run(f"psql -h {database_host} -d {db_name} -a -f db/cof_sql/fund.sql") - c.run(f"psql -h {database_host} -d {db_name} -a -f db/cof_sql/rounds.sql") - c.run(f"psql -h {database_host} -d {db_name} -a -f db/cof_sql/sections.sql") + c.run(f"psql {database_url} -a -f db/cof_sql/fund.sql") + c.run(f"psql {database_url} -a -f db/cof_sql/rounds.sql") + c.run(f"psql {database_url} -a -f db/cof_sql/sections.sql") c.run( - f"psql -h {database_host} -d {db_name} -a -f db/cof_sql/assessment_fields.sql" + f"psql {database_url} -a -f db/cof_sql/assessment_fields.sql" ) - c.run(f"psql -h {database_host} -d {db_name} -a -f db/cof_sql/section_fields.sql") + c.run(f"psql {database_url} -a -f db/cof_sql/section_fields.sql") # c.run( - # f"psql -h {database_host} -d {db_name} -a -f" + # f"psql {database_url} -a -f" # " db/cof_sql/translations.sql" # ) - c.run(f"psql -h {database_host} -d {db_name} -a -f db/cof_sql/form_name.sql") + c.run(f"psql {database_url} -a -f db/cof_sql/form_name.sql") c.run( - f'psql -h {database_host} -d {db_name} -c "select f.short_name as' + f'psql {database_url} -c "select f.short_name as' " Fund, r.short_name as Round from round r join fund f on r.fund_id =" ' f.id";' ) c.run( - f'psql -h {database_host} -d {db_name} -c "select f.short_name,' + f'psql {database_url} -c "select f.short_name,' " r.short_name, s.title, s.weighting, s.path from section s join" " round r on round_id=r.id join fund f on r.fund_id = f.id order by" ' path;"' ) c.run( - f'psql -h {database_host} -d {db_name} -c "select s.title, f.title' + f'psql {database_url} -c "select s.title, f.title' " from section s left outer join section_field sf on s.id =" " sf.section_id left outer join assessment_field f on sf.field_id =" ' f.id order by s.path, sf.display_order;"' From 5de1e674688b791711a66c05b863dfca8324e375 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 May 2023 17:53:23 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tasks.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tasks.py b/tasks.py index 527a0364..ed5946f9 100644 --- a/tasks.py +++ b/tasks.py @@ -1,8 +1,9 @@ +import os + from colored import attr from colored import fg from colored import stylize from invoke import task -import os ECHO_STYLE = fg("light_gray") + attr("bold") @@ -10,26 +11,25 @@ @task def recreate_local_db(c, database_host="localhost", db_name="fsd_fund_store_1"): """Create a clean database for testing""" - database_url = os.environ.get("DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}") + database_url = os.environ.get( + "DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" + ) # As we assume "db_name" is not yet created. First we need to connect to psql with a database # Replace database in database_url with "postgres" db - parts = database_url.split('/', 3) + parts = database_url.split("/", 3) parts[3] = "postgres" - database_url = '/'.join(parts) + database_url = "/".join(parts) - c.run(f"psql {database_url} -c \"DROP DATABASE IF EXISTS {db_name} WITH (FORCE);\"") + c.run(f'psql {database_url} -c "DROP DATABASE IF EXISTS {db_name} WITH (FORCE);"') print( stylize( f"{db_name} db dropped from {database_host}...", ECHO_STYLE, ) ) - c.run(f"psql {database_url} -c \"CREATE DATABASE {db_name};\"") - c.run( - f'psql {database_url} -c "create extension if not' - ' exists ltree;"' - ) + c.run(f'psql {database_url} -c "CREATE DATABASE {db_name};"') + c.run(f'psql {database_url} -c "create extension if not exists ltree;"') print(stylize(f"{db_name} db created on {database_host}...", ECHO_STYLE)) @@ -55,7 +55,9 @@ def init_migr(c, database_host="localhost", db_name="fsd_fund_store_1"): @task def seed_db(c, database_host="localhost", db_name="fsd_fund_store_1"): - database_url = os.environ.get("DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}") + database_url = os.environ.get( + "DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" + ) c.run("flask db upgrade") print( stylize( @@ -66,9 +68,7 @@ def seed_db(c, database_host="localhost", db_name="fsd_fund_store_1"): c.run(f"psql {database_url} -a -f db/cof_sql/fund.sql") c.run(f"psql {database_url} -a -f db/cof_sql/rounds.sql") c.run(f"psql {database_url} -a -f db/cof_sql/sections.sql") - c.run( - f"psql {database_url} -a -f db/cof_sql/assessment_fields.sql" - ) + c.run(f"psql {database_url} -a -f db/cof_sql/assessment_fields.sql") c.run(f"psql {database_url} -a -f db/cof_sql/section_fields.sql") # c.run( # f"psql {database_url} -a -f" From 854301be1e8dc51dd109380f606c56d3bddf3a2a Mon Sep 17 00:00:00 2001 From: RamuniN Date: Wed, 17 May 2023 08:44:44 +0100 Subject: [PATCH 3/8] updated the tasks --- tasks.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/tasks.py b/tasks.py index ed5946f9..8726cf21 100644 --- a/tasks.py +++ b/tasks.py @@ -4,22 +4,28 @@ from colored import fg from colored import stylize from invoke import task +from urllib.parse import urlparse ECHO_STYLE = fg("light_gray") + attr("bold") @task -def recreate_local_db(c, database_host="localhost", db_name="fsd_fund_store_1"): +def recreate_local_db(c, database_host=None, db_name=None): """Create a clean database for testing""" - database_url = os.environ.get( - "DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" - ) - # As we assume "db_name" is not yet created. First we need to connect to psql with a database + # As we assume "db_name" is not yet created. First we need to connect to psql with an existing database # Replace database in database_url with "postgres" db - parts = database_url.split("/", 3) - parts[3] = "postgres" - database_url = "/".join(parts) + if not (database_host and db_name): + database_url = os.environ.get("DATABASE_URL") + if not database_url: + raise Exception("Please provide args: [database_host, db_name] or set the var 'DATABASE_URL'") + parsed_db_url = urlparse(database_url) + database_host = parsed_db_url.hostname + db_name = parsed_db_url.path.lstrip('/') + parsed_db_url = parsed_db_url._replace(path="/postgres") + database_url = parsed_db_url.geturl() + else: + database_url = f"postgresql://postgres:postgres@{database_host}:5432/postgres" c.run(f'psql {database_url} -c "DROP DATABASE IF EXISTS {db_name} WITH (FORCE);"') print( @@ -54,10 +60,16 @@ def init_migr(c, database_host="localhost", db_name="fsd_fund_store_1"): @task -def seed_db(c, database_host="localhost", db_name="fsd_fund_store_1"): - database_url = os.environ.get( - "DATABASE_URL", f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" - ) +def seed_db(c, database_host=None, db_name=None): + """Seed the Fund data into the database.""" + + if not (database_host and db_name): + database_url = os.environ.get("DATABASE_URL") + if not database_url: + raise Exception("Please provide args: [database_host, db_name] or set the var 'DATABASE_URL'") + else: + database_url = f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" + c.run("flask db upgrade") print( stylize( From 0696e67c7e46d5f83f4cae9300598594c2c2426b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 17 May 2023 07:45:39 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tasks.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tasks.py b/tasks.py index 8726cf21..ad89f2aa 100644 --- a/tasks.py +++ b/tasks.py @@ -1,10 +1,10 @@ import os +from urllib.parse import urlparse from colored import attr from colored import fg from colored import stylize from invoke import task -from urllib.parse import urlparse ECHO_STYLE = fg("light_gray") + attr("bold") @@ -18,10 +18,13 @@ def recreate_local_db(c, database_host=None, db_name=None): if not (database_host and db_name): database_url = os.environ.get("DATABASE_URL") if not database_url: - raise Exception("Please provide args: [database_host, db_name] or set the var 'DATABASE_URL'") + raise Exception( + "Please provide args: [database_host, db_name] or set the var" + " 'DATABASE_URL'" + ) parsed_db_url = urlparse(database_url) database_host = parsed_db_url.hostname - db_name = parsed_db_url.path.lstrip('/') + db_name = parsed_db_url.path.lstrip("/") parsed_db_url = parsed_db_url._replace(path="/postgres") database_url = parsed_db_url.geturl() else: @@ -66,7 +69,10 @@ def seed_db(c, database_host=None, db_name=None): if not (database_host and db_name): database_url = os.environ.get("DATABASE_URL") if not database_url: - raise Exception("Please provide args: [database_host, db_name] or set the var 'DATABASE_URL'") + raise Exception( + "Please provide args: [database_host, db_name] or set the var" + " 'DATABASE_URL'" + ) else: database_url = f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" From acd3887de4adeaa744bb069cfb3033a97e5dbeea Mon Sep 17 00:00:00 2001 From: RamuniN Date: Wed, 17 May 2023 12:15:54 +0100 Subject: [PATCH 5/8] fixed spelling errors --- db/README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/README b/db/README index 84a6b3ba..dd94e17b 100644 --- a/db/README +++ b/db/README @@ -2,9 +2,9 @@ Tasks to help with dropping and recreating, then repopulating the db during development are in `tasks.py` -Tasks can be run localy or in the conatiner. +Tasks can be run locally and in container -- To run locally set the environment variable `DATABASE_URL`, +- To run locally, set the environment variable `DATABASE_URL`, ```bash export DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/fsd_fund_store_1 ``` From 56c50541377f7844d742b12870be7ac7b54f0539 Mon Sep 17 00:00:00 2001 From: RamuniN Date: Wed, 17 May 2023 16:24:09 +0100 Subject: [PATCH 6/8] remove args & make use of env db url --- db/README | 4 ++-- tasks.py | 38 +++++++++++++------------------------- 2 files changed, 15 insertions(+), 27 deletions(-) diff --git a/db/README b/db/README index dd94e17b..5a0aac3d 100644 --- a/db/README +++ b/db/README @@ -4,9 +4,9 @@ Tasks to help with dropping and recreating, then repopulating the db during deve Tasks can be run locally and in container -- To run locally, set the environment variable `DATABASE_URL`, +- To run locally, make sure `psql` client is installed on your machine(https://www.postgresql.org/download/) & set the environment variable `DATABASE_URL`, ```bash -export DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/fsd_fund_store_1 +export DATABASE_URL=postgresql://postgres:password@127.0.0.1:5432/fund_store ``` - To run the tasks in the container, bash into the container diff --git a/tasks.py b/tasks.py index ad89f2aa..59afe86b 100644 --- a/tasks.py +++ b/tasks.py @@ -10,25 +10,19 @@ @task -def recreate_local_db(c, database_host=None, db_name=None): +def recreate_local_db(c): """Create a clean database for testing""" # As we assume "db_name" is not yet created. First we need to connect to psql with an existing database # Replace database in database_url with "postgres" db - if not (database_host and db_name): - database_url = os.environ.get("DATABASE_URL") - if not database_url: - raise Exception( - "Please provide args: [database_host, db_name] or set the var" - " 'DATABASE_URL'" - ) - parsed_db_url = urlparse(database_url) - database_host = parsed_db_url.hostname - db_name = parsed_db_url.path.lstrip("/") - parsed_db_url = parsed_db_url._replace(path="/postgres") - database_url = parsed_db_url.geturl() - else: - database_url = f"postgresql://postgres:postgres@{database_host}:5432/postgres" + database_url = os.environ.get("DATABASE_URL") + if not database_url: + raise Exception("Please set the environmental variable 'DATABASE_URL'!") + parsed_db_url = urlparse(database_url) + database_host = parsed_db_url.hostname + db_name = parsed_db_url.path.lstrip("/") + parsed_db_url = parsed_db_url._replace(path="/postgres") + database_url = parsed_db_url.geturl() c.run(f'psql {database_url} -c "DROP DATABASE IF EXISTS {db_name} WITH (FORCE);"') print( @@ -63,18 +57,12 @@ def init_migr(c, database_host="localhost", db_name="fsd_fund_store_1"): @task -def seed_db(c, database_host=None, db_name=None): +def seed_db(c): """Seed the Fund data into the database.""" - if not (database_host and db_name): - database_url = os.environ.get("DATABASE_URL") - if not database_url: - raise Exception( - "Please provide args: [database_host, db_name] or set the var" - " 'DATABASE_URL'" - ) - else: - database_url = f"postgresql://postgres:postgres@{database_host}:5432/{db_name}" + database_url = os.environ.get("DATABASE_URL") + if not database_url: + raise Exception("Please set the environmental variable 'DATABASE_URL'!") c.run("flask db upgrade") print( From fe3c135adbb42a52ce2aa5b520ed94dc2a5d3d01 Mon Sep 17 00:00:00 2001 From: RamuniN Date: Wed, 17 May 2023 17:05:41 +0100 Subject: [PATCH 7/8] revert load cof round files --- scripts/load_cof_r2.py | 155 +++++++++++++++++++-------------------- scripts/load_cof_r3w1.py | 21 +++--- 2 files changed, 87 insertions(+), 89 deletions(-) diff --git a/scripts/load_cof_r2.py b/scripts/load_cof_r2.py index e3cf0869..62dce226 100644 --- a/scripts/load_cof_r2.py +++ b/scripts/load_cof_r2.py @@ -51,87 +51,86 @@ def create_sections(path_prefix, round_id, forms_config): # assessment_result = insert_assessment_sections(cof_form_config.COF_ROUND_2_ID, assessment_config) -if __name__ == "__main__": - with app.app_context(): +with app.app_context(): - # -- load fund and rounds -- - fund_config = { - "id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4", - "name": "Community Ownership Fund", - "title": "funding to save an asset in your community", - "short_name": "COF", - "description": ( - "The Community Ownership Fund is a £150 million fund over 4 years" - " to support community groups across England, Wales, Scotland and" - " Northern Ireland to take ownership of assets which are at risk" - " of being lost to the community." - ), - } + # -- load fund and rounds -- + fund_config = { + "id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4", + "name": "Community Ownership Fund", + "title": "funding to save an asset in your community", + "short_name": "COF", + "description": ( + "The Community Ownership Fund is a £150 million fund over 4 years" + " to support community groups across England, Wales, Scotland and" + " Northern Ireland to take ownership of assets which are at risk" + " of being lost to the community." + ), + } - rounds_config = [ - { - "id": "c603d114-5364-4474-a0c4-c41cbf4d3bbd", - "title": "Round 2 Window 2", - "short_name": "R2W2", - "opens": "2022-10-04 12:00:00", - "deadline": "2022-12-14 11:59:00", - "fund_id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4", - "assessment_deadline": "2023-03-30 12:00:00", - "prospectus": "https://www.gov.uk/government/publications/community-ownership-fund-prospectus", - "privacy_notice": "https://www.gov.uk/government/publications/community-ownership-fund-privacy-notice/community-ownership-fund-privacy-notice", - "contact_email": "COF@levellingup.gov.uk", - "contact_phone": None, - "contact_textphone": None, - "support_times": "9am to 5pm", - "support_days": "Monday to Friday", - "instructions": ( - "You must have received an invitation to apply. If we did not" - " invite you, first ' - " express your interest in the fund." - ), - }, - { - "id": "5cf439bf-ef6f-431e-92c5-a1d90a4dd32f", - "title": "Round 2 Window 3", - "short_name": "R2W3", - "opens": "2022-10-04 12:00:00", - "deadline": "2022-12-14 11:59:00", - "fund_id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4", - "assessment_deadline": "2023-03-30 12:00:00", - "prospectus": "https://www.gov.uk/government/publications/community-ownership-fund-prospectus", - "privacy_notice": "https://www.gov.uk/government/publications/community-ownership-fund-privacy-notice/community-ownership-fund-privacy-notice", - "contact_email": "COF@levellingup.gov.uk", - "contact_phone": None, - "contact_textphone": None, - "support_times": "9am to 5pm", - "support_days": "Monday to Friday", - "instructions": ( - "You must have received an invitation to apply. If we did not" - " invite you, first ' - " express your interest in the fund." - ), - }, - ] + rounds_config = [ + { + "id": "c603d114-5364-4474-a0c4-c41cbf4d3bbd", + "title": "Round 2 Window 2", + "short_name": "R2W2", + "opens": "2022-10-04 12:00:00", + "deadline": "2022-12-14 11:59:00", + "fund_id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4", + "assessment_deadline": "2023-03-30 12:00:00", + "prospectus": "https://www.gov.uk/government/publications/community-ownership-fund-prospectus", + "privacy_notice": "https://www.gov.uk/government/publications/community-ownership-fund-privacy-notice/community-ownership-fund-privacy-notice", + "contact_email": "COF@levellingup.gov.uk", + "contact_phone": None, + "contact_textphone": None, + "support_times": "9am to 5pm", + "support_days": "Monday to Friday", + "instructions": ( + "You must have received an invitation to apply. If we did not invite" + " you, first ' + " express your interest in the fund." + ), + }, + { + "id": "5cf439bf-ef6f-431e-92c5-a1d90a4dd32f", + "title": "Round 2 Window 3", + "short_name": "R2W3", + "opens": "2022-10-04 12:00:00", + "deadline": "2022-12-14 11:59:00", + "fund_id": "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4", + "assessment_deadline": "2023-03-30 12:00:00", + "prospectus": "https://www.gov.uk/government/publications/community-ownership-fund-prospectus", + "privacy_notice": "https://www.gov.uk/government/publications/community-ownership-fund-privacy-notice/community-ownership-fund-privacy-notice", + "contact_email": "COF@levellingup.gov.uk", + "contact_phone": None, + "contact_textphone": None, + "support_times": "9am to 5pm", + "support_days": "Monday to Friday", + "instructions": ( + "You must have received an invitation to apply. If we did not invite" + " you, first ' + " express your interest in the fund." + ), + }, + ] - inserted_fund = insert_fund_data(fund_config) - print("Fund inserted:") - print(inserted_fund) - inserted_rounds = insert_round_data(rounds_config) - print("Rounds inserted:") - print(inserted_rounds) + inserted_fund = insert_fund_data(fund_config) + print("Fund inserted:") + print(inserted_fund) + inserted_rounds = insert_round_data(rounds_config) + print("Rounds inserted:") + print(inserted_rounds) - # Do we want to reuse the application sections config? + # Do we want to reuse the application sections config? - # Separate config for r2w2 and r2w3 - # create_sections("1", cof_form_config.COF_ROUND_2_ID, cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, True) - # create_sections("2", cof_form_config.COF_ROUND_2_W3_ID, cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, True) + # Separate config for r2w2 and r2w3 + # create_sections("1", cof_form_config.COF_ROUND_2_ID, cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, True) + # create_sections("2", cof_form_config.COF_ROUND_2_W3_ID, cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, True) - # reuse config between r2w2 and r2w3 - create_sections( - "1", - cof_form_config.COF_ROUND_2_ID, - cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, - ) - create_sections("1", cof_form_config.COF_ROUND_2_W3_ID, None) + # reuse config between r2w2 and r2w3 + create_sections( + "1", + cof_form_config.COF_ROUND_2_ID, + cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, + ) + create_sections("1", cof_form_config.COF_ROUND_2_W3_ID, None) diff --git a/scripts/load_cof_r3w1.py b/scripts/load_cof_r3w1.py index a63026a8..02ab528d 100644 --- a/scripts/load_cof_r3w1.py +++ b/scripts/load_cof_r3w1.py @@ -183,15 +183,14 @@ } ] -if __name__ == "__main__": - with app.app_context(): - print("Inserting fund and round data.") - insert_fund_data(fund_config) - insert_round_data(round_config) +with app.app_context(): + print("Inserting fund and round data.") + insert_fund_data(fund_config) + insert_round_data(round_config) - print("Inserting base sections config.") - insert_application_sections(COF_ROUND_3_WINDOW_1_ID, tree_base_sections) - print("Inserting sections.") - insert_application_sections( - COF_ROUND_3_WINDOW_1_ID, sorted_application_r3w1_sections - ) + print("Inserting base sections config.") + insert_application_sections(COF_ROUND_3_WINDOW_1_ID, tree_base_sections) + print("Inserting sections.") + insert_application_sections( + COF_ROUND_3_WINDOW_1_ID, sorted_application_r3w1_sections + ) From 412add28e73f3426c98e3d58e9dfb7111014e21d Mon Sep 17 00:00:00 2001 From: RamuniN Date: Wed, 17 May 2023 17:14:54 +0100 Subject: [PATCH 8/8] fix app import error --- README.md | 4 ++-- scripts/load_cof_r2.py | 10 ++++++++-- scripts/load_cof_r3w1.py | 12 ++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4b3d7071..ace3c347 100644 --- a/README.md +++ b/README.md @@ -107,11 +107,11 @@ You can also force all defined rounds to be open by setting the environment vari To seed fund & round data to db ``` -docker exec -ti scripts/load_cof_r2.py +docker exec -ti python -m scripts.load_cof_r2 ``` ``` -docker exec -ti scripts/load_cof_r3w1.py +docker exec -ti python -m scripts.load_cof_r3w1 ``` To amend the round dates diff --git a/scripts/load_cof_r2.py b/scripts/load_cof_r2.py index 62dce226..792912c8 100644 --- a/scripts/load_cof_r2.py +++ b/scripts/load_cof_r2.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # flake8: noqa -from app import app # noqa: E402 from config import Config # noqa: E402 from db.queries import insert_application_sections from db.queries import insert_assessment_sections @@ -51,7 +50,7 @@ def create_sections(path_prefix, round_id, forms_config): # assessment_result = insert_assessment_sections(cof_form_config.COF_ROUND_2_ID, assessment_config) -with app.app_context(): +def main() -> None: # -- load fund and rounds -- fund_config = { @@ -134,3 +133,10 @@ def create_sections(path_prefix, round_id, forms_config): cof_form_config.COF_R2_ORDERED_FORMS_CONFIG, ) create_sections("1", cof_form_config.COF_ROUND_2_W3_ID, None) + + +if __name__ == "__main__": + from app import app + + with app.app_context(): + main() diff --git a/scripts/load_cof_r3w1.py b/scripts/load_cof_r3w1.py index 02ab528d..4ad1c5d4 100644 --- a/scripts/load_cof_r3w1.py +++ b/scripts/load_cof_r3w1.py @@ -1,4 +1,4 @@ -from app import app # noqa: E402 +#!/usr/bin/env python3 from db.queries import insert_application_sections from db.queries import insert_fund_data from db.queries import insert_round_data @@ -183,7 +183,8 @@ } ] -with app.app_context(): + +def main() -> None: print("Inserting fund and round data.") insert_fund_data(fund_config) insert_round_data(round_config) @@ -194,3 +195,10 @@ insert_application_sections( COF_ROUND_3_WINDOW_1_ID, sorted_application_r3w1_sections ) + + +if __name__ == "__main__": + from app import app + + with app.app_context(): + main()