# 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
# class EnumType(TypeDecorator, SchemaType):
#     """Custom enum type to be used as :class:`enum.Enum`in Python standard
#     library. It inherits :class:`sqlalchemy.types.SchemaType` since it
#     requires schema-level DDL. PostgreSQL ENUM type defined in an Alembic
#     script must be explicitly created/dropped.
#     """
# 
#     impl = Enum
# 
#     def __init__(self, enum_class: enum.Enum, **kw):
#         if not issubclass(enum_class, enum.Enum):
#             raise TypeError('expected enum.Enum subtype')
#         super().__init__(*(m.name for m in enum_class), **kw)
#         self._enum_class = enum_class
# 
#     def process_bind_param(self, value, dialect):
#         return value.name
# 
#     def process_result_value(self, value, dialect):
#         return self._enum_class[value]
# 
#     def _set_parent(self, column):
#         self.impl._set_parent(column)
# 
#     @property
#     def python_type(self):
#         return self._enum_class
# 
# 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)


import enum
from sqlalchemy.orm import foreign, relationship, remote
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.sql.functions import now
from sqlalchemy.types import Date, DateTime, Integer, String
from .name import Nameable
from .orm import Base
from .sqltypes import EnumType, prevent_discriminator_from_changing
    __repr_columns__ = work_id, trope_id


class World(Nameable):
    """Fictional universe that is a self-consistent fictional setting
    with elements that differ from the real world,
    for example *Middle-earth* and *Marvel Cinematic Universe*.
    """

    #: (:class:`int`) The primary key integer.
    id = Column(Integer, ForeignKey(Nameable.id), primary_key=True)

    #: (:class:`collections.abc.MutableSet`) The set of
    #: :class:`Franchise`\ s that belong the world.
    franchises = relationship(Franchise,
                              foreign_keys=[id],
                              collection_class=set)

    #: (:class:`datetime.datetime`) The date and time on which
    #: the record was created.
    created_at = Column(DateTime(timezone=True), nullable=False,
                        default=now())

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



# 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
# class EnumType(TypeDecorator, SchemaType):
#     """Custom enum type to be used as :class:`enum.Enum`in Python standard
#     library. It inherits :class:`sqlalchemy.types.SchemaType` since it
#     requires schema-level DDL. PostgreSQL ENUM type defined in an Alembic
#     script must be explicitly created/dropped.
#     """
# 
#     impl = Enum
# 
#     def __init__(self, enum_class: enum.Enum, **kw):
#         if not issubclass(enum_class, enum.Enum):
#             raise TypeError('expected enum.Enum subtype')
#         super().__init__(*(m.name for m in enum_class), **kw)
#         self._enum_class = enum_class
# 
#     def process_bind_param(self, value, dialect):
#         return value.name
# 
#     def process_result_value(self, value, dialect):
#         return self._enum_class[value]
# 
#     def _set_parent(self, column):
#         self.impl._set_parent(column)
# 
#     @property
#     def python_type(self):
#         return self._enum_class
# 
# 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/work.py
import enum
from sqlalchemy.orm import foreign, relationship, remote
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.sql.functions import now
from sqlalchemy.types import Date, DateTime, Integer, String
from .name import Nameable
from .orm import Base
from .sqltypes import EnumType, prevent_discriminator_from_changing

    __repr_columns__ = work_id, trope_id


class World(Nameable):
    """Fictional universe that is a self-consistent fictional setting
    with elements that differ from the real world,
    for example *Middle-earth* and *Marvel Cinematic Universe*.
    """

    #: (:class:`int`) The primary key integer.
    id = Column(Integer, ForeignKey(Nameable.id), primary_key=True)

    #: (:class:`collections.abc.MutableSet`) The set of
    #: :class:`Franchise`\ s that belong the world.
    franchises = relationship(Franchise,
                              foreign_keys=[id],
                              collection_class=set)

    #: (:class:`datetime.datetime`) The date and time on which
    #: the record was created.
    created_at = Column(DateTime(timezone=True), nullable=False,
                        default=now())

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



prevent_discriminator_from_changing(Franchise.type)