Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables - Simplify inheritance structure #112

Merged
merged 3 commits into from
Aug 22, 2024
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
2 changes: 1 addition & 1 deletion snowexsql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from ._version import __version__ # noqa

__author__ = """Micah Johnson"""
__author__ = """SnowEx SQL Development Team"""
__version__ = __version__
2 changes: 1 addition & 1 deletion snowexsql/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sqlalchemy import MetaData, create_engine
from sqlalchemy.orm import sessionmaker

from snowexsql.tables import Base
from snowexsql.tables.base import Base


def initialize(engine):
Expand Down
5 changes: 0 additions & 5 deletions snowexsql/tables/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from .base import Base, Measurement, SingleLocationData, SnowData
from .image_data import ImageData
from .layer_data import LayerData
from .point_data import PointData
from .site_data import SiteData

__all__ = [
'Base',
'ImageData',
'LayerData',
'Measurement',
'PointData',
'SingleLocationData',
'SiteData'
'SnowData',
]
23 changes: 14 additions & 9 deletions snowexsql/tables/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,31 @@

from geoalchemy2 import Geometry
from sqlalchemy import Column, Date, DateTime, Float, Integer, String, Time
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.sql import func

Base = declarative_base()


class SnowData(object):
class Base(DeclarativeBase):
"""
Base class for which all data will have these attributes
"""
site_name = Column(String(250))
date = Column(Date)
# SQL Alchemy
__table_args__ = {"schema": "public"}

# Primary Key
id = Column(Integer, primary_key=True)

# Standard table columns
time_created = Column(DateTime(timezone=True), server_default=func.now())
time_updated = Column(DateTime(timezone=True), onupdate=func.now())
id = Column(Integer, primary_key=True)
doi = Column(String(50))

date_accessed = Column(Date)
site_name = Column(String(250))
date = Column(Date)
doi = Column(String(50))


class SingleLocationData(SnowData):
class SingleLocationData:
"""
Base class for points and profiles
"""
Expand Down
5 changes: 2 additions & 3 deletions snowexsql/tables/image_data.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from geoalchemy2 import Raster
from sqlalchemy import Column, String

from .base import Base, Measurement, SnowData
from .base import Base, Measurement


class ImageData(SnowData, Measurement, Base):
class ImageData(Base, Measurement):
"""
Class representing the images table. This table holds all images/rasters
"""
__tablename__ = 'images'
__table_args__ = {"schema": "public"}
raster = Column(Raster)
description = Column(String(1000))
1 change: 0 additions & 1 deletion snowexsql/tables/layer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class LayerData(SingleLocationData, Measurement, Base):
temperature etc...
"""
__tablename__ = 'layers'
__table_args__ = {"schema": "public"}

depth = Column(Float)
site_id = Column(String(50))
Expand Down
1 change: 0 additions & 1 deletion snowexsql/tables/point_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class PointData(SingleLocationData, Measurement, Base):
e.g. snow depths
"""
__tablename__ = 'points'
__table_args__ = {"schema": "public"}

version_number = Column(Integer)
equipment = Column(String(50))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from sqlalchemy import Table

from snowexsql.db import *
from snowexsql.db import get_db, get_table_attributes
from snowexsql.tables import ImageData, LayerData, PointData, SiteData
from .sql_test_base import DBSetup

Expand Down
Loading