Verified Commit 8e0b0974 authored by Huste, Tobias (FWCC) - 111645's avatar Huste, Tobias (FWCC) - 111645
Browse files

db: add initial alembic recipes

parent 1ded6119
Pipeline #8720 passed with stage
in 3 minutes and 11 seconds
......@@ -37,6 +37,7 @@ before_script:
- requirements-builder -e $EXTRAS --level=dev --req requirements-devel.txt setup.py > .ci-devel-requirements.txt
- pip install -r .ci-$REQUIREMENTS-requirements.txt
- pip install -e .[$EXTRAS]
- pip install -e git+https://github.com/inveniosoftware/invenio-webhooks.git#egg=invenio-webhooks
.base-job: &base-job
retry: 1
......
......@@ -36,6 +36,7 @@ recursive-include examples *.py
recursive-include examples *.sh
recursive-include invenio_gitlab *.html
recursive-include invenio_gitlab *.js
recursive-include invenio_gitlab *.py
recursive-include invenio_gitlab *.scss
recursive-include tests *.py
recursive-include tests *.json
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 HZDR
#
# This file is part of RODARE.
#
# invenio-gitlab 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.
#
# invenio-gitlab 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 Rodare. If not, see <http://www.gnu.org/licenses/>.
"""Create invenio-gitlab branch."""
import sqlalchemy as sa
from alembic import op
# revision identifier used by Alembic.
revision = '22860f41f06d'
down_revision = None
branch_labels = (u'invenio_gitlab',)
depends_on = 'dbdbc1b19cf2'
def upgrade():
"""Upgrade database."""
pass
def downgrade():
"""Downgrade database."""
pass
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 HZDR
#
# This file is part of RODARE.
#
# invenio-gitlab 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.
#
# invenio-gitlab 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 Rodare. If not, see <http://www.gnu.org/licenses/>.
"""Create invenio-gitlab tables."""
import uuid
from datetime import datetime
import sqlalchemy as sa
import sqlalchemy_utils
from alembic import op
# revision identifiers, used by Alembic.
revision = 'd3ba1d18340c'
down_revision = '22860f41f06d'
branch_labels = ()
depends_on = ('07fb52561c5c', 'a095bd179f5c', 'e12419831262')
def upgrade():
"""Upgrade database."""
op.create_table(
'gitlab_projects',
sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(),
default=uuid.uuid4),
sa.Column('gitlab_id', sa.Integer(), nullable=True),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('ping', sa.DateTime(), nullable=True),
sa.Column('hook', sa.Integer()),
sa.Column('release_regex', sa.String(length=255), default='v.*'),
# Inherited columns from sqlalchemy_utils.models:Timestamp
sa.Column('created', sa.DateTime(), default=datetime.utcnow,
nullable=False),
sa.Column('updated', sa.DateTime(), default=datetime.utcnow,
nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['user_id'], ['accounts_user.id']),
)
op.create_index(
op.f('ix_gitlab_projects_gitlab_id'), 'gitlab_projects',
['gitlab_id'], unique=True,
)
op.create_index(
op.f('ix_gitlab_projects_name'), 'gitlab_projects',
['name'], unique=True,
)
op.create_table(
'gitlab_releases',
sa.Column('id', sqlalchemy_utils.types.uuid.UUIDType(),
default=uuid.uuid4),
sa.Column('tag', sa.String(length=255)),
sa.Column('errors', sa.JSON().with_variant(
sa.dialects.postgresql.JSON(none_as_null=True), 'postgresql',
).with_variant(
sqlalchemy_utils.types.JSONType(), 'sqlite'
).with_variant(
sqlalchemy_utils.types.JSONType(), 'mysql'
), nullable=True),
sa.Column('project_id', sqlalchemy_utils.types.uuid.UUIDType()),
sa.Column('event_id', sqlalchemy_utils.types.uuid.UUIDType(),
nullable=True),
sa.Column('record_id', sqlalchemy_utils.types.uuid.UUIDType(),
nullable=True),
sa.Column('status', sa.CHAR(1), nullable=False),
# Inherited columns from sqlalchemy_utils.models:Timestamp
sa.Column('created', sa.DateTime(), default=datetime.utcnow,
nullable=False),
sa.Column('updated', sa.DateTime(), default=datetime.utcnow,
nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('tag', 'project_id'),
sa.ForeignKeyConstraint(['project_id'], ['gitlab_projects.id']),
sa.ForeignKeyConstraint(['event_id'], ['webhooks_events.id']),
sa.ForeignKeyConstraint(['record_id'], ['records_metadata.id']),
)
def downgrade():
"""Downgrade database."""
op.drop_index(op.f('ix_gitlab_projects_gitlab_id'),
table_name='gitlab_projects')
op.drop_index(op.f('ix_gitlab_projects_name'),
table_name='gitlab_projects')
op.drop_table('gitlab_releases')
op.drop_table('gitlab_projects')
......@@ -249,9 +249,12 @@ class Release(db.Model, Timestamp):
"""Release tag."""
errors = db.Column(
JSONType().with_variant(
postgresql.JSON(none_as_null=True),
'postgresql',
db.JSON().with_variant(
postgresql.JSON(none_as_null=True), 'postgresql',
).with_variant(
JSONType(), 'sqlite'
).with_variant(
JSONType(), 'mysql'
),
nullable=True,
)
......
......@@ -120,6 +120,9 @@ setup(
'invenio_celery.tasks': [
'invenio_gitlab = invenio_gitlab.tasks',
],
'invenio_db.alembic': [
'invenio_gitlab = invenio_gitlab:alembic',
],
'invenio_db.models': [
'invenio_gitlab = invenio_gitlab.models',
],
......
......@@ -41,6 +41,7 @@ from invenio_oauth2server import InvenioOAuth2Server
from invenio_oauthclient import InvenioOAuthClient
from invenio_oauthclient.views.client import blueprint as blueprint_client
from invenio_oauthclient.views.settings import blueprint as settings_blueprint
from invenio_records import InvenioRecords
from invenio_userprofiles import InvenioUserProfiles
from invenio_userprofiles.models import UserProfile
from invenio_webhooks import InvenioWebhooks
......@@ -108,6 +109,7 @@ def base_app(instance_path):
app_.register_blueprint(settings_blueprint)
InvenioOAuth2Server(app_)
InvenioUserProfiles(app_)
InvenioRecords(app_)
return app_
......
......@@ -21,7 +21,9 @@
from __future__ import absolute_import, print_function
import pytest
from flask import Flask
from invenio_db.utils import drop_alembic_version_table
from invenio_gitlab import InvenioGitLab
......@@ -43,3 +45,24 @@ def test_init():
assert 'invenio-gitlab' not in app.extensions
ext.init_app(app)
assert 'invenio-gitlab' in app.extensions
def test_alembic(app, db):
"""Test alembic recipes."""
ext = app.extensions['invenio-db']
if db.engine.name == 'sqlite':
raise pytest.skip('Upgrades are not supported on SQLite.')
assert not ext.alembic.compare_metadata()
db.drop_all()
drop_alembic_version_table()
ext.alembic.upgrade()
assert not ext.alembic.compare_metadata()
ext.alembic.stamp()
ext.alembic.downgrade(target='96e796392533')
ext.alembic.upgrade()
assert not ext.alembic.compare_metadata()
drop_alembic_version_table()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment