# Path: cliche/orm.py
# def make_repr(self):
# def get_alembic_config(engine):
# def initialize_database(engine):
# def get_database_revision(engine):
#     def get_revision(rev, context):
# def upgrade_database(engine, revision='head'):
#     def upgrade(rev, context):
#         def update_current_rev(old, new):
# def downgrade_database(engine, revision):
# def import_all_modules(dry_run=False):  # FIXME
# 
# Path: cliche/sqltypes.py
# def prevent_discriminator_from_changing(col):
#     def set_discriminator(target, value, oldvalue, initiator):
#         oldvalue_is_none = (
#             oldvalue.__class__ != _symbol or oldvalue.name != 'NO_VALUE'
#         )
#         value_is_wrong = (
#             value != target.__mapper_args__['polymorphic_identity']
#         )
#         if oldvalue_is_none or value_is_wrong:
#             raise AttributeError('discriminator column cannot be changed')
# 
#     event.listen(col, 'set', set_discriminator)


from sqlalchemy.orm import relationship
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.sql.functions import now
from sqlalchemy.types import Date, DateTime, Integer
from .name import Nameable
from .orm import Base
from .sqltypes import prevent_discriminator_from_changing

    __tablename__ = 'teams'
    __repr_columns__ = [id]
    __mapper_args__ = {
        'polymorphic_identity': 'teams',
    }


class TeamMembership(Base):
    """Team memberships to people."""

    #: (:class:`int`) :class:`Team.id` of :attr:`team`.
    team_id = Column(Integer, ForeignKey(Team.id), primary_key=True)

    #: (:class:`Team`) The team that the :attr:`member` belongs to.
    team = relationship(Team)

    #: (:class:`int`) :class:`Person.id` of :attr:`member`.
    member_id = Column(Integer, ForeignKey(Person.id), primary_key=True)

    #: (:class:`Person`) The member who is a member of the :attr:`team`.
    member = relationship(Person)

    #: (:class:`datetime.datetime`) The added time.
    created_at = Column(DateTime(timezone=True), nullable=False, default=now())

    __tablename__ = 'team_memberships'
    __repr_columns__ = team_id, member_id



# Path: cliche/orm.py
# def make_repr(self):
# def get_alembic_config(engine):
# def initialize_database(engine):
# def get_database_revision(engine):
#     def get_revision(rev, context):
# def upgrade_database(engine, revision='head'):
#     def upgrade(rev, context):
#         def update_current_rev(old, new):
# def downgrade_database(engine, revision):
# def import_all_modules(dry_run=False):  # FIXME
# 
# Path: cliche/sqltypes.py
# def prevent_discriminator_from_changing(col):
#     def set_discriminator(target, value, oldvalue, initiator):
#         oldvalue_is_none = (
#             oldvalue.__class__ != _symbol or oldvalue.name != 'NO_VALUE'
#         )
#         value_is_wrong = (
#             value != target.__mapper_args__['polymorphic_identity']
#         )
#         if oldvalue_is_none or value_is_wrong:
#             raise AttributeError('discriminator column cannot be changed')
# 
#     event.listen(col, 'set', set_discriminator)


# Path: cliche/people.py
from sqlalchemy.orm import relationship
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.sql.functions import now
from sqlalchemy.types import Date, DateTime, Integer
from .name import Nameable
from .orm import Base
from .sqltypes import prevent_discriminator_from_changing


    __tablename__ = 'teams'
    __repr_columns__ = [id]
    __mapper_args__ = {
        'polymorphic_identity': 'teams',
    }


class TeamMembership(Base):
    """Team memberships to people."""

    #: (:class:`int`) :class:`Team.id` of :attr:`team`.
    team_id = Column(Integer, ForeignKey(Team.id), primary_key=True)

    #: (:class:`Team`) The team that the :attr:`member` belongs to.
    team = relationship(Team)

    #: (:class:`int`) :class:`Person.id` of :attr:`member`.
    member_id = Column(Integer, ForeignKey(Person.id), primary_key=True)

    #: (:class:`Person`) The member who is a member of the :attr:`team`.
    member = relationship(Person)

    #: (:class:`datetime.datetime`) The added time.
    created_at = Column(DateTime(timezone=True), nullable=False, default=now())

    __tablename__ = 'team_memberships'
    __repr_columns__ = team_id, member_id



prevent_discriminator_from_changing(Person.type)