X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=migrations%2F106-down-newinterface.sql;fp=migrations%2F106-down-newinterface.sql;h=2296cde8f63f72b6a4f45cb869ec28cf8c734a26;hb=cb77137d884be296fe1e0b15eabe69d18ba443ae;hp=0000000000000000000000000000000000000000;hpb=f2d58ad2ee7ed321cf24663c049c7177fe9facc6;p=plcapi.git diff --git a/migrations/106-down-newinterface.sql b/migrations/106-down-newinterface.sql new file mode 100644 index 0000000..2296cde --- /dev/null +++ b/migrations/106-down-newinterface.sql @@ -0,0 +1,119 @@ +DELETE FROM network_types WHERE type='ipv6'; + +ALTER TABLE interfaces ADD COLUMN gateway text; +ALTER TABLE interfaces ADD COLUMN dns1 text; +ALTER TABLE interfaces ADD COLUMN dns2 text; +ALTER TABLE interfaces ADD COLUMN type text; +ALTER TABLE interfaces ADD COLUMN ip text; +ALTER TABLE interfaces ADD COLUMN network text; +ALTER TABLE interfaces ADD COLUMN broadcast text; +ALTER TABLE interfaces ADD COLUMN netmask text; + +DROP VIEW view_interfaces; +CREATE OR REPLACE VIEW view_interfaces AS +SELECT +interfaces.interface_id, +interfaces.node_id, +interfaces.is_primary, +interfaces.type, +interfaces.method, +interfaces.ip, +interfaces.mac, +interfaces.gateway, +interfaces.network, +interfaces.broadcast, +interfaces.netmask, +interfaces.dns1, +interfaces.dns2, +interfaces.bwlimit, +interfaces.hostname, +CAST(date_part('epoch', interfaces.last_updated) AS bigint) AS last_updated, +COALESCE((SELECT interface_tag_ids FROM interface_tags WHERE interface_tags.interface_id = interfaces.interface_id), '{}') AS interface_tag_ids +FROM interfaces; + +DROP VIEW view_interface_tags; +CREATE OR REPLACE VIEW view_interface_tags AS +SELECT +interface_tag.interface_tag_id, +interface_tag.interface_id, +interfaces.ip, +tag_types.tag_type_id, +tag_types.tagname, +tag_types.description, +tag_types.category, +interface_tag.value +FROM interface_tag +INNER JOIN tag_types USING (tag_type_id) +INNER JOIN interfaces USING (interface_id); + + +DROP VIEW view_nodes; +CREATE OR REPLACE VIEW view_nodes AS +SELECT +nodes.node_id, +nodes.node_type, +nodes.hostname, +nodes.site_id, +nodes.boot_state, +nodes.run_level, +nodes.deleted, +nodes.model, +nodes.boot_nonce, +nodes.version, +nodes.verified, +nodes.ssh_rsa_key, +nodes.key, +CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created, +CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated, +CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact, +CAST(date_part('epoch', nodes.last_boot) AS bigint) AS last_boot, +CAST(date_part('epoch', nodes.last_download) AS bigint) AS last_download, +CAST(date_part('epoch', nodes.last_pcu_reboot) AS bigint) AS last_pcu_reboot, +CAST(date_part('epoch', nodes.last_pcu_confirmation) AS bigint) AS last_pcu_confirmation, +nodes.last_time_spent_online, +nodes.last_time_spent_offline, +peer_node.peer_id, +peer_node.peer_node_id, +COALESCE((SELECT interface_ids FROM node_interfaces + WHERE node_interfaces.node_id = nodes.node_id), '{}') +AS interface_ids, +COALESCE((SELECT nodegroup_ids FROM node_nodegroups + WHERE node_nodegroups.node_id = nodes.node_id), '{}') +AS nodegroup_ids, +COALESCE((SELECT slice_ids FROM node_slices + WHERE node_slices.node_id = nodes.node_id), '{}') +AS slice_ids, +COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist + WHERE node_slices_whitelist.node_id = nodes.node_id), '{}') +AS slice_ids_whitelist, +COALESCE((SELECT pcu_ids FROM node_pcus + WHERE node_pcus.node_id = nodes.node_id), '{}') +AS pcu_ids, +COALESCE((SELECT ports FROM node_pcus + WHERE node_pcus.node_id = nodes.node_id), '{}') +AS ports, +COALESCE((SELECT conf_file_ids FROM node_conf_files + WHERE node_conf_files.node_id = nodes.node_id), '{}') +AS conf_file_ids, +COALESCE((SELECT node_tag_ids FROM node_tags + WHERE node_tags.node_id = nodes.node_id), '{}') +AS node_tag_ids, +node_session.session_id AS session +FROM nodes +LEFT JOIN peer_node USING (node_id) +LEFT JOIN node_session USING (node_id); + +ALTER TABLE interfaces DROP COLUMN if_name; +ALTER TABLE nodes DROP COLUMN dns; +ALTER TABLE nodes DROP COLUMN ntp; + +DROP VIEW node_routes; +DROP VIEW view_routes; +DROP TABLE routes; + +DROP VIEW interface_ip_addresses; +DROP VIEW view_ip_addresses; +DROP INDEX ip_addresses_interface_id_idx; +DROP TABLE ip_addresses; + +UPDATE plc_db_version SET subversion = 105;