Skip to content

Commit

Permalink
Core & Internals: drop support for old distances DB format. Closes ru…
Browse files Browse the repository at this point in the history
…cio#6367

The code was intended to allow both 1.29 and 1.30 servers to run
in parallel on the same database. This should have no effect on
everybody who correctly applied the migrations.
  • Loading branch information
Radu Carpa committed Nov 10, 2023
1 parent 4380d02 commit 7aad297
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions lib/rucio/db/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from datetime import datetime, timedelta
from typing import Any, Optional, Union

from sqlalchemy import BigInteger, Boolean, DateTime, Enum, Float, Integer, SmallInteger, String, Text, event, UniqueConstraint, inspect
from sqlalchemy import BigInteger, Boolean, DateTime, Enum, Float, Integer, SmallInteger, String, Text, event, UniqueConstraint
from sqlalchemy.engine import Engine
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.ext.declarative import declared_attr
Expand All @@ -34,7 +34,7 @@
RuleState, ReplicaState, RequestState, RequestType, RSEType,
ScopeStatus, SubscriptionState, RuleNotification, LifetimeExceptionsState,
BadPFNStatus, TransferLimitDirection)
from rucio.db.sqla.session import BASE, get_engine
from rucio.db.sqla.session import BASE
from rucio.db.sqla.types import GUID, BooleanString, JSON
from rucio.db.sqla.types import InternalAccountString
from rucio.db.sqla.types import InternalScopeString
Expand Down Expand Up @@ -1408,24 +1408,12 @@ class SourceHistory(BASE, ModelBase):
)


# Compatibility code to permit 1.30 to run with a distances table from the 1.29 database schema
# TODO: remove this code in rucio 1.31
_distance_column_name = 'distance'
_engine = get_engine()
if _engine.dialect.name in ['oracle', 'mysql', 'postgresql']:
_insp = inspect(_engine)
if _engine.dialect.name in ['oracle', 'postgresql'] or BASE.metadata.schema in _insp.get_schema_names():
if 'distances' in _insp.get_table_names(schema=BASE.metadata.schema):
if any(c['name'] == 'ranking' for c in _insp.get_columns(table_name='distances', schema=BASE.metadata.schema)):
_distance_column_name = 'ranking'


class Distance(BASE, ModelBase):
"""Represents distance between rses"""
__tablename__ = 'distances'
src_rse_id: Mapped[uuid.UUID] = mapped_column(GUID())
dest_rse_id: Mapped[uuid.UUID] = mapped_column(GUID())
distance: Mapped[Optional[int]] = mapped_column(Integer(), name=_distance_column_name)
distance: Mapped[Optional[int]] = mapped_column(Integer())
_table_args = (PrimaryKeyConstraint('src_rse_id', 'dest_rse_id', name='DISTANCES_PK'),
ForeignKeyConstraint(['src_rse_id'], ['rses.id'], name='DISTANCES_SRC_RSES_FK'),
ForeignKeyConstraint(['dest_rse_id'], ['rses.id'], name='DISTANCES_DEST_RSES_FK'),
Expand Down

0 comments on commit 7aad297

Please sign in to comment.