service key migration

This commit is contained in:
Jimmy Zelinskie 2016-03-30 16:16:35 -04:00 committed by Jimmy Zelinskie
parent d277fe6741
commit dff59b4a39
3 changed files with 67 additions and 4 deletions

View file

@ -888,8 +888,8 @@ class ServiceKey(BaseModel):
name = CharField()
kid = CharField(unique=True, index=True)
service = CharField(index=True)
jwk = JSONField(unique=True)
metadata = JSONField(unique=True)
jwk = JSONField()
metadata = JSONField()
created_date = DateTimeField(default=datetime.utcnow)
expiration_date = DateTimeField(null=True)
approval = ForeignKeyField(ServiceKeyApproval, index=True, null=True)

View file

@ -28,7 +28,7 @@ up_mariadb() {
# Sleep for 10s to get MySQL get started.
echo 'Sleeping for 10...'
sleep 10
sleep 20
# Add the database to mysql.
docker run --rm --link mariadb:mariadb mariadb sh -c 'echo "create database genschema" | mysql -h"$MARIADB_PORT_3306_TCP_ADDR" -P"$MARIADB_PORT_3306_TCP_PORT" -uroot -ppassword'
@ -45,7 +45,7 @@ up_percona() {
# Sleep for 10s
echo 'Sleeping for 10...'
sleep 10
sleep 20
# Add the daabase to mysql.
docker run --rm --link percona:percona percona sh -c 'echo "create database genschema" | mysql -h $PERCONA_PORT_3306_TCP_ADDR -uroot -ppassword'

View file

@ -0,0 +1,63 @@
"""initial keyserver
Revision ID: a3ba52d02dec
Revises: e4129c93e477
Create Date: 2016-03-30 15:28:32.036753
"""
# revision identifiers, used by Alembic.
revision = 'a3ba52d02dec'
down_revision = 'e4129c93e477'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
from util.migrate import UTF8LongText
def upgrade(tables):
op.create_table(
'servicekeyapproval',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('approver_id', sa.Integer(), nullable=True),
sa.Column('approval_type', sa.String(length=255), nullable=False),
sa.Column('approved_date', sa.DateTime(), nullable=False),
sa.Column('notes', UTF8LongText(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_servicekeyapproval')),
)
op.bulk_insert(
tables.notificationkind,
[{'name':'service_key_submitted'}],
)
op.create_index('servicekeyapproval_approval_type', 'servicekeyapproval', ['approval_type'], unique=False)
op.create_index('servicekeyapproval_approver_id', 'servicekeyapproval', ['approver_id'], unique=False)
op.create_table(
'servicekey',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('kid', sa.String(length=255), nullable=False),
sa.Column('service', sa.String(length=255), nullable=False),
sa.Column('jwk', UTF8LongText(), nullable=False),
sa.Column('metadata', UTF8LongText(), nullable=False),
sa.Column('created_date', sa.DateTime(), nullable=False),
sa.Column('expiration_date', sa.DateTime(), nullable=True),
sa.Column('approval_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['approval_id'], ['servicekeyapproval.id'],
name=op.f('fk_servicekey_approval_id_servicekeyapproval')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_servicekey')),
)
op.create_index('servicekey_approval_id', 'servicekey', ['approval_id'], unique=False)
op.create_index('servicekey_kid', 'servicekey', ['kid'], unique=True)
op.create_index('servicekey_service', 'servicekey', ['service'], unique=False)
op.add_column(u'notification', sa.Column('lookup_path', sa.String(length=255), nullable=True))
op.create_index('notification_lookup_path', 'notification', ['lookup_path'], unique=False)
def downgrade(tables):
op.drop_column(u'notification', 'lookup_path')
op.drop_table('servicekey')
op.drop_table('servicekeyapproval')