"""Rights Attribute modeling.""" from sqlalchemy import Column from sqlalchemy import DateTime from sqlalchemy import Enum from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import JSON from sqlalchemy import String from sqlalchemy.orm import relationship from sqlalchemy.sql import func from backend.connectors import mysql class RightsAttributes(mysql.BaseModel): """Model for Rights Attributes.""" __tablename__ = 'rights_attributes' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 description = Column(String(100), nullable=False) def to_dict(self): """Rights Attributes data dictionary. Returns: dict """ return { 'id': self.id, 'description': self.description } class RightsAttributesSuggestionKeywords(mysql.BaseModel): """Model for Rights Attributes Suggestion Keywords.""" __tablename__ = 'rights_attributes_suggestion_keywords' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 rights_attribute_id = Column(Integer, ForeignKey( 'rights_attributes.id'), nullable=False) keyword = Column(String(30), nullable=False) def to_dict(self): """Rights Attributes Suggestion Keywords data dictionary. Returns: dict """ return { 'id': self.id, 'rights_attribute_id': self.rights_attribute_id, 'keyword': self.keyword } class RightsAttributesSuggestionVendorImprintKeywords(mysql.BaseModel): """Model for Rights Attributes Suggestion Vendor/Imprint Keywords.""" __tablename__ = 'rights_attributes_suggestion_vendor_imprint_keywords' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 rights_attribute_id = Column(Integer, ForeignKey('rights_attributes.id'), nullable=False) vendor_id = Column(Integer, nullable=False) imprint_keyword = Column(String(100), nullable=False) class RightsAttributesSuggestionVendorSubaccountKeywords(mysql.BaseModel): """Model for Rights Attributes Suggestion Vendor/Subaccount Keywords.""" __tablename__ = 'rights_attributes_suggestion_vendor_subaccount_keywords' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 rights_attribute_id = Column(Integer, ForeignKey('rights_attributes.id'), nullable=False) vendor_id = Column(Integer, nullable=False) subaccount_id = Column(Integer, nullable=False) class RightsAttributesSuggestionGenreSubgenreKeywords(mysql.BaseModel): """Model for Rights Attributes Suggestion Genre/Subgenre Keywords.""" __tablename__ = 'rights_attributes_suggestion_genre_subgenre_keywords' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 rights_attribute_id = Column(Integer, ForeignKey('rights_attributes.id'), nullable=False) subgenre_id = Column(Integer, nullable=False) genre_id = Column(Integer, nullable=True) class TrackRightsAttributes(mysql.BaseModel): """Model for Track Rights Attributes.""" __tablename__ = 'track_rights_attributes' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 unique_track_id = Column(Integer, ForeignKey('track.id'), nullable=False) rights_attribute_id = Column(Integer, ForeignKey( 'rights_attributes.id'), nullable=False) rights_attributes = relationship( 'RightsAttributes', foreign_keys=[rights_attribute_id]) def to_dict(self): """Rights Attributes data dictionary. Returns: dict """ return { 'id': self.id, 'unique_track_id': self.unique_track_id, 'rights_attribute_id': self.rights_attribute_id, 'rights_attributes': self.rights_attributes } class TrackRightsAttributesEdits(mysql.BaseModel): """Model for Track Rights Attributes Edits.""" __tablename__ = 'track_rights_attributes_edits' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 unique_track_id = Column(Integer, ForeignKey('track.id'), nullable=False) rights_attribute_id = Column(Integer, ForeignKey( 'rights_attributes.id'), nullable=False) rights_attributes = relationship( 'RightsAttributes', foreign_keys=[rights_attribute_id]) def to_dict(self): """Rights Attributes data dictionary. Returns: dict """ return { 'id': self.id, 'unique_track_id': self.unique_track_id, 'rights_attribute_id': self.rights_attribute_id, 'rights_attributes': self.rights_attributes } class TrackRightsAttributesChangelog(mysql.BaseModel): """Model for Track Rights Attributes Changelog.""" __tablename__ = 'track_rights_attributes_changelog' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 unique_track_id = Column(Integer, ForeignKey('track.id'), nullable=False) rights_attribute_id = Column(Integer, ForeignKey('rights_attributes.id'), nullable=False) user_uuid = Column(String(36)) action = Column(Enum('insert', 'delete')) datetime = Column(DateTime, default=func.now(), onupdate=func.now()) change_source = Column(String(255), nullable=True) def to_dict(self): """Track Rights Attributes Changelog. Returns: dict """ return { 'id': self.id, 'unique_track_id': self.unique_track_id, 'rights_attribute_id': self.rights_attribute_id, 'user_uuid': self.user_uuid, 'action': self.action, 'datetime': self.datetime, 'change_source': self.change_source } class TrackRightsAttributeSuggestions(mysql.BaseModel): """Model for Track Rights Attribute Suggestions.""" __tablename__ = 'track_rights_attribute_suggestions' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 unique_track_id = Column(Integer, ForeignKey('track.id'), nullable=False) suggestions = Column(JSON, nullable=False) user_uuid = Column(String(36), nullable=False) review_queue_id = Column(Integer, nullable=False) class VendorRightsAttributes(mysql.BaseModel): """Model for Vendor Rights Attributes.""" __tablename__ = 'vendor_rights_attributes' id = Column(Integer, primary_key=True, autoincrement=True) # noqa: A003 vendor_id = Column(Integer) rights_attribute_id = Column(Integer, ForeignKey( 'rights_attributes.id'), nullable=False) rights_attributes = relationship( 'RightsAttributes', foreign_keys=[rights_attribute_id]) def to_dict(self): """Rights Attributes data dictionary. Returns: dict """ return { 'id': self.id, 'vendor_id': self.vendor_id, 'rights_attribute_id': self.rights_attribute_id, 'rights_attributes': self.rights_attributes }