Skip to content

Commit

Permalink
Tables - LayerData - Drop sample and flag columns
Browse files Browse the repository at this point in the history
This gets rid of columns sample_a|b|c and the flags column in favor of
storing three values for identical top and bottom height. The flags
column information will move to the comments. Also adding not-null and
index constraints for better data integrity.

Fixes #165
  • Loading branch information
jomey committed Oct 23, 2024
1 parent d759654 commit 8cf4bc9
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
14 changes: 5 additions & 9 deletions snowexsql/tables/layer_data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from sqlalchemy import Column, Float, Integer, String, ForeignKey
from sqlalchemy import Column, Float, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship

from .base import Base
from .doi import HasDOI
from .measurement_type import HasMeasurementType
from .instrument import HasInstrument
from .measurement_type import HasMeasurementType


class LayerData(
Expand All @@ -18,15 +18,11 @@ class LayerData(
"""
__tablename__ = 'layers'

depth = Column(Float)
depth = Column(Float, nullable=False, index=True)
pit_id = Column(String(50))
bottom_depth = Column(Float)
comments = Column(String(1000))
sample_a = Column(String(20))
sample_b = Column(String(20))
sample_c = Column(String(20))
value = Column(String(50))
flags = Column(String(20))
comments = Column(Text)
value = Column(Text, nullable=False, index=True)

# Link the site id with a foreign key
site_id = Column(
Expand Down
2 changes: 1 addition & 1 deletion tests/db_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def populated_layer(self, db):
'geom': WKTElement(
"POINT(747987.6190615438 4324061.7062127385)", srid=26912
),
'depth': 100,
'value': '42.5',
'sample_a': '42.5'
}
self._add_entry(
db.url, LayerData, 'fakeinstrument', ["TEST"],
Expand Down
2 changes: 0 additions & 2 deletions tests/factories/layer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class Meta:
bottom_depth = 90.0
comments = 'Layer comment'
value = '40'
flags = 'Sample'
sample_a = '42'

measurement_type = factory.SubFactory(
MeasurementTypeFactory, name='Density', units='kg/m3'
Expand Down
6 changes: 0 additions & 6 deletions tests/tables/test_layer_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def test_comments_attribute(self):
def test_value_attribute(self):
assert self.subject.value == self.attributes.value

def test_sample_a_attribute(self):
assert self.subject.sample_a == self.attributes.sample_a

def test_flags_attribute(self):
assert self.subject.flags == self.attributes.flags

def test_has_site(self):
assert isinstance(self.subject.site, Site)
assert self.subject.site.name == self.attributes.site.name
Expand Down

0 comments on commit 8cf4bc9

Please sign in to comment.