parent
41c5d261af
commit
fdc287bb61
@ -0,0 +1,40 @@ |
||||
"""Allow articles to be associated with a publisher. |
||||
|
||||
Revision ID: a33edb7272a2 |
||||
Revises: 21ec84874208 |
||||
Create Date: 2021-10-22 20:10:50.440849 |
||||
|
||||
""" |
||||
from alembic import op |
||||
import sqlalchemy as sa |
||||
|
||||
|
||||
# revision identifiers, used by Alembic. |
||||
revision = 'a33edb7272a2' |
||||
down_revision = '21ec84874208' |
||||
branch_labels = None |
||||
depends_on = None |
||||
|
||||
|
||||
from alembic import context |
||||
is_sqlite = context.config.get_main_option( "sqlalchemy.url" ).startswith( "sqlite://" ) |
||||
|
||||
|
||||
def upgrade(): |
||||
# ### commands auto generated by Alembic - please adjust! ### |
||||
op.add_column('article', sa.Column('publ_id', sa.Integer(), nullable=True)) |
||||
if is_sqlite: |
||||
op.execute( "PRAGMA foreign_keys = off" ) # nb: stop cascading deletes |
||||
with op.batch_alter_table('article') as batch_op: |
||||
batch_op.create_foreign_key('fk_article_publisher', 'publisher', ['publ_id'], ['publ_id'], ondelete='CASCADE') |
||||
# ### end Alembic commands ### |
||||
|
||||
|
||||
def downgrade(): |
||||
# ### commands auto generated by Alembic - please adjust! ### |
||||
if is_sqlite: |
||||
op.execute( "PRAGMA foreign_keys = off" ) # nb: stop cascading deletes |
||||
with op.batch_alter_table('article') as batch_op: |
||||
batch_op.drop_constraint('fk_article_publisher', type_='foreignkey') |
||||
op.drop_column('article', 'publ_id') |
||||
# ### end Alembic commands ### |
@ -0,0 +1,17 @@ |
||||
{ |
||||
|
||||
"publisher": [ |
||||
{ "publ_id": 1, "publ_name": "Avalon Hill" }, |
||||
{ "publ_id": 2, "publ_name": "Multiman Publishing" }, |
||||
{ "publ_id": 3, "publ_name": "Le Franc Tireur" } |
||||
], |
||||
|
||||
"publication": [ |
||||
{ "pub_id": 20, "pub_name": "MMP News", "publ_id": 2 } |
||||
], |
||||
|
||||
"article": [ |
||||
{ "article_id": 200, "article_title": "MMP Today", "pub_id": 20 } |
||||
] |
||||
|
||||
} |
Loading…
Reference in new issue