Blame alembic/versions/61ac23e35f86_fix_pr_project_from_key.py
|
Pierre-Yves Chibon |
ffd53a |
"""Fix pr project_from key
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
Revision ID: 61ac23e35f86
|
|
Pierre-Yves Chibon |
ffd53a |
Revises: 47f5fab6f46a
|
|
Pierre-Yves Chibon |
ffd53a |
Create Date: 2017-12-05 16:59:17.117199
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
"""
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
# revision identifiers, used by Alembic.
|
|
Pierre-Yves Chibon |
ffd53a |
revision = '61ac23e35f86'
|
|
Pierre-Yves Chibon |
ffd53a |
down_revision = '47f5fab6f46a'
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
from alembic import op
|
|
Pierre-Yves Chibon |
ffd53a |
import sqlalchemy as sa
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
def upgrade():
|
|
Pierre-Yves Chibon |
ffd53a |
""" Alter the pull_requests table to update the foreign key to set null
|
|
Pierre-Yves Chibon |
ffd53a |
on delete.
|
|
Pierre-Yves Chibon |
ffd53a |
"""
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
op.drop_constraint(
|
|
Pierre-Yves Chibon |
ffd53a |
'pull_requests_project_id_from_fkey',
|
|
Pierre-Yves Chibon |
ffd53a |
'pull_requests',
|
|
Pierre-Yves Chibon |
ffd53a |
type_='foreignkey')
|
|
Pierre-Yves Chibon |
ffd53a |
op.create_foreign_key(
|
|
Pierre-Yves Chibon |
ffd53a |
name='pull_requests_project_id_from_fkey',
|
|
Pierre-Yves Chibon |
ffd53a |
source_table='pull_requests',
|
|
Pierre-Yves Chibon |
ffd53a |
referent_table='projects',
|
|
Pierre-Yves Chibon |
0e2c78 |
local_cols=['project_id_from'],
|
|
Pierre-Yves Chibon |
ffd53a |
remote_cols=['id'],
|
|
Pierre-Yves Chibon |
ffd53a |
onupdate='cascade',
|
|
Pierre-Yves Chibon |
ffd53a |
ondelete='set null',
|
|
Pierre-Yves Chibon |
ffd53a |
)
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
def downgrade():
|
|
Pierre-Yves Chibon |
ffd53a |
""" Alter the pull_requests table to update the foreign key to cascade
|
|
Pierre-Yves Chibon |
ffd53a |
on delete.
|
|
Pierre-Yves Chibon |
ffd53a |
"""
|
|
Pierre-Yves Chibon |
ffd53a |
|
|
Pierre-Yves Chibon |
ffd53a |
op.drop_constraint(
|
|
Pierre-Yves Chibon |
ffd53a |
'pull_requests_project_id_from_fkey',
|
|
Pierre-Yves Chibon |
ffd53a |
'pull_requests',
|
|
Pierre-Yves Chibon |
ffd53a |
type_='foreignkey')
|
|
Pierre-Yves Chibon |
ffd53a |
op.create_foreign_key(
|
|
Pierre-Yves Chibon |
ffd53a |
name='pull_requests_project_id_from_fkey',
|
|
Pierre-Yves Chibon |
ffd53a |
source_table='pull_requests',
|
|
Pierre-Yves Chibon |
ffd53a |
referent_table='projects',
|
|
Pierre-Yves Chibon |
0e2c78 |
local_cols=['project_id_from'],
|
|
Pierre-Yves Chibon |
ffd53a |
remote_cols=['id'],
|
|
Pierre-Yves Chibon |
ffd53a |
onupdate='cascade',
|
|
Pierre-Yves Chibon |
ffd53a |
ondelete='cascade',
|
|
Pierre-Yves Chibon |
ffd53a |
)
|