Browse Source

Function versioning: db scheme support

Spec reference:
https://docs.openstack.org/qinling/latest/specs/function_versioning.html

Change-Id: I0c31ca2de866c9ecbe2a7caaa9e8ab660efb78e9
story: #2001829
task: #12585
changes/19/560719/2
Lingxian Kong 3 years ago
parent
commit
39a5a057dd
  1. 63
      qinling/db/sqlalchemy/migration/alembic_migrations/versions/002_add_function_version_support.py
  2. 24
      qinling/db/sqlalchemy/models.py

63
qinling/db/sqlalchemy/migration/alembic_migrations/versions/002_add_function_version_support.py

@ -0,0 +1,63 @@
# 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 version support
Revision ID: 002
Revises: 001
Create Date: 2018-04-12 00:12:45.461970
"""
# revision identifiers, used by Alembic.
revision = '002'
down_revision = '001'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.create_table(
'function_versions',
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('function_id', sa.String(length=36), nullable=False),
sa.Column('description', sa.String(length=255), nullable=True),
sa.Column('version_number', sa.Integer, nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['function_id'], [u'functions.id']),
sa.UniqueConstraint('function_id', 'version_number', 'project_id'),
sa.Index(
'function_versions_project_id_function_id_version_number',
'project_id', 'function_id', 'version_number'
)
)
op.add_column(
'executions',
sa.Column('function_version', sa.Integer, nullable=False),
)
op.add_column(
'jobs',
sa.Column('function_version', sa.Integer, nullable=False),
)
op.add_column(
'webhooks',
sa.Column('function_version', sa.Integer, nullable=False),
)

24
qinling/db/sqlalchemy/models.py

@ -54,6 +54,7 @@ class Execution(model_base.QinlingSecureModelBase):
__tablename__ = 'executions'
function_id = sa.Column(sa.String(36), nullable=False)
function_version = sa.Column(sa.Integer, default=0)
status = sa.Column(sa.String(32), nullable=False)
sync = sa.Column(sa.BOOLEAN, default=True)
input = sa.Column(st.JsonLongDictType())
@ -77,6 +78,7 @@ class Job(model_base.QinlingSecureModelBase):
)
function = relationship('Function', back_populates="jobs")
function_input = sa.Column(sa.String(255), nullable=True)
function_version = sa.Column(sa.Integer, default=0)
def to_dict(self):
d = super(Job, self).to_dict()
@ -92,9 +94,31 @@ class Webhook(model_base.QinlingSecureModelBase):
sa.String(36),
sa.ForeignKey(Function.id)
)
function_version = sa.Column(sa.Integer, default=0)
description = sa.Column(sa.String(255))
class FunctionVersion(model_base.QinlingSecureModelBase):
__tablename__ = 'function_versions'
__table_args__ = (
sa.UniqueConstraint('project_id', 'function_id', 'version_number'),
sa.Index(
'%s_project_id_function_id_version_number' % __tablename__,
'project_id',
'function_id',
'version_number'
)
)
function_id = sa.Column(
sa.String(36),
sa.ForeignKey(Function.id)
)
description = sa.Column(sa.String(255), nullable=True)
version_number = sa.Column(sa.Integer, default=0)
Runtime.functions = relationship("Function", back_populates="runtime")
# Only get running jobs

Loading…
Cancel
Save