aboutsummaryrefslogtreecommitdiff
path: root/migrations/versions/3f83bfe93fc_adding_category.py
blob: bd65a01f732f864f6971ede493b76378f175079e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""adding category

Revision ID: 3f83bfe93fc
Revises: 25ca960a207
Create Date: 2015-09-01 14:15:04.212563
"""

# revision identifiers, used by Alembic.
revision = '3f83bfe93fc'
down_revision = '25ca960a207'

import conf
from alembic import op
import sqlalchemy as sa


def upgrade():
    op.create_table('category',
            sa.Column('id', sa.Integer(), nullable=False),
            sa.Column('name', sa.String(), nullable=True),
            sa.Column('user_id', sa.Integer(), nullable=True),
            sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
            sa.PrimaryKeyConstraint('id'))
    op.add_column('article',
                  sa.Column('category_id', sa.Integer(), nullable=True))
    op.add_column('feed',
                  sa.Column('category_id', sa.Integer(), nullable=True))
    if 'sqlite' not in conf.SQLALCHEMY_DATABASE_URI:
        op.create_foreign_key(None, 'article', 'category',
                              ['category_id'], ['id'])
        op.create_foreign_key(None, 'feed', 'category',
                              ['category_id'], ['id'])


def downgrade():
    if 'sqlite' not in conf.SQLALCHEMY_DATABASE_URI:
        op.drop_constraint(None, 'feed', type_='foreignkey')
        op.drop_constraint(None, 'feed', type_='foreignkey')
        op.drop_column('feed', 'category_id')
        op.drop_constraint(None, 'article', type_='foreignkey')
        op.drop_column('article', 'category_id')
        op.drop_table('category')
bgstack15