hs.hsadmin/hsarback/database/database_update.sql
2013-05-13 19:52:13 +02:00

62 lines
2.1 KiB
SQL

-- INSERT INTO domain__domain_option
-- SELECT domain_option_id, domain_id FROM domain
-- JOIN unixuser on ( domain.domain_owner = unixuser.unixuser_id )
-- JOIN packet on ( unixuser.packet_id = packet.packet_id )
-- JOIN basepacket on ( packet.bp_id = basepacket.basepacket_id ), domain_option
-- WHERE basepacket.basepacket_code = 'PAC/DW'
-- AND domain_option.domain_option_name = 'php' ;
-- DELETE FROM domain__domain_option
-- USING domain_option, domain
-- JOIN unixuser on ( domain.domain_owner = unixuser.unixuser_id )
-- JOIN packet on ( unixuser.packet_id = packet.packet_id )
-- JOIN basepacket on ( packet.bp_id = basepacket.basepacket_id )
-- WHERE basepacket.basepacket_code != 'PAC/DW'
-- AND domain__domain_option.domain_option_id = domain_option.domain_option_id
-- AND domain_option.domain_option_name = 'php' ;
--
-- Name: packet_component_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE packet_component_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
CREATE SEQUENCE component_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
ALTER TABLE packet_component ADD COLUMN packet_component_id integer
DEFAULT nextval(('"packet_component_id_seq"'::text)::regclass) NOT NULL;
ALTER TABLE component ADD COLUMN component_id integer
DEFAULT nextval(('"component_id_seq"'::text)::regclass) NOT NULL;
ALTER TABLE ONLY packet_component
DROP CONSTRAINT pk_packet_component;
ALTER TABLE ONLY component
DROP CONSTRAINT pk_component CASCADE;
ALTER TABLE ONLY packet_component
ADD CONSTRAINT pk_packet_component PRIMARY KEY (packet_component_id);
ALTER TABLE ONLY component
ADD CONSTRAINT pk_component PRIMARY KEY (component_id);
ALTER TABLE ONLY packet ADD COLUMN basepacket_id integer;
UPDATE packet SET basepacket_id = ( SELECT basepacket_id FROM packet_component
WHERE packet_component.packet_id = packet.packet_id LIMIT 1 );
ALTER TABLE ONLY packet
ADD CONSTRAINT base_packet_ref FOREIGN KEY (basepacket_id) REFERENCES basepacket(basepacket_id);
ALTER TABLE ONLY packet_component
DROP COLUMN basepacket_id;