--revision
UPDATE revision.attributes SET
	contents = hstore('transport_bus_route:ft_type_id', '2201') || contents
	WHERE contents ? 'cat:transport_bus_route';
UPDATE revision.attributes SET
	contents = hstore('cat:transport_bus_route', '1') || hstore('transport_bus_route:ft_type_id', '2202') || (contents-'cat:transport_trolleybus_route'::text)
	WHERE contents ? 'cat:transport_trolleybus_route';
UPDATE revision.attributes SET
	contents = hstore('cat:transport_bus_route', '1') || hstore('transport_bus_route:ft_type_id', '2204') || (contents-'cat:transport_minibus_route'::text)
	WHERE contents ? 'cat:transport_minibus_route';
UPDATE revision.attributes SET
    contents = hstore('cat:transport_bus_thread', '1') || (contents - 'cat:transport_minibus_thread'::text)
    WHERE contents ? 'cat:transport_minibus_thread';
UPDATE revision.attributes SET
    contents = hstore('cat:transport_bus_thread', '1') || (contents - 'cat:transport_trolleybus_thread'::text)
    WHERE contents ? 'cat:transport_trolleybus_thread';

UPDATE revision.attributes SET
    contents = hstore('rel:master', 'transport_bus_route') || (contents - 'rel:master'::text)
    WHERE contents @> hstore('rel:master', 'transport_trolleybus_route') OR contents @> hstore('rel:master', 'transport_minibus_route');
UPDATE revision.attributes SET
    contents = hstore('rel:slave', 'transport_bus_route') || (contents - 'rel:slave'::text)
    WHERE contents @> hstore('rel:slave', 'transport_trolleybus_route') OR contents @> hstore('rel:slave', 'transport_minibus_route');

UPDATE revision.attributes SET
    contents = hstore('rel:master', 'transport_bus_thread') || (contents - 'rel:master'::text)
    WHERE contents @> hstore('rel:master', 'transport_trolleybus_thread') OR contents @> hstore('rel:master', 'transport_minibus_thread');
UPDATE revision.attributes SET
    contents = hstore('rel:slave', 'transport_bus_thread') || (contents - 'rel:slave'::text)
    WHERE contents @> hstore('rel:slave', 'transport_trolleybus_thread') OR contents @> hstore('rel:slave', 'transport_minibus_thread');

UPDATE revision.attributes SET
     contents = hstore('rel:role', 'assigned_bus') || (contents - 'rel:role'::text)
     WHERE contents @> hstore('rel:role', 'assigned_minibus');
UPDATE revision.attributes SET
     contents = hstore('rel:role', 'assigned_bus') || (contents - 'rel:role'::text)
     WHERE contents @> hstore('rel:role', 'assigned_trolleybus');

UPDATE revision.attributes SET
     contents = hstore('rel:role', 'bus_part') || (contents - 'rel:role'::text)
     WHERE contents @> hstore('rel:role', 'minibus_part') OR contents @> hstore('rel:role', 'trolleybus_part');

UPDATE revision.attributes SET
    contents = hstore('transport_bus_route:disp_class', contents->'transport_minibus_route:disp_class') ||
        (contents - 'transport_minibus_route:disp_class'::text)
    WHERE contents ? 'transport_minibus_route:disp_class';

UPDATE revision.attributes SET
    contents = hstore('transport_bus_route:disp_class', contents->'transport_trolleybus_route:disp_class') ||
        (contents - 'transport_trolleybus_route:disp_class'::text)
    WHERE contents ? 'transport_trolleybus_route:disp_class';

--vrevisions_
SELECT vrevisions.for_vrevisions('
    UPDATE objects_c SET
        domain_attrs = hstore(\'transport_bus_route:ft_type_id\', \'2201\') || domain_attrs
        WHERE domain_attrs ? \'cat:transport_bus_route\';
    UPDATE objects_c SET
        domain_attrs = hstore(\'cat:transport_bus_route\', \'1\') || hstore(\'transport_bus_route:ft_type_id\', \'2202\') || (domain_attrs-\'cat:transport_trolleybus_route\'::text)
        WHERE domain_attrs ? \'cat:transport_trolleybus_route\';
    UPDATE objects_c SET
        domain_attrs = hstore(\'cat:transport_bus_route\', \'1\') || hstore(\'transport_bus_route:ft_type_id\', \'2204\') || (domain_attrs-\'cat:transport_minibus_route\'::text)
        WHERE domain_attrs ? \'cat:transport_minibus_route\';
    UPDATE objects_c SET
        domain_attrs = hstore(\'cat:transport_bus_thread\', \'1\') || (domain_attrs - \'cat:transport_minibus_thread\'::text)
        WHERE domain_attrs ? \'cat:transport_minibus_thread\';
    UPDATE objects_c SET
        domain_attrs = hstore(\'cat:transport_bus_thread\', \'1\') || (domain_attrs - \'cat:transport_trolleybus_thread\'::text)
        WHERE domain_attrs ? \'cat:transport_trolleybus_thread\';

    UPDATE objects_c SET
        domain_attrs = hstore(\'transport_bus_route:disp_class\', domain_attrs->\'transport_minibus_route:disp_class\') ||
            (domain_attrs - \'transport_minibus_route:disp_class\'::text)
        WHERE domain_attrs ? \'transport_minibus_route:disp_class\';

    UPDATE objects_c SET
        domain_attrs = hstore(\'transport_bus_route:disp_class\', domain_attrs->\'transport_trolleybus_route:disp_class\') ||
            (domain_attrs - \'transport_trolleybus_route:disp_class\'::text)
        WHERE domain_attrs ? \'transport_trolleybus_route:disp_class\';


    UPDATE objects_r SET
        domain_attrs = hstore(\'rel:master\', \'transport_bus_route\') || (domain_attrs - \'rel:master\'::text)
        WHERE domain_attrs @> hstore(\'rel:master\', \'transport_trolleybus_route\') OR domain_attrs @> hstore(\'rel:master\', \'transport_minibus_route\');
    UPDATE objects_r SET
        domain_attrs = hstore(\'rel:slave\', \'transport_bus_route\') || (domain_attrs - \'rel:slave\'::text)
        WHERE domain_attrs @> hstore(\'rel:slave\', \'transport_trolleybus_route\') OR domain_attrs @> hstore(\'rel:slave\', \'transport_minibus_route\');

    UPDATE objects_r SET
        domain_attrs = hstore(\'rel:master\', \'transport_bus_thread\') || (domain_attrs - \'rel:master\'::text)
        WHERE domain_attrs @> hstore(\'rel:master\', \'transport_trolleybus_thread\') OR domain_attrs @> hstore(\'rel:master\', \'transport_minibus_thread\');
    UPDATE objects_r SET
        domain_attrs = hstore(\'rel:slave\', \'transport_bus_thread\') || (domain_attrs - \'rel:slave\'::text)
        WHERE domain_attrs @> hstore(\'rel:slave\', \'transport_trolleybus_thread\') OR domain_attrs @> hstore(\'rel:slave\', \'transport_minibus_thread\');

    UPDATE objects_r SET
         domain_attrs = hstore(\'rel:role\', \'assigned_bus\') || (domain_attrs - \'rel:role\'::text)
         WHERE domain_attrs @> hstore(\'rel:role\', \'assigned_minibus\');
    UPDATE objects_r SET
         domain_attrs = hstore(\'rel:role\', \'assigned_bus\') || (domain_attrs - \'rel:role\'::text)
         WHERE domain_attrs @> hstore(\'rel:role\', \'assigned_trolleybus\');

    UPDATE objects_r SET
         domain_attrs = hstore(\'rel:role\', \'bus_part\') || (domain_attrs - \'rel:role\'::text)
         WHERE domain_attrs @> hstore(\'rel:role\', \'minibus_part\') OR domain_attrs @> hstore(\'rel:role\', \'trolleybus_part\');

    UPDATE suggest_data SET
        categories = hstore(\'cat:transport_bus_route\', \'1\') || (categories - ARRAY[\'cat:transport_minibus_route\'::text, \'cat:transport_trolleybus_route\'::text])
        WHERE categories ?| ARRAY[\'cat:transport_minibus_route\', \'cat:transport_trolleybus_route\'];
');
--revision_meta
UPDATE revision_meta.geometry SET
    categories = hstore('cat:transport_bus_route', '1') || (categories - ARRAY['cat:transport_minibus_route'::text, 'cat:transport_trolleybus_route'::text])
    WHERE categories ?| ARRAY['cat:transport_minibus_route', 'cat:transport_trolleybus_route'];
UPDATE revision_meta.geometry SET
    categories = hstore('cat:transport_bus_thread', '1') || (categories - ARRAY['cat:transport_minibus_thread'::text, 'cat:transport_trolleybus_thread'::text])
    WHERE categories ?| ARRAY['cat:transport_minibus_thread', 'cat:transport_trolleybus_thread'];
--social
UPDATE social.task
    SET primary_object_category_id = 'transport_bus_route'
    WHERE primary_object_category_id IN ('transport_minibus_route', 'transport_trolleybus_route');
UPDATE social.task
    SET primary_object_category_id = 'transport_bus_thread'
    WHERE primary_object_category_id IN ('transport_minibus_thread', 'transport_trolleybus_thread');

UPDATE social.commit_event
    SET primary_object_category_id = 'transport_bus_route'
    WHERE primary_object_category_id IN ('transport_minibus_route', 'transport_trolleybus_route');
UPDATE social.commit_event
    SET primary_object_category_id = 'transport_bus_thread'
    WHERE primary_object_category_id IN ('transport_minibus_thread', 'transport_trolleybus_thread');

--diffallert
UPDATE diffalert.message_attributes
    SET category_id = 'transport_bus_route'
    WHERE category_id IN ('transport_minibus_route', 'transport_trolleybus_route');
UPDATE diffalert.message_attributes
    SET category_id = 'transport_bus_thread'
    WHERE category_id IN ('transport_minibus_thread', 'transport_trolleybus_thread');
