Skip to content

Commit

Permalink
fix test, add alembic migration
Browse files Browse the repository at this point in the history
  • Loading branch information
steiza committed Oct 27, 2018
1 parent 365844a commit fe8f05f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/unit/accounts/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def test_get_tokens_by_username(self, user_service):
account_token = AccountTokenFactory.create(username=user.username)

found_account_token = user_service.get_tokens_by_username(user.username)
assert found_account_token.id == account_token.id
assert account_token in found_account_token


class TestTokenService:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
add accounts_token table to store API key state
Revision ID: ac7073f2f9f2
Revises: e82c3a017d60
Create Date: 2018-08-22 12:48:48.526328
"""

from alembic import op
import citext
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision = "ac7073f2f9f2"
down_revision = "e82c3a017d60"

# Note: It is VERY important to ensure that a migration does not lock for a
# long period of time and to ensure that each individual migration does
# not break compatibility with the *previous* version of the code base.
# This is because the migrations will be ran automatically as part of the
# deployment process, but while the previous version of the code is still
# up and running. Thus backwards incompatible changes must be broken up
# over multiple migrations inside of multiple pull requests in order to
# phase them in over multiple deploys.


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"accounts_token",
sa.Column(
"id",
postgresql.UUID(as_uuid=True),
server_default=sa.text("gen_random_uuid()"),
nullable=False,
),
sa.Column("username", citext.CIText(), nullable=True),
sa.Column("description", sa.String(length=100), nullable=True),
sa.Column("is_active", sa.Boolean(), server_default="TRUE", nullable=True),
sa.Column(
"created", sa.DateTime(), server_default=sa.text("now()"), nullable=True
),
sa.Column("last_used", sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(
["username"],
["accounts_user.username"],
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("accounts_token")
# ### end Alembic commands ###

0 comments on commit fe8f05f

Please sign in to comment.