Generate alembic migration scripts for new models.

Generate alembic migration scripts for new database models.

Change-Id: Ifed2bf405a620cf8201a28fe8400bc6b1a30b1e4
This commit is contained in:
Robert Putt 2017-11-30 21:10:42 +00:00
parent 1836ccbc6b
commit 9b661abd2a
4 changed files with 92 additions and 8 deletions

View File

@ -0,0 +1,53 @@
"""Initial models
Revision ID: 53784f13e35d
Revises: fecb5e4a7be4
Create Date: 2017-11-30 21:10:13.531156
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '53784f13e35d'
down_revision = 'fecb5e4a7be4'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('lookup_request')
op.drop_table('file')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('file',
sa.Column('file_id', sa.BIGINT(), nullable=False),
sa.Column('sha512_hash', sa.TEXT(), nullable=True),
sa.Column('sha256_hash', sa.TEXT(), nullable=True),
sa.Column('sha1_hash', sa.TEXT(), nullable=True),
sa.Column('md5_hash', sa.TEXT(), nullable=True),
sa.Column('crc32', sa.TEXT(), nullable=True),
sa.Column('size', sa.FLOAT(), nullable=True),
sa.Column('mime_type', sa.VARCHAR(length=40), nullable=True),
sa.Column('submitted_by', sa.VARCHAR(length=120), nullable=False),
sa.Column('status', sa.VARCHAR(length=20), nullable=False),
sa.Column('last_updated', sa.DATETIME(), nullable=False),
sa.Column('first_seen', sa.DATETIME(), nullable=False),
sa.PrimaryKeyConstraint('file_id')
)
op.create_table('lookup_request',
sa.Column('request_id', sa.BIGINT(), nullable=False),
sa.Column('requested_at', sa.DATETIME(), nullable=False),
sa.Column('requestor', sa.VARCHAR(length=120), nullable=False),
sa.Column('file_id', sa.BIGINT(), nullable=True),
sa.Column('lookup_hash', sa.TEXT(), nullable=False),
sa.Column('result', sa.VARCHAR(length=20), nullable=False),
sa.ForeignKeyConstraint(['file_id'], ['file.file_id'], ),
sa.PrimaryKeyConstraint('request_id')
)
# ### end Alembic commands ###

View File

@ -0,0 +1,28 @@
"""Blank initial database
Revision ID: fecb5e4a7be4
Revises:
Create Date: 2017-11-30 21:01:52.006085
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'fecb5e4a7be4'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###

View File

@ -1,15 +1,15 @@
[DEFAULT]
[keystone_authtoken]
identity_uri =
auth_uri =
admin_tenant_name =
admin_user =
admin_password =
auth_version =
auth_protocol =
identity_uri =
auth_uri =
admin_tenant_name =
admin_user =
admin_password =
auth_version =
auth_protocol =
delay_auth_decision = True
[sqlalchemy]
database_uri = sqlite:////tmp/nemesis.db
database_uri = sqlite:////tmp/nemesis.db
echo = true

View File

@ -15,6 +15,8 @@
from flask import Blueprint
from python_nemesis.exceptions import general_handler
from python_nemesis.exceptions import NemesisException
from python_nemesis.extensions import db
from python_nemesis.db.models import FileLookupRequest, Files
V1_API = Blueprint('v1_api', __name__)
@ -27,4 +29,5 @@ def handle_exception(error):
@V1_API.route('/v1')
def api_definition():
db.create_all()
return ""