diff options
| author | rubenwardy <rw@rubenwardy.com> | 2020-07-08 22:45:24 +0100 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2020-07-08 22:45:24 +0100 |
| commit | a72b9a174ab6b811a53b47811384c76da1c524be (patch) | |
| tree | 05e4712293e24c1bb8f27280d435a78745535ef9 /migrations | |
| parent | ecb3d83c57b00684e2cc1b8740df3df4510be720 (diff) | |
| download | cheatdb-a72b9a174ab6b811a53b47811384c76da1c524be.tar.xz | |
Add support for package maintainers
Fixes #159
Diffstat (limited to 'migrations')
| -rw-r--r-- | migrations/versions/cb6ab141c522_.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/migrations/versions/cb6ab141c522_.py b/migrations/versions/cb6ab141c522_.py new file mode 100644 index 0000000..33da88b --- /dev/null +++ b/migrations/versions/cb6ab141c522_.py @@ -0,0 +1,45 @@ +"""empty message + +Revision ID: cb6ab141c522 +Revises: 7a48dbd05780 +Create Date: 2020-07-08 21:03:51.856561 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy import orm +from app.models import Package + + +# revision identifiers, used by Alembic. +revision = 'cb6ab141c522' +down_revision = '7a48dbd05780' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('maintainers', + sa.Column('user_id', sa.Integer(), nullable=False), + sa.Column('package_id', sa.Integer(), nullable=False), + sa.ForeignKeyConstraint(['package_id'], ['package.id'], ), + sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), + sa.PrimaryKeyConstraint('user_id', 'package_id') + ) + + bind = op.get_bind() + session = orm.Session(bind=bind) + + for package in session.query(Package).all(): + package.maintainers.append(package.author) + + session.commit() + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('maintainers') + # ### end Alembic commands ### |
