# Path: _15thnight/models.py
# class Category(Model):
#     """Category/type of provided help representation."""
#     __tablename__ = "categories"
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String(255), nullable=False, unique=True)
#     description = Column(Text)
#     sort_order = Column(Integer, nullable=False, default=0)
# 
#     @classmethod
#     def all(cls):
#         return cls.query.order_by(cls.sort_order).all()
# 
#     @classmethod
#     def get_by_name(cls, name):
#         return cls.query.filter(cls.name == name).first()
# 
#     def to_json(self):
#         return dict(
#             id=self.id,
#             name=self.name,
#             description=self.description,
#             services=Service.get_by_category(self.id),
#             sort_order=self.sort_order
#         )
# 
# class Service(Model):
#     """Service of provider."""
#     __tablename__ = 'service'
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String(255), nullable=False, unique=True)
#     description = Column(Text)
#     category_id = Column(ForeignKey('categories.id'), nullable=False)
#     category = relationship(
#         'Category', backref=backref('services', cascade="all, delete-orphan"))
#     sort_order = Column(Integer, nullable=False, default=0)
# 
#     @classmethod
#     def get_by_category(cls, category_id):
#         return cls.query.filter(cls.category_id == category_id) \
#             .order_by(cls.sort_order) \
#             .all()
# 
#     @classmethod
#     def get_by_name(cls, name):
#         return cls.query.filter(cls.name == name).first()
# 
#     def to_json(self):
#         return dict(
#             id=self.id,
#             name=self.name,
#             description=self.description,
#             category=dict(
#                 id=self.category.id,
#                 name=self.category.name,
#                 description=self.category.description
#             ),
#             sort_order=self.sort_order
#         )


from alembic import op
from _15thnight.models import Category, Service
import sqlalchemy as sa
"""sort order not null

Revision ID: 3e7e65c44fc2
Revises: 368b199625d8
Create Date: 2016-08-21 03:05:06.778204

"""

# revision identifiers, used by Alembic.
revision = '3e7e65c44fc2'
down_revision = '368b199625d8'
branch_labels = None
depends_on = None




def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.execute(
        Category.__table__.update()

# Path: _15thnight/models.py
# class Category(Model):
#     """Category/type of provided help representation."""
#     __tablename__ = "categories"
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String(255), nullable=False, unique=True)
#     description = Column(Text)
#     sort_order = Column(Integer, nullable=False, default=0)
# 
#     @classmethod
#     def all(cls):
#         return cls.query.order_by(cls.sort_order).all()
# 
#     @classmethod
#     def get_by_name(cls, name):
#         return cls.query.filter(cls.name == name).first()
# 
#     def to_json(self):
#         return dict(
#             id=self.id,
#             name=self.name,
#             description=self.description,
#             services=Service.get_by_category(self.id),
#             sort_order=self.sort_order
#         )
# 
# class Service(Model):
#     """Service of provider."""
#     __tablename__ = 'service'
# 
#     id = Column(Integer, primary_key=True)
#     name = Column(String(255), nullable=False, unique=True)
#     description = Column(Text)
#     category_id = Column(ForeignKey('categories.id'), nullable=False)
#     category = relationship(
#         'Category', backref=backref('services', cascade="all, delete-orphan"))
#     sort_order = Column(Integer, nullable=False, default=0)
# 
#     @classmethod
#     def get_by_category(cls, category_id):
#         return cls.query.filter(cls.category_id == category_id) \
#             .order_by(cls.sort_order) \
#             .all()
# 
#     @classmethod
#     def get_by_name(cls, name):
#         return cls.query.filter(cls.name == name).first()
# 
#     def to_json(self):
#         return dict(
#             id=self.id,
#             name=self.name,
#             description=self.description,
#             category=dict(
#                 id=self.category.id,
#                 name=self.category.name,
#                 description=self.category.description
#             ),
#             sort_order=self.sort_order
#         )


# Path: _15thnight/migrations/versions/3e7e65c44fc2_sort_order_not_null.py
from alembic import op
from _15thnight.models import Category, Service
import sqlalchemy as sa

"""sort order not null

Revision ID: 3e7e65c44fc2
Revises: 368b199625d8
Create Date: 2016-08-21 03:05:06.778204

"""

# revision identifiers, used by Alembic.
revision = '3e7e65c44fc2'
down_revision = '368b199625d8'
branch_labels = None
depends_on = None




def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.execute(
        Category.__table__.update()

        .where(Category.__table__.c.sort_order == None)