<filename>migrations/versions/bbe1397dc8a9_hosting_service.py
"""Hosting Service

Revision ID: bbe1397dc8a9
Revises: 8b2e530dc029
Create Date: 2021-09-03 07:33:30.999951

"""
import logging

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = 'bbe1397dc8a9'
down_revision = '8b2e530dc029'
branch_labels = None
depends_on = None

# set logger
logger = logging.getLogger('alembic.env')


def upgrade():
    bind = op.get_bind()
    registries = bind.execute("SELECT id FROM workflow_registry")

    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('hosting_service',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['id'], ['resource.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.drop_constraint('workflow_registry_id_fkey', 'workflow_registry', type_='foreignkey')

    for r in registries:
        logger.info(r[0])
        bind.execute(f"INSERT INTO hosting_service (id) VALUES ({r[0]})")

    op.create_foreign_key(None, 'workflow_registry', 'hosting_service', ['id'], ['id'])

    # Fix relationship RO-Crate->HostingService
    op.drop_constraint("ro_crate_hosting_service_id_fkey", 'ro_crate', type_='foreignkey')
    op.create_foreign_key("ro_crate_hosting_service_id_fkey", 'ro_crate', 'hosting_service', ['hosting_service_id'], ['id'])

    # ### end Alembic commands ###


def downgrade():
    # Fix relationship RO-Crate->HostingService
    op.drop_constraint("ro_crate_hosting_service_id_fkey", 'ro_crate', type_='foreignkey')
    op.create_foreign_key("ro_crate_hosting_service_id_fkey", 'ro_crate', 'resource', ['hosting_service_id'], ['id'])

    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("workflow_registry_id_fkey", 'workflow_registry', type_='foreignkey')
    op.create_foreign_key('workflow_registry_id_fkey', 'workflow_registry', 'resource', ['id'], ['id'])
    op.drop_table('hosting_service')

    # ### end Alembic commands ###

<filename>migrations/versions/bbe1397dc8a9_hosting_service.py
"""Hosting Service

Revision ID: bbe1397dc8a9
Revises: 8b2e530dc029
Create Date: 2021-09-03 07:33:30.999951

"""
import logging

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = 'bbe1397dc8a9'
down_revision = '8b2e530dc029'
branch_labels = None
depends_on = None

# set logger
logger = logging.getLogger('alembic.env')


def upgrade():
    bind = op.get_bind()
    registries = bind.execute("SELECT id FROM workflow_registry")

    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('hosting_service',
                    sa.Column('id', sa.Integer(), nullable=False),
                    sa.ForeignKeyConstraint(['id'], ['resource.id'], ),
                    sa.PrimaryKeyConstraint('id')
                    )
    op.drop_constraint('workflow_registry_id_fkey', 'workflow_registry', type_='foreignkey')

    for r in registries:
        logger.info(r[0])
        bind.execute(f"INSERT INTO hosting_service (id) VALUES ({r[0]})")

    op.create_foreign_key(None, 'workflow_registry', 'hosting_service', ['id'], ['id'])

    # Fix relationship RO-Crate->HostingService
    op.drop_constraint("ro_crate_hosting_service_id_fkey", 'ro_crate', type_='foreignkey')
    op.create_foreign_key("ro_crate_hosting_service_id_fkey", 'ro_crate', 'hosting_service', ['hosting_service_id'], ['id'])

    # ### end Alembic commands ###


def downgrade():
    # Fix relationship RO-Crate->HostingService
    op.drop_constraint("ro_crate_hosting_service_id_fkey", 'ro_crate', type_='foreignkey')
    op.create_foreign_key("ro_crate_hosting_service_id_fkey", 'ro_crate', 'resource', ['hosting_service_id'], ['id'])

    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint("workflow_registry_id_fkey", 'workflow_registry', type_='foreignkey')
    op.create_foreign_key('workflow_registry_id_fkey', 'workflow_registry', 'resource', ['id'], ['id'])
    op.drop_table('hosting_service')

    # ### end Alembic commands ###

Hosting Service  Revision ID: bbe1397dc8a9 Revises: 8b2e530dc029 Create Date: 2021-09-03 07:33:30.999951 # revision identifiers, used by Alembic. # set logger # ### commands auto generated by Alembic - please adjust! ### # Fix relationship RO-Crate->HostingService # ### end Alembic commands ### # Fix relationship RO-Crate->HostingService # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###