Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TRANSFER_ASSETS=False
TRANSFER_SURFACE_WATER_DATA=True
TRANSFER_HYDRAULICS_DATA=True
TRANSFER_CHEMISTRY_SAMPLEINFO=True
TRANSFER_MAJOR_CHEMISTRY=True
TRANSFER_RADIONUCLIDES=True
TRANSFER_NGWMN_VIEWS=True
TRANSFER_WATERLEVELS_PRESSURE_DAILY=True
Expand Down
104 changes: 104 additions & 0 deletions alembic/versions/a7b8c9d0e1f2_create_nma_major_chemistry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
"""Create legacy NMA_MajorChemistry table.

Revision ID: a7b8c9d0e1f2
Revises: f3b4c5d6e7f8
Create Date: 2026-03-01 02:00:00.000000
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op
from sqlalchemy import inspect
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = "a7b8c9d0e1f2"
down_revision: Union[str, Sequence[str], None] = "f1a2b3c4d5e6"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Create the legacy major chemistry table."""
bind = op.get_bind()
inspector = inspect(bind)
if not inspector.has_table("NMA_MajorChemistry"):
op.create_table(
"NMA_MajorChemistry",
sa.Column(
"SamplePtID",
postgresql.UUID(as_uuid=True),
sa.ForeignKey(
"NMA_Chemistry_SampleInfo.SamplePtID", ondelete="CASCADE"
),
nullable=False,
),
sa.Column("SamplePointID", sa.String(length=10), nullable=True),
sa.Column("Analyte", sa.String(length=50), nullable=True),
sa.Column("Symbol", sa.String(length=50), nullable=True),
sa.Column(
"SampleValue", sa.Float(), nullable=True, server_default=sa.text("0")
),
sa.Column("Units", sa.String(length=50), nullable=True),
sa.Column("Uncertainty", sa.Float(), nullable=True),
sa.Column("AnalysisMethod", sa.String(length=255), nullable=True),
sa.Column("AnalysisDate", sa.DateTime(), nullable=True),
sa.Column("Notes", sa.String(length=255), nullable=True),
sa.Column(
"Volume", sa.Integer(), nullable=True, server_default=sa.text("0")
),
sa.Column("VolumeUnit", sa.String(length=50), nullable=True),
sa.Column("OBJECTID", sa.Integer(), nullable=True, unique=True),
sa.Column(
"GlobalID",
postgresql.UUID(as_uuid=True),
nullable=False,
primary_key=True,
),
sa.Column("AnalysesAgency", sa.String(length=50), nullable=True),
sa.Column("WCLab_ID", sa.String(length=25), nullable=True),
)
op.create_index(
"MajorChemistry$AnalysesAgency",
"NMA_MajorChemistry",
["AnalysesAgency"],
)
op.create_index(
"MajorChemistry$Analyte",
"NMA_MajorChemistry",
["Analyte"],
)
op.create_index(
"MajorChemistry$Chemistry SampleInfoMajorChemistry",
"NMA_MajorChemistry",
["SamplePtID"],
)
op.create_index(
"MajorChemistry$SamplePointID",
"NMA_MajorChemistry",
["SamplePointID"],
)
op.create_index(
"MajorChemistry$SamplePointIDAnalyte",
"NMA_MajorChemistry",
["SamplePointID", "Analyte"],
)
op.create_index(
"MajorChemistry$SamplePtID",
"NMA_MajorChemistry",
["SamplePtID"],
)
op.create_index(
"MajorChemistry$WCLab_ID",
"NMA_MajorChemistry",
["WCLab_ID"],
)


def downgrade() -> None:
"""Drop the legacy major chemistry table."""
bind = op.get_bind()
inspector = inspect(bind)
if inspector.has_table("NMA_MajorChemistry"):
op.drop_table("NMA_MajorChemistry")
55 changes: 55 additions & 0 deletions db/nma_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ class ChemistrySampleInfo(Base):
passive_deletes=True,
)

major_chemistries: Mapped[List["NMAMajorChemistry"]] = relationship(
"NMAMajorChemistry",
back_populates="chemistry_sample_info",
cascade="all, delete-orphan",
passive_deletes=True,
)

@validates("thing_id")
def validate_thing_id(self, key, value):
"""Prevent orphan ChemistrySampleInfo - must have a parent Thing."""
Expand Down Expand Up @@ -455,4 +462,52 @@ def validate_sample_pt_id(self, key, value):
return value


class NMAMajorChemistry(Base):
"""
Legacy MajorChemistry table from NM_Aquifer_Dev_DB.
"""

__tablename__ = "NMA_MajorChemistry"

global_id: Mapped[uuid.UUID] = mapped_column(
"GlobalID", UUID(as_uuid=True), primary_key=True
)
sample_pt_id: Mapped[uuid.UUID] = mapped_column(
"SamplePtID",
UUID(as_uuid=True),
ForeignKey("NMA_Chemistry_SampleInfo.SamplePtID", ondelete="CASCADE"),
nullable=False,
)
sample_point_id: Mapped[Optional[str]] = mapped_column("SamplePointID", String(10))
analyte: Mapped[Optional[str]] = mapped_column("Analyte", String(50))
symbol: Mapped[Optional[str]] = mapped_column("Symbol", String(50))
sample_value: Mapped[Optional[float]] = mapped_column(
"SampleValue", Float, server_default=text("0")
)
units: Mapped[Optional[str]] = mapped_column("Units", String(50))
uncertainty: Mapped[Optional[float]] = mapped_column("Uncertainty", Float)
analysis_method: Mapped[Optional[str]] = mapped_column(
"AnalysisMethod", String(255)
)
analysis_date: Mapped[Optional[datetime]] = mapped_column("AnalysisDate", DateTime)
notes: Mapped[Optional[str]] = mapped_column("Notes", String(255))
volume: Mapped[Optional[int]] = mapped_column(
"Volume", Integer, server_default=text("0")
)
volume_unit: Mapped[Optional[str]] = mapped_column("VolumeUnit", String(50))
object_id: Mapped[Optional[int]] = mapped_column("OBJECTID", Integer, unique=True)
analyses_agency: Mapped[Optional[str]] = mapped_column("AnalysesAgency", String(50))
wclab_id: Mapped[Optional[str]] = mapped_column("WCLab_ID", String(25))

chemistry_sample_info: Mapped["ChemistrySampleInfo"] = relationship(
"ChemistrySampleInfo", back_populates="major_chemistries"
)

@validates("sample_pt_id")
def validate_sample_pt_id(self, key, value):
if value is None:
raise ValueError("NMAMajorChemistry requires a SamplePtID")
return value


# ============= EOF =============================================
Loading
Loading