diff --git a/inspirehep/alembic/cb5153afd839_create_workflow_record_resources_table.py b/inspirehep/alembic/cb5153afd839_create_workflow_record_resources_table.py new file mode 100644 index 0000000000..61050ae9f5 --- /dev/null +++ b/inspirehep/alembic/cb5153afd839_create_workflow_record_resources_table.py @@ -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 . +# +# 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') diff --git a/tests/integration/test_alembic.py b/tests/integration/test_alembic.py index efbb51359e..a1ed9799a4 100644 --- a/tests/integration/test_alembic.py +++ b/tests/integration/test_alembic.py @@ -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()