Add a table for attachments
This commit adds a model and migration for storing links to and metadata about attachments in the StoryBoard database. Change-Id: Ib2e291f5cc80222b226627d076ba3e1f5b88a454 Story: 2000679 Task: 3146
This commit is contained in:
parent
6b805aafce
commit
29428572cc
@ -0,0 +1,65 @@
|
|||||||
|
# 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 an attachments table
|
||||||
|
|
||||||
|
Revision ID: 067
|
||||||
|
Revises: 066
|
||||||
|
Create Date: 2019-01-27 16:07:04.427155
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '067'
|
||||||
|
down_revision = '066'
|
||||||
|
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
from oslo_log import log
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
import storyboard
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(active_plugins=None, options=None):
|
||||||
|
op.create_table('attachments',
|
||||||
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('created_at', storyboard.db.decorators.UTCDateTime(),
|
||||||
|
nullable=True),
|
||||||
|
sa.Column('updated_at', storyboard.db.decorators.UTCDateTime(),
|
||||||
|
nullable=True),
|
||||||
|
sa.Column('name', sa.Unicode(length=255), nullable=False),
|
||||||
|
sa.Column('link', sa.UnicodeText(), nullable=False),
|
||||||
|
sa.Column('creator_id', sa.Integer(), nullable=False, index=True),
|
||||||
|
sa.Column('story_id', sa.Integer(), nullable=False, index=True),
|
||||||
|
sa.ForeignKeyConstraint(['creator_id'], ['users.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['story_id'], ['stories.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
|
||||||
|
version_info = op.get_bind().engine.dialect.server_version_info
|
||||||
|
if version_info[-1] == "MariaDB":
|
||||||
|
# Removes fake mysql prefix
|
||||||
|
version_info = version_info[-4:]
|
||||||
|
if version_info[0] < 5 or version_info[0] == 5 and version_info[1] < 6:
|
||||||
|
LOG.warning(
|
||||||
|
"MySQL version is lower than 5.6. Skipping full-text index")
|
||||||
|
return
|
||||||
|
|
||||||
|
op.execute("ALTER TABLE attachments ADD FULLTEXT attachments_fti (name)")
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(active_plugins=None, options=None):
|
||||||
|
op.drop_table('attachments')
|
@ -1,6 +1,7 @@
|
|||||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||||
# Copyright 2013 Thierry Carrez <thierry@openstack.org>
|
# Copyright 2013 Thierry Carrez <thierry@openstack.org>
|
||||||
# Copyright 2015-2016 Codethink Ltd.
|
# Copyright 2015-2016 Codethink Ltd.
|
||||||
|
# Copyright 2019 Adam Coldrick
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
@ -360,6 +361,20 @@ class Task(FullText, ModelBuilder, Base):
|
|||||||
"milestone_id"]
|
"milestone_id"]
|
||||||
|
|
||||||
|
|
||||||
|
class Attachment(FullText, ModelBuilder, Base):
|
||||||
|
__tablename__ = 'attachments'
|
||||||
|
__fulltext_columns__ = ['name']
|
||||||
|
|
||||||
|
name = Column(Unicode(CommonLength.top_large_length), nullable=False)
|
||||||
|
link = Column(UnicodeText(), nullable=False)
|
||||||
|
creator_id = Column(
|
||||||
|
Integer, ForeignKey('users.id'), nullable=False, index=True)
|
||||||
|
story_id = Column(
|
||||||
|
Integer, ForeignKey('stories.id'), nullable=False, index=True)
|
||||||
|
|
||||||
|
_public_fields = ["id", "name", "link", "creator_id", "story_id"]
|
||||||
|
|
||||||
|
|
||||||
story_permissions = Table(
|
story_permissions = Table(
|
||||||
'story_permissions', Base.metadata,
|
'story_permissions', Base.metadata,
|
||||||
Column('story_id', Integer, ForeignKey('stories.id')),
|
Column('story_id', Integer, ForeignKey('stories.id')),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user