]> git.lizzy.rs Git - cheatdb.git/blob - migrations/versions/cb6ab141c522_.py
Fix migration error when migrating from scratch
[cheatdb.git] / migrations / versions / cb6ab141c522_.py
1 """empty message
2
3 Revision ID: cb6ab141c522
4 Revises: 7a48dbd05780
5 Create Date: 2020-07-08 21:03:51.856561
6
7 """
8 from alembic import op
9 import sqlalchemy as sa
10 from sqlalchemy import orm
11 from app.models import Package
12
13
14 # revision identifiers, used by Alembic.
15 revision = 'cb6ab141c522'
16 down_revision = '7a48dbd05780'
17 branch_labels = None
18 depends_on = None
19
20
21 def upgrade():
22         # ### commands auto generated by Alembic - please adjust! ###
23         op.create_table('maintainers',
24         sa.Column('user_id', sa.Integer(), nullable=False),
25         sa.Column('package_id', sa.Integer(), nullable=False),
26         sa.ForeignKeyConstraint(['package_id'], ['package.id'], ),
27         sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
28         sa.PrimaryKeyConstraint('user_id', 'package_id')
29         )
30
31         bind = op.get_bind()
32         session = orm.Session(bind=bind)
33
34         op.execute('INSERT INTO maintainers (package_id, user_id) SELECT id, author_id FROM package;')
35
36         session.commit()
37
38         # ### end Alembic commands ###
39
40
41 def downgrade():
42         # ### commands auto generated by Alembic - please adjust! ###
43         op.drop_table('maintainers')
44         # ### end Alembic commands ###