Skip to content

Commit

Permalink
alembic: Create workflow_record_resources table
Browse files Browse the repository at this point in the history
Signed-off-by: Zacharias Zacharodimos <[email protected]>
  • Loading branch information
zzacharo authored and ammirate committed Nov 22, 2017
1 parent f04c1a4 commit ec6ae1f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
#
# This file is part of INSPIRE.
# Copyright (C) 2014-2017 CERN.
#
# INSPIRE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# INSPIRE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>.
#
# In applying this license, CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.

"""Create `workflow_record_resources` table"""

from __future__ import absolute_import, division, print_function

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from sqlalchemy_utils.types import JSONType, UUIDType

# revision identifiers, used by Alembic.
revision = 'cb5153afd839'
down_revision = 'fddb3cfe7a9c'
branch_labels = ()
depends_on = '862037093962'


def upgrade():
"""Upgrade database."""
op.create_table(
'workflows_record_sources',
sa.Column('source', sa.Text, default='', nullable=False),
sa.Column('record_id', UUIDType, sa.ForeignKey('records_metadata.id', ondelete='CASCADE'), nullable=False),
sa.PrimaryKeyConstraint('record_id', 'source'),
sa.Column('json',
JSONType().with_variant(postgresql.JSON(none_as_null=True), 'postgresql'),
default=lambda: dict(),
nullable=True
),
)


def downgrade():
"""Downgrade database."""
op.drop_table('workflows_record_sources')
23 changes: 23 additions & 0 deletions tests/integration/test_alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,26 @@ def get_indexes(tablename):
assert 'idxgincollections' in index_names

drop_alembic_version_table()


def test_alembic_revision_cb5153afd839(alembic_app):
ext = alembic_app.extensions['invenio-db']

if db.engine.name == 'sqlite':
raise pytest.skip('Upgrades are not supported on SQLite.')

db.drop_all()
drop_alembic_version_table()

inspector = inspect(db.engine)
assert 'workflows_record_sources' not in inspector.get_table_names()

ext.alembic.upgrade(target='cb5153afd839')
inspector = inspect(db.engine)
assert 'workflows_record_sources' in inspector.get_table_names()

ext.alembic.downgrade(target='fddb3cfe7a9c')
inspector = inspect(db.engine)
assert 'workflows_record_sources' not in inspector.get_table_names()

drop_alembic_version_table()

0 comments on commit ec6ae1f

Please sign in to comment.