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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,9 @@ python -m transfers.transfer
```

Configure the `.env` file with the appropriate credentials before running transfers.

To drop the existing schema and rebuild from migrations before transferring data, set:

```bash
export DROP_AND_REBUILD_DB=true
```
6 changes: 5 additions & 1 deletion admin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
GroupAdmin,
NotesAdmin,
SampleAdmin,
HydraulicsDataAdmin,
ChemistrySampleInfoAdmin,
GeologicFormationAdmin,
DataProvenanceAdmin,
Expand Down Expand Up @@ -63,7 +64,7 @@
from db.group import Group
from db.notes import Notes
from db.sample import Sample
from db.nma_legacy import ChemistrySampleInfo, SurfaceWaterData
from db.nma_legacy import ChemistrySampleInfo, NMAHydraulicsData, SurfaceWaterData
from db.geologic_formation import GeologicFormation
from db.data_provenance import DataProvenance
from db.transducer import TransducerObservation
Expand Down Expand Up @@ -133,6 +134,9 @@ def create_admin(app):
admin.add_view(ChemistrySampleInfoAdmin(ChemistrySampleInfo))
admin.add_view(SurfaceWaterDataAdmin(SurfaceWaterData))

# Hydraulics
admin.add_view(HydraulicsDataAdmin(NMAHydraulicsData))

# Field
admin.add_view(FieldEventAdmin(FieldEvent))
admin.add_view(FieldActivityAdmin(FieldActivity))
Expand Down
2 changes: 2 additions & 0 deletions admin/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from admin.views.group import GroupAdmin
from admin.views.notes import NotesAdmin
from admin.views.sample import SampleAdmin
from admin.views.hydraulicsdata import HydraulicsDataAdmin
from admin.views.chemistry_sampleinfo import ChemistrySampleInfoAdmin
from admin.views.geologic_formation import GeologicFormationAdmin
from admin.views.data_provenance import DataProvenanceAdmin
Expand Down Expand Up @@ -58,6 +59,7 @@
"GroupAdmin",
"NotesAdmin",
"SampleAdmin",
"HydraulicsDataAdmin",
"ChemistrySampleInfoAdmin",
"GeologicFormationAdmin",
"DataProvenanceAdmin",
Expand Down
129 changes: 129 additions & 0 deletions admin/views/hydraulicsdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# ===============================================================================
# Copyright 2026
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
"""
HydraulicsDataAdmin view for legacy NMA_HydraulicsData.
"""
from admin.views.base import OcotilloModelView


class HydraulicsDataAdmin(OcotilloModelView):
"""
Admin view for NMAHydraulicsData model.
"""

# ========== Basic Configuration ==========

name = "Hydraulics Data"
label = "Hydraulics Data"
icon = "fa fa-tint"

can_create = False
can_edit = False
can_delete = False

# ========== List View ==========

column_list = [
"global_id",
"point_id",
"hydraulic_unit",
"hydraulic_unit_type",
"test_top",
"test_bottom",
"t_ft2_d",
"k_darcy",
"data_source",
]

column_sortable_list = [
"global_id",
"point_id",
"hydraulic_unit",
"hydraulic_unit_type",
"test_top",
"test_bottom",
"t_ft2_d",
"k_darcy",
"data_source",
]

search_fields = [
"global_id",
"point_id",
"hydraulic_unit",
"hydraulic_remarks",
]

column_filters = [
"hydraulic_unit",
"hydraulic_unit_type",
"data_source",
]

can_export = True
export_types = ["csv", "excel"]

page_size = 50
page_size_options = [25, 50, 100, 200]

# ========== Form View ==========

fields = [
"global_id",
"point_id",
"hydraulic_unit",
"hydraulic_unit_type",
"hydraulic_remarks",
"test_top",
"test_bottom",
"t_ft2_d",
"s_dimensionless",
"ss_ft_1",
"sy_decimalfractn",
"kh_ft_d",
"kv_ft_d",
"hl_day_1",
"hd_ft2_d",
"cs_gal_d_ft",
"p_decimal_fraction",
"k_darcy",
"data_source",
]

labels = {
"global_id": "GlobalID",
"point_id": "PointID",
"hydraulic_unit": "HydraulicUnit",
"hydraulic_unit_type": "HydraulicUnitType",
"hydraulic_remarks": "Hydraulic Remarks",
"test_top": "TestTop",
"test_bottom": "TestBottom",
"t_ft2_d": "T (ft2/d)",
"s_dimensionless": "S (dimensionless)",
"ss_ft_1": "Ss (ft-1)",
"sy_decimalfractn": "Sy (decimalfractn)",
"kh_ft_d": "KH (ft/d)",
"kv_ft_d": "KV (ft/d)",
"hl_day_1": "HL (day-1)",
"hd_ft2_d": "HD (ft2/d)",
"cs_gal_d_ft": "Cs (gal/d/ft)",
"p_decimal_fraction": "P (decimal fraction)",
"k_darcy": "k (darcy)",
"data_source": "Data Source",
}


# ============= EOF =============================================
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def upgrade() -> None:
# Create NMA_MinorTraceChemistry table
op.create_table(
"NMA_MinorTraceChemistry",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("GlobalID", postgresql.UUID(as_uuid=True), nullable=False),
sa.Column(
"chemistry_sample_info_id",
postgresql.UUID(as_uuid=True),
Expand All @@ -100,7 +100,7 @@ def upgrade() -> None:
sa.Column("uncertainty", sa.Float(), nullable=True),
sa.Column("volume", sa.Float(), nullable=True),
sa.Column("volume_unit", sa.String(20), nullable=True),
sa.PrimaryKeyConstraint("id"),
sa.PrimaryKeyConstraint("GlobalID"),
sa.ForeignKeyConstraint(
["chemistry_sample_info_id"],
["NMA_Chemistry_SampleInfo.SamplePtID"],
Expand Down
61 changes: 61 additions & 0 deletions alembic/versions/d1a2b3c4e5f6_create_nma_hydraulicsdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Create legacy NMA_HydraulicsData table.

Revision ID: d1a2b3c4e5f6
Revises: c9f1d2e3a4b5
Create Date: 2026-02-10 04:00:00.000000
"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect

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


def upgrade() -> None:
"""Create the legacy hydraulics data table used for backfill."""
bind = op.get_bind()
inspector = inspect(bind)
if not inspector.has_table("NMA_HydraulicsData"):
op.create_table(
"NMA_HydraulicsData",
sa.Column("GlobalID", sa.String(length=40), primary_key=True),
sa.Column("PointID", sa.String(length=50), nullable=True),
sa.Column("HydraulicUnit", sa.String(length=18), nullable=True),
sa.Column(
"thing_id",
sa.Integer(),
sa.ForeignKey("thing.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("TestTop", sa.SmallInteger(), nullable=False),
sa.Column("TestBottom", sa.SmallInteger(), nullable=False),
sa.Column("HydraulicUnitType", sa.String(length=2), nullable=True),
sa.Column("Hydraulic Remarks", sa.String(length=200), nullable=True),
sa.Column("T (ft2/d)", sa.Float(), nullable=True),
sa.Column("S (dimensionless)", sa.Float(), nullable=True),
sa.Column("Ss (ft-1)", sa.Float(), nullable=True),
sa.Column("Sy (decimalfractn)", sa.Float(), nullable=True),
sa.Column("KH (ft/d)", sa.Float(), nullable=True),
sa.Column("KV (ft/d)", sa.Float(), nullable=True),
sa.Column("HL (day-1)", sa.Float(), nullable=True),
sa.Column("HD (ft2/d)", sa.Float(), nullable=True),
sa.Column("Cs (gal/d/ft)", sa.Float(), nullable=True),
sa.Column("P (decimal fraction)", sa.Float(), nullable=True),
sa.Column("k (darcy)", sa.Float(), nullable=True),
sa.Column("Data Source", sa.String(length=255), nullable=True),
)


def downgrade() -> None:
"""Drop the legacy hydraulics data table."""
bind = op.get_bind()
inspector = inspect(bind)
if inspector.has_table("NMA_HydraulicsData"):
op.drop_table("NMA_HydraulicsData")
72 changes: 72 additions & 0 deletions alembic/versions/d2f4c6a8b1c2_make_minor_trace_globalid_pk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Make GlobalID the primary key for NMA_MinorTraceChemistry.

Revision ID: d2f4c6a8b1c2
Revises: 6e1c90f6135a
Create Date: 2026-03-01 00:00:00.000000
"""

from typing import Sequence, Union

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

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


def upgrade() -> None:
"""Upgrade schema."""
bind = op.get_bind()
inspector = inspect(bind)
if not inspector.has_table("NMA_MinorTraceChemistry"):
return

columns = {col["name"] for col in inspector.get_columns("NMA_MinorTraceChemistry")}
if "GlobalID" not in columns:
op.add_column(
"NMA_MinorTraceChemistry",
sa.Column("GlobalID", postgresql.UUID(as_uuid=True), nullable=False),
)

pk = inspector.get_pk_constraint("NMA_MinorTraceChemistry")
pk_name = pk.get("name")
if pk_name:
op.drop_constraint(pk_name, "NMA_MinorTraceChemistry", type_="primary")

if "id" in columns:
op.drop_column("NMA_MinorTraceChemistry", "id")

op.create_primary_key(
"NMA_MinorTraceChemistry_pkey",
"NMA_MinorTraceChemistry",
["GlobalID"],
)


def downgrade() -> None:
"""Downgrade schema."""
bind = op.get_bind()
inspector = inspect(bind)
if not inspector.has_table("NMA_MinorTraceChemistry"):
return

op.drop_constraint(
"NMA_MinorTraceChemistry_pkey",
"NMA_MinorTraceChemistry",
type_="primary",
)
op.add_column(
"NMA_MinorTraceChemistry",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
)
op.create_primary_key(
"NMA_MinorTraceChemistry_id_pkey",
"NMA_MinorTraceChemistry",
["id"],
)
op.drop_column("NMA_MinorTraceChemistry", "GlobalID")
Loading
Loading