|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | +# you may not use this file except in compliance with the License. |
| 3 | +# You may obtain a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | +""" |
| 13 | +add accounts_token table to store API key state |
| 14 | +
|
| 15 | +Revision ID: ac7073f2f9f2 |
| 16 | +Revises: e82c3a017d60 |
| 17 | +Create Date: 2018-08-22 12:48:48.526328 |
| 18 | +""" |
| 19 | + |
| 20 | +from alembic import op |
| 21 | +import citext |
| 22 | +import sqlalchemy as sa |
| 23 | +from sqlalchemy.dialects import postgresql |
| 24 | + |
| 25 | +revision = "ac7073f2f9f2" |
| 26 | +down_revision = "e82c3a017d60" |
| 27 | + |
| 28 | +# Note: It is VERY important to ensure that a migration does not lock for a |
| 29 | +# long period of time and to ensure that each individual migration does |
| 30 | +# not break compatibility with the *previous* version of the code base. |
| 31 | +# This is because the migrations will be ran automatically as part of the |
| 32 | +# deployment process, but while the previous version of the code is still |
| 33 | +# up and running. Thus backwards incompatible changes must be broken up |
| 34 | +# over multiple migrations inside of multiple pull requests in order to |
| 35 | +# phase them in over multiple deploys. |
| 36 | + |
| 37 | + |
| 38 | +def upgrade(): |
| 39 | + # ### commands auto generated by Alembic - please adjust! ### |
| 40 | + op.create_table( |
| 41 | + "accounts_token", |
| 42 | + sa.Column( |
| 43 | + "id", |
| 44 | + postgresql.UUID(as_uuid=True), |
| 45 | + server_default=sa.text("gen_random_uuid()"), |
| 46 | + nullable=False, |
| 47 | + ), |
| 48 | + sa.Column("username", citext.CIText(), nullable=True), |
| 49 | + sa.Column("description", sa.String(length=100), nullable=True), |
| 50 | + sa.Column("is_active", sa.Boolean(), server_default="TRUE", nullable=True), |
| 51 | + sa.Column( |
| 52 | + "created", sa.DateTime(), server_default=sa.text("now()"), nullable=True |
| 53 | + ), |
| 54 | + sa.Column("last_used", sa.DateTime(), nullable=True), |
| 55 | + sa.ForeignKeyConstraint( |
| 56 | + ["username"], |
| 57 | + ["accounts_user.username"], |
| 58 | + onupdate="CASCADE", |
| 59 | + ondelete="CASCADE", |
| 60 | + ), |
| 61 | + sa.PrimaryKeyConstraint("id"), |
| 62 | + ) |
| 63 | + # ### end Alembic commands ### |
| 64 | + |
| 65 | + |
| 66 | +def downgrade(): |
| 67 | + # ### commands auto generated by Alembic - please adjust! ### |
| 68 | + op.drop_table("accounts_token") |
| 69 | + # ### end Alembic commands ### |
0 commit comments