diff --git a/CHANGELOG.md b/CHANGELOG.md index 860593c8..382d13ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## v2.4.0 (2024-10-11) +* Update SBA framework + * Multiple DB migrations (final migration (ce8e6e308e5c)) + * No longer prefill information + * Add fields for framework information * Allow linking between observation system and application nodes ## v2.3.0 (2024-10-02) diff --git a/deploy/post/v2.4.0 b/deploy/post/v2.4.0 new file mode 100755 index 00000000..bc4b5185 --- /dev/null +++ b/deploy/post/v2.4.0 @@ -0,0 +1,24 @@ +#!/bin/bash + +set -euo pipefail + +# HACK: Garrison doesn't see these variables that were exported in main deploy +# script, which is unintuitive. NOTE that sourcing VERSION.env is not +# compatible with integration, but this script doesn't receive the environment +# as a parameter. Garrison needs some extra thought here. +source /etc/profile.d/envvars.sh +source VERSION.env + +# TODO: figure out better way +echo "Waiting 10 seconds for the new stack to come up..." +sleep 10 + +docker compose run --rm usaon-benefit-tool alembic upgrade head + +# confirm the expected migration was applied +current=$(docker compose run --rm usaon-benefit-tool alembic current 2>/dev/null) +if [ "ce8e6e308e5c (head)" = "${current}" ]; then + echo "Data migration successful. On expected revision ${current}." +else + echo "Data migration failed. On unexpected revision ${current}." +fi diff --git a/migrations/versions/b9357b81d2b0_add_new_sba_related_fields.py b/migrations/versions/b9357b81d2b0_add_new_sba_related_fields.py new file mode 100644 index 00000000..b8e781e2 --- /dev/null +++ b/migrations/versions/b9357b81d2b0_add_new_sba_related_fields.py @@ -0,0 +1,53 @@ +"""Add new SBA related fields. + +Revision ID: b9357b81d2b0 +Revises: ea1181510e10 +Create Date: 2024-10-14 22:37:03.652801 + +""" + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = 'b9357b81d2b0' +down_revision: str | None = 'ea1181510e10' +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('name', sa.String(length=512), nullable=True), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('short_name', sa.String(length=256), nullable=True), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('description', sa.String(), nullable=True), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('framework_name', sa.String(length=256), nullable=True), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('framework_url', sa.String(length=512), nullable=True), + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('node_subtype_societal_benefit_area', 'framework_url') + op.drop_column('node_subtype_societal_benefit_area', 'framework_name') + op.drop_column('node_subtype_societal_benefit_area', 'description') + op.drop_column('node_subtype_societal_benefit_area', 'short_name') + op.drop_column('node_subtype_societal_benefit_area', 'name') + # ### end Alembic commands ### diff --git a/migrations/versions/ce8e6e308e5c_remove_prefilled_sba_reference_tables.py b/migrations/versions/ce8e6e308e5c_remove_prefilled_sba_reference_tables.py new file mode 100644 index 00000000..f6caaf14 --- /dev/null +++ b/migrations/versions/ce8e6e308e5c_remove_prefilled_sba_reference_tables.py @@ -0,0 +1,74 @@ +"""remove prefilled sba reference tables. + +Revision ID: ce8e6e308e5c +Revises: d46c4d798847 +Create Date: 2024-10-15 23:03:00.302098 + +""" + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = 'ce8e6e308e5c' +down_revision: str | None = 'd46c4d798847' +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('societal_benefit_key_objective') + op.drop_table('societal_benefit_subarea') + op.drop_table('societal_benefit_area') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + 'societal_benefit_area', + sa.Column('id', sa.VARCHAR(length=256), autoincrement=False, nullable=False), + sa.PrimaryKeyConstraint('id', name='pk_societal_benefit_area'), + postgresql_ignore_search_path=False, + ) + op.create_table( + 'societal_benefit_subarea', + sa.Column('id', sa.VARCHAR(length=256), autoincrement=False, nullable=False), + sa.Column( + 'societal_benefit_area_id', + sa.VARCHAR(length=256), + autoincrement=False, + nullable=False, + ), + sa.ForeignKeyConstraint( + ['societal_benefit_area_id'], + ['societal_benefit_area.id'], + name='fk_societal_benefit_subarea_societal_benefit_area_id_so_0d93', + ), + sa.PrimaryKeyConstraint('id', name='pk_societal_benefit_subarea'), + postgresql_ignore_search_path=False, + ) + op.create_table( + 'societal_benefit_key_objective', + sa.Column('id', sa.VARCHAR(length=256), autoincrement=False, nullable=False), + sa.Column( + 'societal_benefit_subarea_id', + sa.VARCHAR(length=256), + autoincrement=False, + nullable=False, + ), + sa.ForeignKeyConstraint( + ['societal_benefit_subarea_id'], + ['societal_benefit_subarea.id'], + name='fk_societal_benefit_key_objective_societal_benefit_suba_8857', + ), + sa.PrimaryKeyConstraint( + 'id', + 'societal_benefit_subarea_id', + name='pk_societal_benefit_key_objective', + ), + ) + # ### end Alembic commands ### diff --git a/migrations/versions/d46c4d798847_remove_sba_foreign_key_relationship.py b/migrations/versions/d46c4d798847_remove_sba_foreign_key_relationship.py new file mode 100644 index 00000000..619c7dc3 --- /dev/null +++ b/migrations/versions/d46c4d798847_remove_sba_foreign_key_relationship.py @@ -0,0 +1,80 @@ +"""Remove SBA foreign key relationship. + +Revision ID: d46c4d798847 +Revises: b9357b81d2b0 +Create Date: 2024-10-15 22:10:15.917116 + +""" + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = 'd46c4d798847' +down_revision: str | None = 'b9357b81d2b0' +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint( + 'uq_node_subtype_societal_benefit_area_societal_benefit_area_id', + 'node_subtype_societal_benefit_area', + type_='unique', + ) + op.drop_constraint( + 'fk_node_subtype_societal_benefit_area_societal_benefit__adfa', + 'node_subtype_societal_benefit_area', + type_='foreignkey', + ) + op.drop_column('node_subtype_societal_benefit_area', 'description') + op.drop_column('node_subtype_societal_benefit_area', 'short_name') + op.drop_column('node_subtype_societal_benefit_area', 'name') + op.drop_column('node_subtype_societal_benefit_area', 'societal_benefit_area_id') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column( + 'societal_benefit_area_id', + sa.VARCHAR(), + autoincrement=False, + nullable=False, + ), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('name', sa.VARCHAR(length=512), autoincrement=False, nullable=True), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column( + 'short_name', + sa.VARCHAR(length=256), + autoincrement=False, + nullable=True, + ), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=True), + ) + op.create_foreign_key( + 'fk_node_subtype_societal_benefit_area_societal_benefit__adfa', + 'node_subtype_societal_benefit_area', + 'societal_benefit_area', + ['societal_benefit_area_id'], + ['id'], + ) + op.create_unique_constraint( + 'uq_node_subtype_societal_benefit_area_societal_benefit_area_id', + 'node_subtype_societal_benefit_area', + ['societal_benefit_area_id'], + ) + # ### end Alembic commands ### diff --git a/usaon_benefit_tool/constants/sba.py b/usaon_benefit_tool/constants/sba.py deleted file mode 100644 index 07a6065c..00000000 --- a/usaon_benefit_tool/constants/sba.py +++ /dev/null @@ -1,390 +0,0 @@ -# TODO: Consider using a type compatible with SQLAlchemy models -SocietalBenefitKeyObjective = str -SocietalBenefitSubArea = list[SocietalBenefitKeyObjective] -SocietalBenefitArea = dict[str, SocietalBenefitSubArea] -IaoaSbaFramework = dict[str, SocietalBenefitArea] - -# International Arctic Observations Assessment Framework -# https://www.arcticobserving.org/images/pdf/misc/STPI-SAON-International-Arctic-Observations-Framework-Report-2017.pdf -IAOA_SBA_FRAMEWORK: IaoaSbaFramework = { - 'Disaster Preparedness': { - 'Disaster Mitigation': [ - 'Apply common indices and indicators to inform' - ' disaster mitigation activities', - 'Develop educationtrainingand compliance procedures' - ' for disaster mitigation', - 'Ensure access to disaster-relevant environmental intelligence', - 'Inform infrastructure design standards for disaster mitigation', - ], - 'Disaster Protection and Prevention': [ - 'Apply common indices and indicators to assess' - ' state of disaster preparedness', - 'Conduct risk assessments to inform disaster preparedness activities', - 'Deploy emergency responder personnel and equipment in an optimal' - ' manner prior to a disaster', - 'Develop and execute plans and procedures for disaster prevention', - 'Improve emergency preparedness for human-made hazards', - 'Improve emergency preparedness for natural hazards', - ], - 'Disaster Recovery': [ - 'Conduct damage assessments to inform disaster recovery', - 'Improve future disaster preparedness activies', - 'Inform social, economic, and cultural post-disaster recovery', - 'Support disaster aid planning and deployment', - ], - 'Disaster Response': [ - 'Conduct disaster response operations in a timely and' - ' cost-effective manner', - 'Conduct search and rescue operations in a safe and effective manner', - 'Deploy emergency responder personnel and equipment in an optimal' - ' manner during and after a disaster', - 'Ensure domain awareness for disaster response', - ], - 'Hazard Identification and Disaster Prediction': [ - 'Develop and maintain analytical capabilities for hazard' - ' identification and disaster prediction', - 'Ensure domain awareness for identification and prediction' - ' of all hazards', - 'Improve understanding of Earth systems to inform hazard' - ' identification and disaster prediction', - ], - }, - 'Environmental Quality': { - 'Drivers of Environmental Impacts': [ - 'Improve ability to identify environmental impact thresholds' - ' and predict their consequences', - 'Improve understanding of climate as a driver of changing' - ' environmental quality', - 'Manage regional and local human activities in the Arctic' - ' to mitigate environmental impact', - 'Reduce the source of transboundary and local pullutants in the Arctic', - ], - 'Environmental Impacts': [ - 'Adapt to and mitigate the impacts of climate change on' - ' ecosystems and human health', - 'Improve understanding of the impacts of climate change' - ' on ecosystems and human health', - 'Manage the environmental impacts of increased human' - ' activities in the Arctic', - 'Mitigate the impacts of pollutants on ecosystems and human health', - 'Understand the impacts of pollutants on the energy balance and' - ' the effects on the cryosphere', - ], - 'Quality of Ecosystem Functions': [ - 'Ensure the availability of freshwater suitable for human use' - ' and ecosystem function', - 'Improve the understanding and function of habitats in the Arctic', - 'Improve understanding of the value proposition of ecosystem' - ' services in the Arctic', - 'Maintain ecosystem quality, diversity, and extent to ensure the' - ' delivery of ecosystem functions and services', - ], - }, - 'Food Security': { - 'Accesible Available and Sustainable Food': [ - 'Enhance resilience to changes in Arctic climate and ecosystems' - ' that affect access to food', - 'Ensure continued access to and viability of hunting, fishing,' - ' and gathering active ities in the Arctic', - 'Improve stewardship of fisheries and animal stocks in an' - ' environmentally sustainable manner', - 'Improve understanding of land use on sustainable stewardship' - ' of food resources', - 'Improve understanding of the energy demands associated with' - ' the Arctic food supply chain', - 'Improve understanding of the impacts of climate change on hunting' - ' and fishing in the Arctic', - 'Improve understanding of the impacts of climate change on the Arctic' - ' food supply chain', - 'Understand and coordinate institutional arrangements affecting the' - ' availability, accessibility, and sustainability of food', - ], - 'Exchange of Food': [ - 'Ensure continued operation of transportatoin and shipping activities' - ' for food exhange', - 'Improve understanding of formal and informal exchange networks to' - ' assess the use of food beyond its currency value', - 'Understanding and coordinate food exchange regulations and activities' - ' to mitigate resource scarcity and overabundance', - ], - 'Safe Food': [ - 'Ensure food supplies do not exceed minimum pollutant thresholds', - 'Ensure the safety and storage of food supplies under changing' - ' environmental conditions', - 'Improve the quality of and access to information about the' - ' availability and safety of food', - 'Improve understanding of the nutritional quality of food in the Arctic', - 'Improve understanding of the nutritional requirements of Arctic' - ' populations', - 'Understand and coordinate institutional arrangements affecting food' - ' safety', - ], - }, - 'Fundamental Understanding of Arctic Systems': { - 'Linkages, Interactions, and Feedback among Arctic Subsystems': [ - 'Improve ability to scale projections, models, and information' - ' related to components of the Arctic system', - 'Improve systems-level understanding by identifying predictability' - ' limits for the Arctic system', - 'Improve Understanding of processes, variables, and rates of change' - ' in components of the Arctic system, including the cryosphere', - ], - 'Linkages, Interactions and Feedback between Arctic Subsystems' - ' and Global Systems': [ - 'Improve understanding of anthropogenic influences on Arctic change', - 'Improve understanding of Arctic amplification of global warming', - 'Improve understanding of the impacts of biologic drivers on the' - ' Arctic system', - 'Improve understanding of the impacts of socioeconomic drivers on' - ' the Arctic system', - 'Improve understanding of the relationship between Arctic and global' - ' atmospheric and oceanic processes', - ], - }, - 'Human Health': { - 'Mental Health': [ - 'Improve understanding of mental health determinants of Arctic residents', - 'Improve understanding of the risks and benefits of climatic and' - ' environmental changes on community, household, and individual mental' - ' health', - 'Mitigate the impacts of climatic and environmental changes on community,' - ' household, and individual mental health', - 'Promote community, household, and individual mental health through' - ' adaptation to climatic and environmental changes', - ], - 'Physical Health': [ - 'Improve understanding of physical health determinants of Arctic residents', - 'Improve understanding of the risks and benefits of climatic and' - ' environmental changes on community, household, and individual' - ' physical health', - 'Mitigate the impacts of climatic and environmental changes on' - ' community, household, and individual physical health', - 'Promote community, household, and inidivdual physical health' - ' through adaptation to climatic and environmental changes', - ], - 'Public Health': [ - 'Ensure access to health care and health promotion services', - 'Improves access to clean water and sanitation infastructure', - 'Improve early warning systems for impending public health emergencies', - 'Improve synthesis of health- and environmental health-related' - ' knowledge across Arctic cultures', - 'Improve understanding of epidemiology and health behaviors' - ' in the Arctic to inform public health policies and strategies', - 'Improve understanding of influences of climatic and environmental' - ' changes on emerging infectious diseases in the Arctic', - 'Reduce presence of foodborne pathogens and contaminants in Arctic food' - ' supplies', - ], - }, - 'Infrastructure and Operations': { - 'Planning of Infrastructure': [ - 'Ensure safe and secure infrastructure design', - 'Improve understanding of the impacts of infrastructure on the' - ' environment, human systems, and society', - 'Support infrastructure design siting', - ], - 'Development of Infrastructure': [ - 'Ensure compliance with infrastructure codes and' - ' environmental regulations', - 'Inform and support construction and quality assurance' - ' and control activities', - ], - 'Operations and Maintenance of Infrastructure': [ - 'Ensure safe and secure infrastructure operations', - 'Improve understanding of environmental effects on' - ' infrastructure operations', - 'Maintain awareness and provide predictive capabilities' - ' to support safe operation of infrastructure', - 'Maintain operational awareness of infrastructure systems', - 'Support economic optimization of operations', - ], - 'Decommissioning of Infrastructure': [ - 'Dispose of infrastructure materials or assets that cannot be re-utilized', - 'Identify opportunities for re-utilization of infrastructure system assets', - 'Improve understanding of long-term impacts of decommissioned' - ' infrastructure systems on Arctic communities and the environment', - 'Inform decisions regarding re-utilization and disposition' - ' of infrastructure systems', - ], - }, - 'Marine and Coastal Ecosystems and Processes': { - 'Marine and Coastal Ecosystem Biodiversity': [ - 'Identify and preserve culturally important marine and coastal areas', - 'Identify and preserve ecologically sensitive marine and coastal' - ' areas for biodiversity', - 'Identify and understand the diversity of Arctic biota throughout' - ' their ranges', - 'Manage and preserve Arctic biota throughout their ranges', - 'Promote resilience and sustainability of Arctic biodiversity' - ' in marine and coastal ecosystems', - ], - 'Marine and Coastal Ecosystem Changes': [ - 'Improve understanding of impacts of environmental change on' - ' Arctic marine and coastal ecosystems', - 'Improve understanding of ecological and evolutionary responses' - ' of marine and coastal organisms to changes in the Arctic', - 'Inform human adaptation to ecosystem changes', - 'Manage disturbances to marine and coastal ecosystems', - ], - 'Marine and Coastal Living Resources': [ - 'Characterize and assess the status and trends of Arctic' - ' and migratory living resources', - 'Manage Arctic and migratory living resources in a sustainable manner', - 'Sustain marine bioprospecting in the Arctic', - ], - 'Marine and Coastal Processes': [ - 'Asses the impact of changing hydrologic and cryospheric' - ' conditions on marine and coastal ecosystems', - 'Improve decision making for responses to changes in' - ' marine and coastal conditions', - 'Improve understanding of physical oceanography, ocean' - ' biogeochemistry, and their interactions', - ], - }, - 'Natural Resources': { - 'Natural Resource Exploration and Assessment': [ - 'Asses and reduce to impact of natural resource exploration', - 'Improve understanding of the connections and dynamics between' - ' resources and environment', - 'Improve understanding of the distribution of Arctic', - 'Manage inventories of existing natural resource stocks,' - ' inlucind protected stocks, in a sustainable manner', - ], - 'Natural Resource Development and Exploitation': [ - 'Assess, manage, and reduce the impact of natural resource' - ' development and exploitation', - 'Ensure regulatory compliance of natural resource' - ' development activities', - 'Maintain the safe and secure operation of natural resource' - ' exploitation activities', - 'Support natural resource development decisions', - 'Understand and project conditions to inform facility' - ' management and support operator situational awareness', - ], - 'Natural Resource Decommissioning and Reclamation': [ - 'Assess long-term risks and hazards associated with reclaimed' - ' or decommissioned sites', - 'Ensure effectiveness of reclamaton measures in the Arctic', - 'Ensure regulatory compliance of reclamation and' - ' decommissioning activities', - 'Inform the development of long-term reclamation and' - ' decommissioning plans', - ], - }, - 'Resilient Communities': { - 'Adaptation and Response of Communities': [ - 'Develop capacity to adapt and respond to Arctic' - ' system changes on communities', - 'Improve community education on Arctic system changes and their impacts', - 'Mitigate the impacts of Arctic system changes on communities', - ], - 'Baseline Conditions of Communities': [ - 'Assess community resources to adapt to Arctic system changes', - 'Assess community understanding of the threats, impacts, and' - ' causes of Arctic system changes', - 'Assess community vulnerability to Arctic system changes', - ], - 'Future Projections of Community Changes': [ - 'Characterize the magnitudes and rates of Arctic system' - ' changes and their impacts on communities', - 'Improve the projections of impacts from Arctic system' - ' changes on communities', - ], - }, - 'Sociocultural Services': { - 'Cultural and Spiritual Experiences': [ - 'Ensure continued access to opportunities for recreation' - ' and human connection with nature', - 'Maintain areas of cultural significance in the Arctic', - 'Maintain the vitality of Arctic languages, cultures,' - ' and communities to preserve knowledge sources', - ], - 'Knowledge Development and Integration': [ - 'Ensure integration of indigenous languages, cultures, and' - ' communities for knowledge co-production', - 'Improve understafing of Arctic processes and cultures to' - ' improve and enhance knowledge co-production', - 'Support development, co-production, and dissemination of' - ' scientific knowledge across Arctic cultures', - ], - 'Socioeconomics': [ - 'Improve understanding of formal and informal exchange networks' - ' for Arctic resources', - 'Improve understanding of socioeconomic systems that impact the Arctic', - 'Improve understanding of the cryospheric and environmental' - ' processes in the Arctic on socioeconomic systems', - ], - }, - 'Terrestrial and Freshwater Ecosystems and Processes': { - 'Terrestrial and Freshwater Ecosystem Biodiversity': [ - 'Identify and preserve culturally important terrestrial' - ' and freshwater areas', - 'Identify and preserve ecologically sensitive terrestrial' - ' and freshwater areas for biodiversity', - 'Identify and understand the diversity of biota throughout their ranges', - 'Manage and preserve biota throughout their ranges', - 'Promote resilience and sustainability of biodiversity in' - ' terrestrial and freshwater ecosystems', - ], - 'Terrestrial and Freshwater Ecosystem Responses to Arctic Changes': [ - 'Improve understanding of changing environmental impacts' - ' on terrestrial and freshwater ecosystems', - 'Improve understanding of ecological and evolutionary responses' - ' of terrestrial and freshwater organisms to changes in the Arctic', - 'Inform human adaptation to ecosystem changes', - 'Manage disturbances to terrestrial and freshwater ecosystems', - ], - 'Terrestrial and Freshwater Living Resources': [ - 'Assess and manage land cover and land use in a sustainable manner', - 'Characterize and assess the status and trends of Arctic and' - ' migratory living resources', - 'Manage and use water resources in a sustainable manner', - 'Manage Arctic and migratory living resources in a sustainable manner', - 'Manage natural resources that support the use of Arctic and migratory' - ' living resources in a sustainable manner', - 'Understand and assess the role of the terrestrial cryosphere as a' - ' resource', - ], - 'Terrestrial and Freshwater Processess': [ - 'Assess the impact of changing hydrologic and cryospheric conditions' - ' on terrestrial and freshwater ecosystems', - 'Improve decision making for responses to changes in terrestrial and' - ' freshwater conditions', - 'Improve understanding of physical and biogeochemical processes in' - ' cryospheric and hydrospheric systems', - 'Improve understanding of the impact of the hydrologic cycle on biota', - ], - }, - 'Weather and Climate': { - 'Weather Effects on Economic Productivity': [ - 'Provide community-specific weather predictions for economic productivity', - 'Provide sector-specific weather predictions for economic productivity', - ], - 'Weather Effects on Protection of Lives and Property': [ - 'Improve understanding, prediction, and detection of weather events in' - ' the Arctic and their effects on life and property', - 'Reduce loss of life and injury and damage to property due to high-impact' - ' weather events', - 'Reduce loss of life and injury and damage to property due to routine' - ' weather events', - ], - 'Weather Effects on Quality of Life': [ - 'Improve public understanding and use of weather products and services', - 'Support ability to understand, plan for, and mitigate changing weather' - ' patterns in the Arctic', - 'Support effective weather response, planning, mitigation, and resource' - ' allocation for communities', - ], - 'Weather Forecasting and Climate Projections': [ - 'Improve understanding of the relationship between the Arctic and global' - ' processes to improve weather predictions and climate projections', - 'Improve linkages between weather and climate observations across' - ' timescales to reduce uncertainty in weather and climate modeling and' - ' prediction', - 'Improve fundamental understanding of Arctic processes that impact' - ' weather in the mid-latitudes', - 'Support effective response, planning, mitigation, and resource allocation' - ' based on changing climatic conditions', - ], - }, -} diff --git a/usaon_benefit_tool/forms.py b/usaon_benefit_tool/forms.py index aa539b33..11979522 100644 --- a/usaon_benefit_tool/forms.py +++ b/usaon_benefit_tool/forms.py @@ -115,11 +115,7 @@ def get_node_label(node: Node) -> str: ), NodeSubtypeSocietalBenefitArea: model_form( NodeSubtypeSocietalBenefitArea, - exclude=[*node_exclude, "societal_benefit_area_id"], - exclude_fk=False, - field_args={ - 'societal_benefit_area': {'get_label': 'id'}, - }, + exclude=node_exclude, ), User: model_form( User, diff --git a/usaon_benefit_tool/models/tables.py b/usaon_benefit_tool/models/tables.py index cbb2f748..60c99426 100644 --- a/usaon_benefit_tool/models/tables.py +++ b/usaon_benefit_tool/models/tables.py @@ -245,7 +245,6 @@ class NodeSubtypeSocietalBenefitArea(Node): """Fields that are specific to societal benefit area type nodes.""" __tablename__ = "node_subtype_societal_benefit_area" - __table_args__ = (UniqueConstraint('societal_benefit_area_id'),) __mapper_args__: ClassVar = { 'polymorphic_identity': NodeTypeDiscriminator.SOCIETAL_BENEFIT_AREA.value, } @@ -256,15 +255,13 @@ class NodeSubtypeSocietalBenefitArea(Node): primary_key=True, nullable=False, ) - societal_benefit_area_id = Column( - String, - ForeignKey('societal_benefit_area.id'), - nullable=False, - ) + + framework_name = Column(String(256), nullable=True) + framework_url = Column(String(512), nullable=True) # TODO: Relationship to societal benefit area table? How would we make a similar # relationship for the other node types? - societal_benefit_area = relationship("SocietalBenefitArea") + # societal_benefit_area = relationship("SocietalBenefitArea") class AssessmentNode(BaseModel): @@ -459,56 +456,3 @@ class AssessmentStatus(BaseModel): Assessment, back_populates='status', ) - - -class SocietalBenefitArea(BaseModel): - __tablename__ = 'societal_benefit_area' - id = Column( - String(256), - primary_key=True, - ) - - societal_benefit_sub_areas = relationship( - 'SocietalBenefitSubArea', - back_populates='societal_benefit_area', - ) - - -class SocietalBenefitSubArea(BaseModel): - __tablename__ = 'societal_benefit_subarea' - id = Column( - String(256), - primary_key=True, - ) - societal_benefit_area_id = Column( - String(256), - ForeignKey('societal_benefit_area.id'), - nullable=False, - ) - - societal_benefit_area = relationship( - 'SocietalBenefitArea', - back_populates='societal_benefit_sub_areas', - ) - societal_benefit_key_objectives = relationship( - 'SocietalBenefitKeyObjective', - back_populates='societal_benefit_sub_area', - ) - - -class SocietalBenefitKeyObjective(BaseModel): - __tablename__ = 'societal_benefit_key_objective' - id = Column( - String(256), - primary_key=True, - ) - societal_benefit_subarea_id = Column( - String(256), - ForeignKey('societal_benefit_subarea.id'), - primary_key=True, - ) - - societal_benefit_sub_area = relationship( - 'SocietalBenefitSubArea', - back_populates='societal_benefit_key_objectives', - ) diff --git a/usaon_benefit_tool/util/db/setup.py b/usaon_benefit_tool/util/db/setup.py index 19e362c4..82385ebe 100644 --- a/usaon_benefit_tool/util/db/setup.py +++ b/usaon_benefit_tool/util/db/setup.py @@ -15,7 +15,6 @@ from usaon_benefit_tool import db from usaon_benefit_tool._types import NodeType, RoleName -from usaon_benefit_tool.constants.sba import IAOA_SBA_FRAMEWORK from usaon_benefit_tool.constants.status import ASSESSMENT_STATUSES from usaon_benefit_tool.models.tables import ( Assessment, @@ -26,9 +25,6 @@ NodeSubtypeOther, NodeSubtypeSocietalBenefitArea, Role, - SocietalBenefitArea, - SocietalBenefitKeyObjective, - SocietalBenefitSubArea, User, ) from usaon_benefit_tool.util.dev import DEV_USER, TEST_USER @@ -61,7 +57,6 @@ def populate_reference_data() -> None: Reference tables are tables containing (mostly) static data, e.g. the statuses table. Usually these are not editable within the GUI. """ - _init_societal_benefit_areas(db.session) _init_roles(db.session) _init_statuses(db.session) @@ -100,53 +95,6 @@ def _init_roles(session: Session) -> None: session.commit() -def _init_societal_benefit_areas(session: Session) -> None: - """Insert Societal Benefit Areas from GEOSS framework. - - https://en.wikipedia.org/wiki/Global_Earth_Observation_System_of_Systems - """ - # Add all areas: - session.add_all( - [ - SocietalBenefitArea( - id=sba_name, - ) - for sba_name in IAOA_SBA_FRAMEWORK.keys() - ], - ) - - # Flush guarantees that these records will be present in the transaction before we - # add the subsequent child records. - session.flush() - - for sba_name, sba in IAOA_SBA_FRAMEWORK.items(): - # Add all of `sba`'s sub-areas: - session.add_all( - [ - SocietalBenefitSubArea( - id=sub_area_name, - societal_benefit_area_id=sba_name, - ) - for sub_area_name in sba.keys() - ], - ) - session.flush() - - for sub_area_name, sub_area in sba.items(): - # Add all of `sub_area`'s key objectives: - session.add_all( - [ - SocietalBenefitKeyObjective( - id=key_objective_name, - societal_benefit_subarea_id=sub_area_name, - ) - for key_objective_name in sub_area - ], - ) - - session.commit() - - def _init_test_assessment(session: Session) -> None: test_user = _get_or_create_test_user(session) @@ -195,7 +143,6 @@ def _init_test_assessment(session: Session) -> None: sba = NodeSubtypeSocietalBenefitArea( title="This is a test SBA", short_name="Test SBA", - societal_benefit_area_id=next(iter(IAOA_SBA_FRAMEWORK.keys())), type=NodeType.SOCIETAL_BENEFIT_AREA, created_by=test_user, )