def METHOD_NAME():
    if skip_based_on_legacy_engine_version(op, __name__):
        return
    op.create_table(
        'resource_group',
        sa.Column('id', sa.UnicodeText, primary_key=True),
        sa.Column('package_id', sa.UnicodeText, sa.ForeignKey('package.id')),
        sa.Column('label', sa.UnicodeText),
        sa.Column('sort_order', sa.UnicodeText),
        sa.Column('extras', sa.UnicodeText),
        sa.Column('state', sa.UnicodeText),
        sa.Column('revision_id', sa.UnicodeText, sa.ForeignKey('revision.id')),
    )
    op.create_table(
        'resource_group_revision',
        sa.Column('id', sa.UnicodeText, primary_key=True),
        sa.Column('package_id', sa.UnicodeText, sa.ForeignKey('package.id')),
        sa.Column('label', sa.UnicodeText),
        sa.Column('sort_order', sa.UnicodeText),
        sa.Column('extras', sa.UnicodeText),
        sa.Column('state', sa.UnicodeText),
        sa.Column(
            'revision_id',
            sa.UnicodeText,
            sa.ForeignKey('revision.id'),
            primary_key=True
        ),
        sa.Column(
            'continuity_id', sa.UnicodeText,
            sa.ForeignKey('resource_group.id')
        )
    )
    op.alter_column(
        'package_resource', 'package_id', new_column_name='resource_group_id'
    )
    op.alter_column(
        'package_resource_revision',
        'package_id',
        new_column_name='resource_group_id'
    )
    op.rename_table('package_resource', 'resource')
    op.rename_table('package_resource_revision', 'resource_revision')
    op.execute('ALTER INDEX package_resource_pkey RENAME TO resource_pkey')
    op.execute(
        'ALTER INDEX package_resource_revision_pkey '
        'RENAME TO resource_revision_pkey'
    )
    op.drop_constraint(
        'package_resource_revision_continuity_id_fkey', 'resource_revision'
    )
    op.drop_constraint(
        'package_resource_revision_package_id_fkey', 'resource_revision'
    )
    op.drop_constraint(
        'package_resource_revision_revision_id_fkey', 'resource_revision'
    )
    op.drop_constraint('package_resource_revision_id_fkey', 'resource')
    op.drop_constraint('package_resource_package_id_fkey', 'resource')
    op.create_foreign_key(
        'resource_resource_group_id_fkey', 'resource', 'resource_group',
        ['resource_group_id'], ['id']
    )
    op.create_foreign_key(
        'resource_revision_id_fkey', 'resource', 'revision', ['revision_id'],
        ['id']
    )
    op.create_foreign_key(
        'resource_revision_continuity_id_fkey', 'resource_revision',
        'resource', ['continuity_id'], ['id']
    )
    op.create_foreign_key(
        'resource_revision_resource_group_id_fkey', 'resource_revision',
        'resource_group', ['resource_group_id'], ['id']
    )
    op.create_foreign_key(
        'resource_revision_revision_id_fkey', 'resource_revision', 'revision',
        ['revision_id'], ['id']
    )