<commit_before>#!/ms/dist/python/PROJ/core/2.5.2-1/bin/python
""" ChassisSlot sets up a structure for tracking position within a chassis. """
import sys
import os

from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relation, backref

from aquilon.aqdb.db_factory import Base
from aquilon.aqdb.hw.machine import Machine
from aquilon.aqdb.sy.chassis import Chassis


class ChassisSlot(Base):
    """ ChassisSlot allows a Machine to be assigned to each unique position
        within a Chassis. """

    __tablename__ = 'chassis_slot'

    chassis_id = Column(Integer,
                        ForeignKey('chassis.id',
                                   name='chassis_slot_chassis_fk',
                                   ondelete='CASCADE'),
                        primary_key=True)

    slot_number = Column(Integer, primary_key=True)

    # TODO: Code constraint that these are Blades...
    machine_id = Column(Integer,
                        ForeignKey('machine.id',
                                   name='chassis_slot_machine_fk'),
                        nullable=True)

    chassis = relation(Chassis, uselist=False,
                       backref=backref('slots', cascade='delete'),
                       passive_deletes=True)

    machine = relation(Machine, uselist=False,
                       backref=backref('chassis_slot'))

chassis_slot = ChassisSlot.__table__
chassis_slot.primary_key.name = 'chassis_slot_pk'

table = chassis_slot
<commit_msg>Present chassis slots in slot order when using backref.<commit_after>#!/ms/dist/python/PROJ/core/2.5.2-1/bin/python
""" ChassisSlot sets up a structure for tracking position within a chassis. """
import sys
import os

from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relation, backref
from sqlalchemy.sql.expression import asc

from aquilon.aqdb.db_factory import Base
from aquilon.aqdb.hw.machine import Machine
from aquilon.aqdb.sy.chassis import Chassis


class ChassisSlot(Base):
    """ ChassisSlot allows a Machine to be assigned to each unique position
        within a Chassis. """

    __tablename__ = 'chassis_slot'

    chassis_id = Column(Integer,
                        ForeignKey('chassis.id',
                                   name='chassis_slot_chassis_fk',
                                   ondelete='CASCADE'),
                        primary_key=True)

    slot_number = Column(Integer, primary_key=True)

    # TODO: Code constraint that these are Blades...
    machine_id = Column(Integer,
                        ForeignKey('machine.id',
                                   name='chassis_slot_machine_fk'),
                        nullable=True)

    chassis = relation(Chassis, uselist=False,
                       backref=backref('slots', cascade='delete',
                                       order_by=[asc('slot_number')]),
                       passive_deletes=True)

    machine = relation(Machine, uselist=False,
                       backref=backref('chassis_slot'))

chassis_slot = ChassisSlot.__table__
chassis_slot.primary_key.name = 'chassis_slot_pk'

table = chassis_slot

{'fraction_non_alphanumeric': 0.08524904214559387, 'fraction_numerical': 0.002554278416347382, 'mean_word_length': 2.2100409836065573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5927383', 'n_tokens_mistral': 943, 'n_tokens_neox': 836, 'n_words': 201}