|
| 1 | +"""Create existing tables |
| 2 | +
|
| 3 | +Revision ID: 103676e0a497 |
| 4 | +Revises: |
| 5 | +Create Date: 2018-09-04 16:57:42.622504 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | +# revision identifiers, used by Alembic. |
| 12 | +revision = '103676e0a497' |
| 13 | +down_revision = None |
| 14 | +branch_labels = None |
| 15 | +depends_on = None |
| 16 | + |
| 17 | + |
| 18 | +def upgrade(): |
| 19 | + |
| 20 | + op.create_table( |
| 21 | + 'state', |
| 22 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 23 | + sa.Column('name', sa.Unicode(100)), |
| 24 | + ) |
| 25 | + |
| 26 | + op.create_table( |
| 27 | + 'revision', |
| 28 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 29 | + sa.Column('timestamp', sa.DateTime(timezone=False)), |
| 30 | + sa.Column('author', sa.Unicode(200)), |
| 31 | + sa.Column('message', sa.UnicodeText()), |
| 32 | + sa.Column('state_id', sa.Integer), |
| 33 | + ) |
| 34 | + |
| 35 | + op.create_table( |
| 36 | + 'apikey', |
| 37 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 38 | + sa.Column('name', sa.UnicodeText()), |
| 39 | + sa.Column('key', sa.UnicodeText()), |
| 40 | + ) |
| 41 | + |
| 42 | + op.create_table( |
| 43 | + 'license', |
| 44 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 45 | + sa.Column('name', sa.Unicode(100)), sa.Column('state_id', sa.Integer) |
| 46 | + ) |
| 47 | + |
| 48 | + op.create_table( |
| 49 | + 'package', |
| 50 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 51 | + sa.Column('name', sa.Unicode(100), nullable=False, unique=True), |
| 52 | + sa.Column('title', sa.UnicodeText()), |
| 53 | + sa.Column('version', sa.Unicode(100)), |
| 54 | + sa.Column('url', sa.UnicodeText()), |
| 55 | + sa.Column('download_url', sa.UnicodeText()), |
| 56 | + sa.Column('notes', sa.UnicodeText()), |
| 57 | + sa.Column('license_id', sa.Integer, sa.ForeignKey('license.id')), |
| 58 | + sa.Column('state_id', sa.Integer, sa.ForeignKey('state.id')), |
| 59 | + sa.Column('revision_id', sa.Integer, sa.ForeignKey('revision.id')), |
| 60 | + ) |
| 61 | + |
| 62 | + op.create_table( |
| 63 | + 'package_revision', |
| 64 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 65 | + sa.Column('name', sa.Unicode(100), nullable=False), |
| 66 | + sa.Column('title', sa.UnicodeText()), |
| 67 | + sa.Column('version', sa.Unicode(100)), |
| 68 | + sa.Column('url', sa.UnicodeText()), |
| 69 | + sa.Column('download_url', sa.UnicodeText()), |
| 70 | + sa.Column('notes', sa.UnicodeText()), |
| 71 | + sa.Column('license_id', sa.Integer, sa.ForeignKey('license.id')), |
| 72 | + sa.Column('state_id', sa.Integer, sa.ForeignKey('state.id')), |
| 73 | + sa.Column( |
| 74 | + 'revision_id', |
| 75 | + sa.Integer, |
| 76 | + sa.ForeignKey('revision.id'), |
| 77 | + primary_key=True |
| 78 | + ), |
| 79 | + sa.Column('continuity_id', sa.Integer, sa.ForeignKey('package.id')), |
| 80 | + ) |
| 81 | + |
| 82 | + op.create_table( |
| 83 | + 'tag', |
| 84 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 85 | + sa.Column('name', sa.Unicode(100), nullable=False, unique=True), |
| 86 | + ) |
| 87 | + |
| 88 | + op.create_table( |
| 89 | + 'package_tag', |
| 90 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 91 | + sa.Column('package_id', sa.Integer, sa.ForeignKey('package.id')), |
| 92 | + sa.Column('tag_id', sa.Integer, sa.ForeignKey('tag.id')), |
| 93 | + sa.Column('state_id', sa.Integer, sa.ForeignKey('state.id')), |
| 94 | + sa.Column('revision_id', sa.Integer, sa.ForeignKey('revision.id')), |
| 95 | + ) |
| 96 | + |
| 97 | + op.create_table( |
| 98 | + 'package_tag_revision', |
| 99 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 100 | + sa.Column('package_id', sa.Integer, sa.ForeignKey('package.id')), |
| 101 | + sa.Column('tag_id', sa.Integer, sa.ForeignKey('tag.id')), |
| 102 | + sa.Column('state_id', sa.Integer, sa.ForeignKey('state.id')), |
| 103 | + sa.Column( |
| 104 | + 'revision_id', |
| 105 | + sa.Integer, |
| 106 | + sa.ForeignKey('revision.id'), |
| 107 | + primary_key=True |
| 108 | + ), |
| 109 | + sa.Column( |
| 110 | + 'continuity_id', sa.Integer, sa.ForeignKey('package_tag.id') |
| 111 | + ), |
| 112 | + ) |
| 113 | + |
| 114 | + op.create_table( |
| 115 | + 'package_extra', |
| 116 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 117 | + sa.Column('package_id', sa.Integer, sa.ForeignKey('package.id')), |
| 118 | + sa.Column('key', sa.UnicodeText()), |
| 119 | + sa.Column('value', sa.UnicodeText()), |
| 120 | + sa.Column('state_id', sa.Integer, sa.ForeignKey('state.id')), |
| 121 | + sa.Column('revision_id', sa.Integer, sa.ForeignKey('revision.id')), |
| 122 | + ) |
| 123 | + |
| 124 | + op.create_table( |
| 125 | + 'package_extra_revision', |
| 126 | + sa.Column('id', sa.Integer, primary_key=True, nullable=False), |
| 127 | + sa.Column('package_id', sa.Integer, sa.ForeignKey('package.id')), |
| 128 | + sa.Column('key', sa.UnicodeText()), |
| 129 | + sa.Column('value', sa.UnicodeText()), |
| 130 | + sa.Column('state_id', sa.Integer, sa.ForeignKey('state.id')), |
| 131 | + sa.Column( |
| 132 | + 'revision_id', |
| 133 | + sa.Integer, |
| 134 | + sa.ForeignKey('revision.id'), |
| 135 | + primary_key=True |
| 136 | + ), |
| 137 | + sa.Column( |
| 138 | + 'continuity_id', sa.Integer, sa.ForeignKey('package_extra.id') |
| 139 | + ), |
| 140 | + ) |
| 141 | + |
| 142 | + |
| 143 | +def downgrade(): |
| 144 | + op.drop_table('package_extra_revision') |
| 145 | + op.drop_table('package_extra') |
| 146 | + op.drop_table('package_tag_revision') |
| 147 | + op.drop_table('package_tag') |
| 148 | + op.drop_table('tag') |
| 149 | + op.drop_table('package_revision') |
| 150 | + op.drop_table('package') |
| 151 | + op.drop_table('license') |
| 152 | + op.drop_table('apikey') |
| 153 | + op.drop_table('revision') |
| 154 | + op.drop_table('state') |
0 commit comments