Blame alembic/versions/c34f4b09ef18_star_a_project.py
|
Vivek Anand |
f019f5 |
"""star_a_project
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
Revision ID: c34f4b09ef18
|
|
Vivek Anand |
4c4312 |
Revises: 8a5d68f74beb
|
|
Vivek Anand |
f019f5 |
Create Date: 2017-07-07 00:08:18.257075
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
"""
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
# revision identifiers, used by Alembic.
|
|
Vivek Anand |
f019f5 |
revision = 'c34f4b09ef18'
|
|
Vivek Anand |
4c4312 |
down_revision = '8a5d68f74beb'
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
from alembic import op
|
|
Vivek Anand |
f019f5 |
import sqlalchemy as sa
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
def upgrade():
|
|
Vivek Anand |
f019f5 |
''' Add a new table to store data about who starred which project '''
|
|
Vivek Anand |
f019f5 |
op.create_table(
|
|
Vivek Anand |
f019f5 |
'stargazers',
|
|
Vivek Anand |
f019f5 |
sa.Column('id', sa.Integer, primary_key=True),
|
|
Vivek Anand |
f019f5 |
sa.Column(
|
|
Vivek Anand |
f019f5 |
'project_id',
|
|
Vivek Anand |
f019f5 |
sa.Integer,
|
|
Vivek Anand |
f019f5 |
sa.ForeignKey(
|
|
Vivek Anand |
f019f5 |
'projects.id', onupdate='CASCADE', ondelete='CASCADE'),
|
|
Vivek Anand |
0b85e6 |
nullable=False,
|
|
Vivek Anand |
0b85e6 |
index=True,
|
|
Vivek Anand |
f019f5 |
),
|
|
Vivek Anand |
f019f5 |
sa.Column(
|
|
Vivek Anand |
f019f5 |
'user_id',
|
|
Vivek Anand |
f019f5 |
sa.Integer,
|
|
Vivek Anand |
f019f5 |
sa.ForeignKey('users.id', onupdate='CASCADE', ondelete='CASCADE'),
|
|
Vivek Anand |
f019f5 |
nullable=False,
|
|
Vivek Anand |
f019f5 |
)
|
|
Vivek Anand |
f019f5 |
)
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
op.create_unique_constraint(
|
|
Vivek Anand |
ed7323 |
constraint_name='uq_stargazers_project_id_user_id_key',
|
|
Vivek Anand |
f019f5 |
table_name='stargazers',
|
|
Vivek Anand |
f019f5 |
columns=['project_id', 'user_id']
|
|
Vivek Anand |
f019f5 |
)
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
|
|
Vivek Anand |
f019f5 |
def downgrade():
|
|
Vivek Anand |
f019f5 |
''' Remove the stargazers table from the database '''
|
|
Vivek Anand |
f019f5 |
op.drop_constraint(
|
|
Vivek Anand |
ed7323 |
constraint_name='uq_stargazers_project_id_user_id_key',
|
|
Vivek Anand |
f019f5 |
table_name='stargazers'
|
|
Vivek Anand |
f019f5 |
)
|
|
Vivek Anand |
f019f5 |
op.drop_table('stargazers')
|