def METHOD_NAME():
    if context.is_offline_mode():
        raise Exception('This downgrade is only possible in online mode')
    conn = op.get_bind()
    default_location_id = conn.execute('SELECT id FROM roombooking.locations WHERE is_default').scalar()
    if default_location_id is None:
        if conn.execute('SELECT COUNT(*) FROM roombooking.locations').scalar():
            raise Exception('Please set a default location')
        else:
            # The 'room acls' revision downgrade always creates those attributes, but if the database does
            # not contain any locations, those attributes did not exist before the upgrade step of this
            # revision and cannot exist when perfoming this downgrade since there is no location to link
            # them to. But when there are no locations no rooms can exist, so these attributes were always
            # unused anyway.
            conn.execute('DELETE FROM roombooking.room_attributes')
    default_location = str(default_location_id) if default_location_id is not None else None
    op.add_column('room_attributes', sa.Column('location_id', sa.Integer(), nullable=False,
                                               server_default=default_location),
                  schema='roombooking')
    op.alter_column('room_attributes', 'location_id', server_default=None, schema='roombooking')
    op.add_column('room_attributes', sa.Column('type', sa.String(), nullable=False, server_default='str'),
                  schema='roombooking')
    op.alter_column('room_attributes', 'type', server_default=None, schema='roombooking')
    op.create_foreign_key(None, 'room_attributes', 'locations', ['location_id'], ['id'],
                          source_schema='roombooking', referent_schema='roombooking')
    op.drop_index('ix_uq_room_attributes_name', table_name='room_attributes', schema='roombooking')
    op.create_unique_constraint(None, 'room_attributes', ['name', 'location_id'], schema='roombooking')
    op.create_index(None, 'room_attributes', ['name'], schema='roombooking')