diff --git a/qinling/db/sqlalchemy/migration/alembic_migrations/versions/004_add_function_aliases_support.py b/qinling/db/sqlalchemy/migration/alembic_migrations/versions/004_add_function_aliases_support.py new file mode 100644 index 00000000..5e5b6286 --- /dev/null +++ b/qinling/db/sqlalchemy/migration/alembic_migrations/versions/004_add_function_aliases_support.py @@ -0,0 +1,54 @@ +# Copyright 2018 OpenStack Foundation. +# +# 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 function aliases support + +Revision ID: 004 +Revises: 003 +Create Date: 2018-05-17 03:09:04.888969 + +""" + +# revision identifiers, used by Alembic. +revision = '004' +down_revision = '003' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.create_table( + 'function_aliases', + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.Column('project_id', sa.String(length=80), nullable=False), + sa.Column('id', sa.String(length=36), nullable=False), + sa.Column('name', sa.String(length=255), nullable=False), + sa.Column('function_id', sa.String(length=36), nullable=False), + sa.Column('function_version', sa.Integer, nullable=False), + sa.Column('description', sa.String(length=255), nullable=True), + sa.PrimaryKeyConstraint('id'), + sa.ForeignKeyConstraint(['function_id'], [u'functions.id']), + sa.UniqueConstraint('function_id', 'function_version', 'project_id'), + sa.UniqueConstraint('name', 'project_id'), + sa.Index( + 'function_aliases_project_id_function_id_function_version', + 'project_id', 'function_id', 'function_version' + ), + sa.Index( + 'function_aliases_project_id_name', + 'project_id', 'name' + ) + ) diff --git a/qinling/db/sqlalchemy/models.py b/qinling/db/sqlalchemy/models.py index e7eb1545..d7764532 100644 --- a/qinling/db/sqlalchemy/models.py +++ b/qinling/db/sqlalchemy/models.py @@ -119,6 +119,34 @@ class FunctionVersion(model_base.QinlingSecureModelBase): count = sa.Column(sa.Integer, default=0) +class FunctionAlias(model_base.QinlingSecureModelBase): + __tablename__ = 'function_aliases' + + __table_args__ = ( + sa.UniqueConstraint('project_id', 'function_id', 'function_version'), + sa.Index( + '%s_project_id_function_id_function_version' % __tablename__, + 'project_id', + 'function_id', + 'function_version' + ), + sa.UniqueConstraint('project_id', 'name'), + sa.Index( + '%s_project_id_name' % __tablename__, + 'project_id', + 'name' + ) + ) + + function_id = sa.Column( + sa.String(36), + sa.ForeignKey(Function.id) + ) + name = sa.Column(sa.String(255), nullable=False) + description = sa.Column(sa.String(255), nullable=True) + function_version = sa.Column(sa.Integer, default=0) + + # Only get running jobs Function.jobs = relationship( "Job",