From 99b090462e1557dfa2e1ca5b92118b0b44017086 Mon Sep 17 00:00:00 2001 From: Gardient Date: Wed, 22 Sep 2021 19:36:41 +0300 Subject: [PATCH] Added registration migration --- api/__init__.py | 17 ++++---- .../5dfa048b8215_added_registrations.py | 41 +++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 migrations/versions/5dfa048b8215_added_registrations.py diff --git a/api/__init__.py b/api/__init__.py index 5da89db..fbad6c7 100644 --- a/api/__init__.py +++ b/api/__init__.py @@ -1,6 +1,6 @@ from flask import Flask, Blueprint -from . import commands, login, target_exchange, target +from . import commands, login, target_exchange, target, registration from .exceptions import ApiException from .extensions import db, migrate, jwt, apispec from .settings import ProdConfig, Config @@ -10,7 +10,7 @@ def create_app(config: Config = ProdConfig) -> Flask: """An application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/. - :param config_object: The configuration object to use. + :param config: The configuration object to use. """ app = Flask(__name__.split('.')[0]) app.url_map.strict_slashes = False @@ -37,12 +37,10 @@ def register_blueprints(app: Flask): """Register Flask blueprints.""" api_blueprint = Blueprint('api', __name__, url_prefix='/api') - api_blueprint.register_blueprint( - login.views.blueprint, url_prefix='/login') - api_blueprint.register_blueprint( - target_exchange.views.blueprint, url_prefix='/target-exchange') - api_blueprint.register_blueprint( - target.views.blueprint, url_prefix='/target') + api_blueprint.register_blueprint(login.views.blueprint, url_prefix='/login') + api_blueprint.register_blueprint(target_exchange.views.blueprint, url_prefix='/target-exchange') + api_blueprint.register_blueprint(target.views.blueprint, url_prefix='/target') + api_blueprint.register_blueprint(registration.views.blueprint, url_prefix='/registration') app.register_blueprint(api_blueprint) @@ -85,7 +83,8 @@ def register_shellcontext(app: Flask): return { 'db': db, 'TargetExchange': target_exchange.models.TargetExchange, - 'Target': target.models.Target + 'Target': target.models.Target, + 'Registration': registration.models.Registration, } app.shell_context_processor(shell_context) diff --git a/migrations/versions/5dfa048b8215_added_registrations.py b/migrations/versions/5dfa048b8215_added_registrations.py new file mode 100644 index 0000000..fbf1043 --- /dev/null +++ b/migrations/versions/5dfa048b8215_added_registrations.py @@ -0,0 +1,41 @@ +"""added registrations + +Revision ID: 5dfa048b8215 +Revises: 294a2085f840 +Create Date: 2021-09-22 19:35:23.584306 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '5dfa048b8215' +down_revision = '294a2085f840' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('registration', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('routing_key', sa.String(length=255), nullable=False), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + op.create_table('registration_target', + sa.Column('registration', sa.Integer(), nullable=True), + sa.Column('target', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['registration'], ['target.id'], ), + sa.ForeignKeyConstraint(['target'], ['registration.id'], ) + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table('registration_target') + op.drop_table('registration') + # ### end Alembic commands ###