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

refacto: begin refacto uniformisation repositories #218

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
###############################################################################################
# these values are used in the local docker env. You can use "localhost" hostname
# if you run the application without docker
POSTGRES_DRIVER=postgresql
POSTGRES_HOSTNAME=postgres_bloom
POSTGRES_USER=bloom_user
POSTGRES_PASSWORD=bloom
Expand Down
1 change: 1 addition & 0 deletions backend/bloom/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Settings(BaseSettings):
default=5432)

postgres_db:str = Field(min_length=1,max_length=32,pattern=r'^(?:[a-zA-Z]|_)[\w\d_]*$')
postgres_schema:str = Field(default='public')
srid: int = Field(default=4326)
spire_token:str = Field(default='')
data_folder:str=Field(default=str(Path(__file__).parent.parent.parent.joinpath('./data')))
Expand Down
2 changes: 1 addition & 1 deletion backend/bloom/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from bloom.services.metrics import MetricsService
from bloom.usecase.GenerateAlerts import GenerateAlerts
from dependency_injector import containers, providers
import redis


class UseCases(containers.DeclarativeContainer):
Expand All @@ -25,7 +26,6 @@ class UseCases(containers.DeclarativeContainer):

vessel_repository = providers.Factory(
VesselRepository,
session_factory=db.provided.session,
)

alert_repository = providers.Factory(
Expand Down
14 changes: 14 additions & 0 deletions backend/bloom/infra/database/sql_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class Vessel(Base):
__tablename__ = "dim_vessel"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
mmsi = Column("mmsi", Integer)
ship_name = Column("ship_name", String, nullable=False)
Expand All @@ -46,6 +47,7 @@ class Vessel(Base):

class Alert(Base):
__tablename__ = "alert"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True, index=True)
timestamp = Column("timestamp", DateTime)
mpa_id = Column("mpa_id", Integer)
Expand All @@ -54,6 +56,7 @@ class Alert(Base):

class Port(Base):
__tablename__ = "dim_port"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True, index=True)
name = Column("name", String, nullable=False)
locode = Column("locode", String, nullable=False)
Expand All @@ -70,6 +73,7 @@ class Port(Base):

class SpireAisData(Base):
__tablename__ = "spire_ais_data"
__table_args__ = {'schema': settings.postgres_schema}

id = Column("id", Integer, primary_key=True)
spire_update_statement = Column("spire_update_statement", DateTime(timezone=True))
Expand Down Expand Up @@ -107,6 +111,7 @@ class SpireAisData(Base):

class Zone(Base):
__tablename__ = "dim_zone"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
category = Column("category", String, nullable=False)
sub_category = Column("sub_category", String)
Expand All @@ -119,6 +124,7 @@ class Zone(Base):

class WhiteZone(Base):
__tablename__ = "dim_white_zone"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
geometry = Column("geometry", Geometry(geometry_type="GEOMETRY", srid=settings.srid))
created_at = Column("created_at", DateTime(timezone=True), server_default=func.now())
Expand All @@ -127,6 +133,7 @@ class WhiteZone(Base):

class VesselPosition(Base):
__tablename__ = "vessel_positions"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
timestamp = Column("timestamp", DateTime(timezone=True), nullable=False)
accuracy = Column("accuracy", String)
Expand All @@ -146,6 +153,7 @@ class VesselPosition(Base):

class VesselData(Base):
__tablename__ = "vessel_data"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
timestamp = Column("timestamp", DateTime(timezone=True), nullable=False)
ais_class = Column("ais_class", String)
Expand All @@ -164,6 +172,7 @@ class VesselData(Base):

class VesselVoyage(Base):
__tablename__ = "vessel_voyage"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
timestamp = Column("timestamp", DateTime(timezone=True), nullable=False)
destination = Column("destination", String)
Expand All @@ -175,6 +184,7 @@ class VesselVoyage(Base):

class Excursion(Base):
__tablename__ = "fct_excursion"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
vessel_id = Column("vessel_id", Integer, ForeignKey("dim_vessel.id"), nullable=False)
departure_port_id = Column("departure_port_id", Integer, ForeignKey("dim_port.id"))
Expand All @@ -199,6 +209,7 @@ class Excursion(Base):

class Segment(Base):
__tablename__ = "fct_segment"
__table_args__ = {'schema': settings.postgres_schema}
id = Column("id", Integer, primary_key=True)
excursion_id = Column("excursion_id", Integer, ForeignKey("fct_excursion.id"), nullable=False)
timestamp_start = Column("timestamp_start", DateTime(timezone=True))
Expand All @@ -224,6 +235,7 @@ class Segment(Base):

class TaskExecution(Base):
__tablename__ = "tasks_executions"
__table_args__ = {'schema': settings.postgres_schema}
task_name = Column("task_name", String, primary_key=True)
point_in_time = Column("point_in_time", DateTime(timezone=True))
created_at = Column("created_at", DateTime(timezone=True), server_default=func.now())
Expand All @@ -234,6 +246,7 @@ class RelSegmentZone(Base):
__tablename__ = "rel_segment_zone"
__table_args__ = (
PrimaryKeyConstraint('segment_id', 'zone_id'),
{'schema': settings.postgres_schema}
)
segment_id = Column("segment_id", Integer, ForeignKey("fct_segment.id"), nullable=False)
zone_id = Column("zone_id", Integer, ForeignKey("dim_zone.id"), nullable=False)
Expand All @@ -253,6 +266,7 @@ class RelSegmentZone(Base):

class MetricsVesselInActivity(Base):
__table__ = vessel_in_activity_request
__table_args__ = {'schema': settings.postgres_schema}
#vessel_id: Mapped[Optional[int]]
#total_time_at_sea: Mapped[Optional[timedelta]]

Loading
Loading