Skip to content

Commit 24cff28

Browse files
Merge pull request #16 from petercarbsmith/Peter-dev
adding database.py and config.py to datamodels folder. modifying ca_b…
2 parents 4f9f759 + eb90e0f commit 24cff28

19 files changed

Lines changed: 948 additions & 65 deletions
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""added test column to Resource
2+
3+
Revision ID: 5a6668dac367
4+
Revises: 184417c6d044
5+
Create Date: 2025-12-22 17:49:18.175092
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '5a6668dac367'
16+
down_revision: Union[str, Sequence[str], None] = '184417c6d044'
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
"""Upgrade schema."""
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.drop_column('landiq_record', 'test')
25+
op.add_column('resource', sa.Column('test', sa.Text(), nullable=True))
26+
# ### end Alembic commands ###
27+
28+
29+
def downgrade() -> None:
30+
"""Downgrade schema."""
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.drop_column('resource', 'test')
33+
op.add_column('landiq_record', sa.Column('test', sa.TEXT(), autoincrement=False, nullable=True))
34+
# ### end Alembic commands ###

alembic/versions/fc422d3d9ea6_adding_infrastructure_i_think.py

Lines changed: 346 additions & 0 deletions
Large diffs are not rendered by default.

census.survey.mmd

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from pydantic_settings import BaseSettings, SettingsConfigDict
2+
from typing import Optional
3+
4+
class Settings(BaseSettings):
5+
"""
6+
Application settings and configuration for the datamodels package.
7+
8+
Uses Pydantic Settings to load configuration from environment variables
9+
and .env files.
10+
"""
11+
POSTGRES_USER: str = "postgres"
12+
POSTGRES_PASSWORD: str = "postgres"
13+
POSTGRES_DB: str = "biositing"
14+
POSTGRES_HOST: str = "db"
15+
POSTGRES_PORT: int = 5432
16+
DATABASE_URL: Optional[str] = None
17+
18+
model_config = SettingsConfigDict(
19+
env_file=".env",
20+
env_file_encoding="utf-8",
21+
extra="ignore",
22+
case_sensitive=True
23+
)
24+
25+
@property
26+
def database_url(self) -> str:
27+
"""
28+
Constructs the database URL from components if not explicitly set.
29+
"""
30+
if self.DATABASE_URL:
31+
return self.DATABASE_URL
32+
return f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}:{self.POSTGRES_PORT}/{self.POSTGRES_DB}"
33+
34+
settings = Settings()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from sqlmodel import SQLModel, create_engine, Session
2+
from .config import settings
3+
4+
# Create engine using the database URL from settings
5+
# echo=False by default to avoid verbose SQL logging
6+
engine = create_engine(settings.database_url, echo=False)
7+
8+
def get_session():
9+
"""
10+
Dependency that yields a database session.
11+
Useful for FastAPI dependencies.
12+
"""
13+
with Session(engine) as session:
14+
yield session
15+
16+
def create_db_and_tables():
17+
"""
18+
Create all tables defined in SQLModel metadata.
19+
"""
20+
SQLModel.metadata.create_all(engine)
21+
22+
def get_engine():
23+
"""
24+
Returns the database engine.
25+
"""
26+
return engine

src/ca_biositing/datamodels/ca_biositing/datamodels/linkml/ca_biositing.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ imports:
3030
- modules/aim1_records
3131
- modules/aim2_records
3232
- modules/external_data
33+
- modules/infrastructure
34+
- modules/geography

src/ca_biositing/datamodels/ca_biositing/datamodels/linkml/modules/resource_information.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ classes:
2626
- resource_class_id
2727
- resource_subclass_id
2828
- note
29+
- test
2930

3031
ResourceClass:
3132
is_a: LookupBase
@@ -100,6 +101,10 @@ slots:
100101
range: integer
101102
description: Reference to ResourceSubclass.
102103

104+
test:
105+
range: string
106+
description: Test field.
107+
103108
#ResourceAvailability slots
104109

105110
resource_id:

src/ca_biositing/datamodels/ca_biositing/datamodels/schemas/generated/aim1_records.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,7 @@ class Resource(BaseEntity):
896896
resource_class_id = Column(Integer())
897897
resource_subclass_id = Column(Integer())
898898
note = Column(Text())
899+
test = Column(Text())
899900
id = Column(Integer(), primary_key=True, nullable=False )
900901
created_at = Column(DateTime())
901902
updated_at = Column(DateTime())
@@ -904,7 +905,7 @@ class Resource(BaseEntity):
904905

905906

906907
def __repr__(self):
907-
return f"Resource(name={self.name},primary_crop_id={self.primary_crop_id},resource_class_id={self.resource_class_id},resource_subclass_id={self.resource_subclass_id},note={self.note},id={self.id},created_at={self.created_at},updated_at={self.updated_at},etl_run_id={self.etl_run_id},lineage_group_id={self.lineage_group_id},)"
908+
return f"Resource(name={self.name},primary_crop_id={self.primary_crop_id},resource_class_id={self.resource_class_id},resource_subclass_id={self.resource_subclass_id},note={self.note},test={self.test},id={self.id},created_at={self.created_at},updated_at={self.updated_at},etl_run_id={self.etl_run_id},lineage_group_id={self.lineage_group_id},)"
908909

909910

910911

src/ca_biositing/datamodels/ca_biositing/datamodels/schemas/generated/aim2_records.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ class Resource(BaseEntity):
922922
resource_class_id = Column(Integer())
923923
resource_subclass_id = Column(Integer())
924924
note = Column(Text())
925+
test = Column(Text())
925926
id = Column(Integer(), primary_key=True, nullable=False )
926927
created_at = Column(DateTime())
927928
updated_at = Column(DateTime())
@@ -930,7 +931,7 @@ class Resource(BaseEntity):
930931

931932

932933
def __repr__(self):
933-
return f"Resource(name={self.name},primary_crop_id={self.primary_crop_id},resource_class_id={self.resource_class_id},resource_subclass_id={self.resource_subclass_id},note={self.note},id={self.id},created_at={self.created_at},updated_at={self.updated_at},etl_run_id={self.etl_run_id},lineage_group_id={self.lineage_group_id},)"
934+
return f"Resource(name={self.name},primary_crop_id={self.primary_crop_id},resource_class_id={self.resource_class_id},resource_subclass_id={self.resource_subclass_id},note={self.note},test={self.test},id={self.id},created_at={self.created_at},updated_at={self.updated_at},etl_run_id={self.etl_run_id},lineage_group_id={self.lineage_group_id},)"
934935

935936

936937

0 commit comments

Comments
 (0)