diff --git a/alembic/env.py b/alembic/env.py index 50ac4f9..e566d3d 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -100,7 +100,7 @@ def create_hypertable_ops(table_name, hypertable_meta, is_existing=False): # Create hypertable SQL hypertable_sql = ( - f"SELECT create_hypertable('{table_name}', by_range('{time_col}', INTERVAL '{chunk_interval}'));" + f"SELECT create_hypertable('{table_name}', by_range('{time_col}', INTERVAL '{chunk_interval}'),create_default_indexes => false);" ) upgrade_ops.append(ops.ExecuteSQLOp(hypertable_sql)) diff --git a/models/atlas_delay.py b/models/atlas_delay.py index 14b0d0d..366eeca 100644 --- a/models/atlas_delay.py +++ b/models/atlas_delay.py @@ -10,7 +10,7 @@ class AtlasDelay(Base): __tablename__ = 'ihr_atlas_delay' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/atlas_delay_alarms.py b/models/atlas_delay_alarms.py index ef71bf7..5f66174 100644 --- a/models/atlas_delay_alarms.py +++ b/models/atlas_delay_alarms.py @@ -8,7 +8,7 @@ class AtlasDelayAlarms(Base): __tablename__ = 'ihr_atlas_delay_alarms' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/atlas_location.py b/models/atlas_location.py index a2e54f1..df55176 100644 --- a/models/atlas_location.py +++ b/models/atlas_location.py @@ -7,7 +7,7 @@ class AtlasLocation(Base): __indexes__ = [ { 'name': 'ihr_atlas_location_af_name_type_idx', - 'columns': ['af', 'name','type'], + 'columns': ['af','type'], },] id = Column(Integer, primary_key=True, autoincrement=True) name = Column( diff --git a/models/delay.py b/models/delay.py index 8a3a70a..847edc4 100644 --- a/models/delay.py +++ b/models/delay.py @@ -8,7 +8,7 @@ class Delay(Base): __tablename__ = 'ihr_delay' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/delay_alarms.py b/models/delay_alarms.py index a3f7266..ccf2776 100644 --- a/models/delay_alarms.py +++ b/models/delay_alarms.py @@ -11,7 +11,7 @@ class DelayAlarms(Base): __tablename__ = 'ihr_delay_alarms' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __indexes__ = [ diff --git a/models/forwarding.py b/models/forwarding.py index c2b085d..bf29825 100644 --- a/models/forwarding.py +++ b/models/forwarding.py @@ -8,7 +8,7 @@ class Forwarding(Base): __tablename__ = 'ihr_forwarding' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/forwarding_alarms.py b/models/forwarding_alarms.py index 8adec29..50cb33b 100644 --- a/models/forwarding_alarms.py +++ b/models/forwarding_alarms.py @@ -8,7 +8,7 @@ class ForwardingAlarms(Base): __tablename__ = 'ihr_forwarding_alarms' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __indexes__ = [ diff --git a/models/hegemony.py b/models/hegemony.py index 07ce68d..be1a70b 100644 --- a/models/hegemony.py +++ b/models/hegemony.py @@ -8,7 +8,7 @@ class Hegemony(Base): __tablename__ = 'ihr_hegemony' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/hegemony_alarms.py b/models/hegemony_alarms.py index 5e69ef0..7c65a20 100644 --- a/models/hegemony_alarms.py +++ b/models/hegemony_alarms.py @@ -8,7 +8,7 @@ class HegemonyAlarms(Base): __tablename__ = 'ihr_hegemony_alarms' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/hegemony_cone.py b/models/hegemony_cone.py index 253d1ec..90546f8 100644 --- a/models/hegemony_cone.py +++ b/models/hegemony_cone.py @@ -9,7 +9,7 @@ class HegemonyCone(Base): __tablename__ = 'ihr_hegemonycone' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __indexes__ = [ diff --git a/models/hegemony_country.py b/models/hegemony_country.py index 543a08d..f6c239e 100644 --- a/models/hegemony_country.py +++ b/models/hegemony_country.py @@ -8,7 +8,7 @@ class HegemonyCountry(Base): __tablename__ = 'ihr_hegemony_country' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/hegemony_prefix.py b/models/hegemony_prefix.py index 1487916..45f9d4b 100644 --- a/models/hegemony_prefix.py +++ b/models/hegemony_prefix.py @@ -8,7 +8,7 @@ class HegemonyPrefix(Base): __tablename__ = 'ihr_hegemony_prefix' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/metis_atlas_deployment.py b/models/metis_atlas_deployment.py index b10503e..f22a5a6 100644 --- a/models/metis_atlas_deployment.py +++ b/models/metis_atlas_deployment.py @@ -8,7 +8,7 @@ class MetisAtlasDeployment(Base): __tablename__ = 'ihr_metis_atlas_deployment' __table_args__ = ( - PrimaryKeyConstraint('id','timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/metis_atlas_selection.py b/models/metis_atlas_selection.py index a75c21d..f526347 100644 --- a/models/metis_atlas_selection.py +++ b/models/metis_atlas_selection.py @@ -8,7 +8,7 @@ class MetisAtlasSelection(Base): __tablename__ = 'ihr_metis_atlas_selection' __table_args__ = ( - PrimaryKeyConstraint('id','timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/models/tr_hegemony.py b/models/tr_hegemony.py index 85c6ec8..62f7e54 100644 --- a/models/tr_hegemony.py +++ b/models/tr_hegemony.py @@ -9,7 +9,7 @@ class TRHegemony(Base): __tablename__ = 'ihr_tr_hegemony' __table_args__ = ( - PrimaryKeyConstraint('id', 'timebin'), + PrimaryKeyConstraint('timebin','id'), ) __hypertable__ = { diff --git a/repositories/atlas_delay_alarms_repository.py b/repositories/atlas_delay_alarms_repository.py index 1520bd3..694c04d 100644 --- a/repositories/atlas_delay_alarms_repository.py +++ b/repositories/atlas_delay_alarms_repository.py @@ -1,4 +1,4 @@ -from sqlalchemy.orm import Session, aliased +from sqlalchemy.orm import Session, aliased, contains_eager from sqlalchemy import and_, or_ from models.atlas_delay_alarms import AtlasDelayAlarms from datetime import datetime @@ -37,7 +37,11 @@ def get_alarms( query = db.query(AtlasDelayAlarms)\ .join(Startpoint, AtlasDelayAlarms.startpoint_relation)\ - .join(Endpoint, AtlasDelayAlarms.endpoint_relation) + .join(Endpoint, AtlasDelayAlarms.endpoint_relation)\ + .options( + contains_eager(AtlasDelayAlarms.startpoint_relation, alias=Startpoint), + contains_eager(AtlasDelayAlarms.endpoint_relation, alias=Endpoint) + ) # If no time filters specified, get rows with max timebin diff --git a/repositories/atlas_delay_repository.py b/repositories/atlas_delay_repository.py index f2c76a3..0cac3ca 100644 --- a/repositories/atlas_delay_repository.py +++ b/repositories/atlas_delay_repository.py @@ -1,4 +1,4 @@ -from sqlalchemy.orm import Session, aliased +from sqlalchemy.orm import Session, aliased, contains_eager from sqlalchemy import and_, or_ from models.atlas_delay import AtlasDelay from datetime import datetime @@ -40,7 +40,11 @@ def get_delays( query = db.query(AtlasDelay)\ .join(Startpoint, AtlasDelay.startpoint_relation)\ - .join(Endpoint, AtlasDelay.endpoint_relation) + .join(Endpoint, AtlasDelay.endpoint_relation)\ + .options( + contains_eager(AtlasDelay.startpoint_relation, alias=Startpoint), + contains_eager(AtlasDelay.endpoint_relation, alias=Endpoint) + ) # If no time filters specified, get rows with max timebin diff --git a/repositories/hegemony_alarms_repository.py b/repositories/hegemony_alarms_repository.py index b3883f1..070c466 100644 --- a/repositories/hegemony_alarms_repository.py +++ b/repositories/hegemony_alarms_repository.py @@ -1,5 +1,5 @@ from datetime import datetime -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, aliased, contains_eager from models.hegemony_alarms import HegemonyAlarms from typing import Optional, List, Tuple from utils import page_size @@ -20,7 +20,16 @@ def get_all( page: int = 1, order_by: Optional[str] = None ) -> Tuple[List[HegemonyAlarms], int]: - query = db.query(HegemonyAlarms) + ASN = aliased(HegemonyAlarms.asn_relation.property.mapper.class_) + OriginASN = aliased(HegemonyAlarms.originasn_relation.property.mapper.class_) + + query = db.query(HegemonyAlarms)\ + .join(ASN, HegemonyAlarms.asn_relation)\ + .join(OriginASN, HegemonyAlarms.originasn_relation)\ + .options( + contains_eager(HegemonyAlarms.asn_relation, alias=ASN), + contains_eager(HegemonyAlarms.originasn_relation, alias=OriginASN) + ) # If no time filters specified, get rows with max timebin if not timebin_gte and not timebin_lte: diff --git a/repositories/hegemony_country_repository.py b/repositories/hegemony_country_repository.py index 691cb12..200b0a8 100644 --- a/repositories/hegemony_country_repository.py +++ b/repositories/hegemony_country_repository.py @@ -1,5 +1,5 @@ from datetime import datetime -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, contains_eager, aliased from models.hegemony_country import HegemonyCountry from typing import Optional, List, Tuple from utils import page_size @@ -23,7 +23,13 @@ def get_all( page: int = 1, order_by: Optional[str] = None ) -> Tuple[List[HegemonyCountry], int]: - query = db.query(HegemonyCountry) + ASN = aliased(HegemonyCountry.asn_relation.property.mapper.class_) + + query = db.query(HegemonyCountry)\ + .join(ASN, HegemonyCountry.asn_relation)\ + .options( + contains_eager(HegemonyCountry.asn_relation, alias=ASN), + ) # If no time filters specified, get rows with max timebin if not timebin_gte and not timebin_lte: diff --git a/repositories/hegemony_prefix_repository.py b/repositories/hegemony_prefix_repository.py index 5c2a363..589f8cd 100644 --- a/repositories/hegemony_prefix_repository.py +++ b/repositories/hegemony_prefix_repository.py @@ -1,5 +1,5 @@ from datetime import datetime -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, contains_eager, aliased from models.hegemony_prefix import HegemonyPrefix from typing import Optional, List, Tuple from utils import page_size @@ -28,8 +28,17 @@ def get_all( page: int = 1, order_by: Optional[str] = None ) -> Tuple[List[HegemonyPrefix], int]: - query = db.query(HegemonyPrefix) + ASN = aliased(HegemonyPrefix.asn_relation.property.mapper.class_) + OriginASN = aliased(HegemonyPrefix.originasn_relation.property.mapper.class_) + + query = db.query(HegemonyPrefix)\ + .join(ASN, HegemonyPrefix.asn_relation)\ + .join(OriginASN, HegemonyPrefix.originasn_relation)\ + .options( + contains_eager(HegemonyPrefix.asn_relation, alias=ASN), + contains_eager(HegemonyPrefix.originasn_relation, alias=OriginASN) + ) # If no time filters specified, get rows with max timebin if not timebin_gte and not timebin_lte: max_timebin = db.query(func.max(HegemonyPrefix.timebin)).scalar() diff --git a/repositories/hegemony_repository.py b/repositories/hegemony_repository.py index 2f2ca48..7a13a24 100644 --- a/repositories/hegemony_repository.py +++ b/repositories/hegemony_repository.py @@ -1,5 +1,5 @@ from datetime import datetime -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, contains_eager, aliased from models.hegemony import Hegemony from typing import Optional, List, Tuple from utils import page_size @@ -21,8 +21,18 @@ def get_all( page: int = 1, order_by: Optional[str] = None ) -> Tuple[List[Hegemony], int]: - query = db.query(Hegemony) - + + ASN = aliased(Hegemony.asn_relation.property.mapper.class_) + OriginASN = aliased(Hegemony.originasn_relation.property.mapper.class_) + + query = db.query(Hegemony)\ + .join(ASN, Hegemony.asn_relation)\ + .join(OriginASN, Hegemony.originasn_relation)\ + .options( + contains_eager(Hegemony.asn_relation, alias=ASN), + contains_eager(Hegemony.originasn_relation, alias=OriginASN) + ) + # If no time filters specified, get rows with max timebin if not timebin_gte and not timebin_lte: max_timebin = db.query(func.max(Hegemony.timebin)).scalar() diff --git a/repositories/metis_atlas_deployment_repository.py b/repositories/metis_atlas_deployment_repository.py index abe9967..8e525f1 100644 --- a/repositories/metis_atlas_deployment_repository.py +++ b/repositories/metis_atlas_deployment_repository.py @@ -1,5 +1,5 @@ from datetime import datetime -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, contains_eager from models.metis_atlas_deployment import MetisAtlasDeployment from typing import Optional, List, Tuple from utils import page_size @@ -21,8 +21,9 @@ def get_all( page: int = 1, order_by: Optional[str] = None ) -> Tuple[List[MetisAtlasDeployment], int]: - query = db.query(MetisAtlasDeployment).join( - MetisAtlasDeployment.asn_relation) + query = db.query(MetisAtlasDeployment)\ + .join(MetisAtlasDeployment.asn_relation)\ + .options(contains_eager(MetisAtlasDeployment.asn_relation)) # If no time filters specified, get rows with max timebin if not timebin and not timebin_gte and not timebin_lte: diff --git a/repositories/metis_atlas_selection_repository.py b/repositories/metis_atlas_selection_repository.py index abd6e99..348af87 100644 --- a/repositories/metis_atlas_selection_repository.py +++ b/repositories/metis_atlas_selection_repository.py @@ -1,5 +1,5 @@ from datetime import datetime -from sqlalchemy.orm import Session +from sqlalchemy.orm import Session, contains_eager from models.metis_atlas_selection import MetisAtlasSelection from typing import Optional, List, Tuple from utils import page_size @@ -21,8 +21,9 @@ def get_all( page: int = 1, order_by: Optional[str] = None ) -> Tuple[List[MetisAtlasSelection], int]: - query = db.query(MetisAtlasSelection).join( - MetisAtlasSelection.asn_relation) + query = db.query(MetisAtlasSelection)\ + .join(MetisAtlasSelection.asn_relation)\ + .options(contains_eager(MetisAtlasSelection.asn_relation)) # If no time filters specified, get rows with max timebin if not timebin and not timebin_gte and not timebin_lte: diff --git a/repositories/tr_hegemony_repository.py b/repositories/tr_hegemony_repository.py index 5f711c3..27a5462 100644 --- a/repositories/tr_hegemony_repository.py +++ b/repositories/tr_hegemony_repository.py @@ -1,4 +1,4 @@ -from sqlalchemy.orm import Session, aliased +from sqlalchemy.orm import Session, aliased, contains_eager from sqlalchemy import and_, or_ from models.tr_hegemony import TRHegemony from datetime import datetime @@ -34,7 +34,11 @@ def get_tr_hegemony( query = db.query(TRHegemony)\ .join(Origin, TRHegemony.origin_relation)\ - .join(Dependency, TRHegemony.dependency_relation) + .join(Dependency, TRHegemony.dependency_relation)\ + .options( + contains_eager(TRHegemony.origin_relation, alias=Origin), + contains_eager(TRHegemony.dependency_relation, alias=Dependency) + ) # If no time filters specified, get rows with max timebin if not timebin and not timebin_gte and not timebin_lte: