 ALTER TABLE admin.oq_user ADD CONSTRAINT admin_oq_user_organization_fk
 FOREIGN KEY (organization_id) REFERENCES admin.organization(id) ON DELETE RESTRICT;
 
-ALTER TABLE pshai.rupture ADD CONSTRAINT pshai_rupture_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.source ADD CONSTRAINT pshai_source_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.simple_fault ADD CONSTRAINT pshai_simple_fault_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.complex_fault ADD CONSTRAINT pshai_complex_fault_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.fault_edge ADD CONSTRAINT pshai_fault_edge_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.mfd_evd ADD CONSTRAINT pshai_mfd_evd_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.mfd_tgr ADD CONSTRAINT pshai_mfd_tgr_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.r_depth_distr ADD CONSTRAINT pshai_r_depth_distr_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.focal_mechanism ADD CONSTRAINT pshai_focal_mechanism_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.r_rate_mdl ADD CONSTRAINT pshai_r_rate_mdl_owner_fk
-FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.complex_fault ADD CONSTRAINT pshai_complex_fault_fault_edge_fk
-FOREIGN KEY (fault_edge_id) REFERENCES pshai.fault_edge(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.r_rate_mdl ADD CONSTRAINT pshai_r_rate_mdl_mfd_tgr_fk
-FOREIGN KEY (mfd_tgr_id) REFERENCES pshai.mfd_tgr(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.r_rate_mdl ADD CONSTRAINT pshai_r_rate_mdl_mfd_evd_fk
-FOREIGN KEY (mfd_evd_id) REFERENCES pshai.mfd_evd(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.r_rate_mdl ADD CONSTRAINT pshai_r_rate_mdl_focal_mechanism_fk
-FOREIGN KEY (focal_mechanism_id) REFERENCES pshai.focal_mechanism(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.r_rate_mdl ADD CONSTRAINT pshai_r_rate_mdl_source_fk
-FOREIGN KEY (source_id) REFERENCES pshai.source(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.simple_fault ADD CONSTRAINT pshai_simple_fault_mfd_tgr_fk
-FOREIGN KEY (mfd_tgr_id) REFERENCES pshai.mfd_tgr(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.simple_fault ADD CONSTRAINT pshai_simple_fault_mfd_evd_fk
-FOREIGN KEY (mfd_evd_id) REFERENCES pshai.mfd_evd(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.complex_fault ADD CONSTRAINT pshai_complex_fault_mfd_tgr_fk
-FOREIGN KEY (mfd_tgr_id) REFERENCES pshai.mfd_tgr(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.complex_fault ADD CONSTRAINT pshai_complex_fault_mfd_evd_fk
-FOREIGN KEY (mfd_evd_id) REFERENCES pshai.mfd_evd(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.source ADD CONSTRAINT pshai_source_simple_fault_fk
-FOREIGN KEY (simple_fault_id) REFERENCES pshai.simple_fault(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.source ADD CONSTRAINT pshai_source_complex_fault_fk
-FOREIGN KEY (complex_fault_id) REFERENCES pshai.complex_fault(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.source ADD CONSTRAINT pshai_source_r_depth_distr_fk
-FOREIGN KEY (r_depth_distr_id) REFERENCES pshai.r_depth_distr(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.source ADD CONSTRAINT pshai_source_input_fk
+ALTER TABLE hzrdi.rupture ADD CONSTRAINT hzrdi_rupture_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.source ADD CONSTRAINT hzrdi_source_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.simple_fault ADD CONSTRAINT hzrdi_simple_fault_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.complex_fault ADD CONSTRAINT hzrdi_complex_fault_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.fault_edge ADD CONSTRAINT hzrdi_fault_edge_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.mfd_evd ADD CONSTRAINT hzrdi_mfd_evd_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.mfd_tgr ADD CONSTRAINT hzrdi_mfd_tgr_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.r_depth_distr ADD CONSTRAINT hzrdi_r_depth_distr_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.focal_mechanism ADD CONSTRAINT hzrdi_focal_mechanism_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.r_rate_mdl ADD CONSTRAINT hzrdi_r_rate_mdl_owner_fk
+FOREIGN KEY (owner_id) REFERENCES admin.oq_user(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.complex_fault ADD CONSTRAINT hzrdi_complex_fault_fault_edge_fk
+FOREIGN KEY (fault_edge_id) REFERENCES hzrdi.fault_edge(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.r_rate_mdl ADD CONSTRAINT hzrdi_r_rate_mdl_mfd_tgr_fk
+FOREIGN KEY (mfd_tgr_id) REFERENCES hzrdi.mfd_tgr(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.r_rate_mdl ADD CONSTRAINT hzrdi_r_rate_mdl_mfd_evd_fk
+FOREIGN KEY (mfd_evd_id) REFERENCES hzrdi.mfd_evd(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.r_rate_mdl ADD CONSTRAINT hzrdi_r_rate_mdl_focal_mechanism_fk
+FOREIGN KEY (focal_mechanism_id) REFERENCES hzrdi.focal_mechanism(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.r_rate_mdl ADD CONSTRAINT hzrdi_r_rate_mdl_source_fk
+FOREIGN KEY (source_id) REFERENCES hzrdi.source(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.simple_fault ADD CONSTRAINT hzrdi_simple_fault_mfd_tgr_fk
+FOREIGN KEY (mfd_tgr_id) REFERENCES hzrdi.mfd_tgr(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.simple_fault ADD CONSTRAINT hzrdi_simple_fault_mfd_evd_fk
+FOREIGN KEY (mfd_evd_id) REFERENCES hzrdi.mfd_evd(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.complex_fault ADD CONSTRAINT hzrdi_complex_fault_mfd_tgr_fk
+FOREIGN KEY (mfd_tgr_id) REFERENCES hzrdi.mfd_tgr(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.complex_fault ADD CONSTRAINT hzrdi_complex_fault_mfd_evd_fk
+FOREIGN KEY (mfd_evd_id) REFERENCES hzrdi.mfd_evd(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.source ADD CONSTRAINT hzrdi_source_simple_fault_fk
+FOREIGN KEY (simple_fault_id) REFERENCES hzrdi.simple_fault(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.source ADD CONSTRAINT hzrdi_source_complex_fault_fk
+FOREIGN KEY (complex_fault_id) REFERENCES hzrdi.complex_fault(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.source ADD CONSTRAINT hzrdi_source_r_depth_distr_fk
+FOREIGN KEY (r_depth_distr_id) REFERENCES hzrdi.r_depth_distr(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.source ADD CONSTRAINT hzrdi_source_input_fk
 FOREIGN KEY (input_id) REFERENCES uiapi.input(id) ON DELETE RESTRICT;
 
-ALTER TABLE pshai.rupture ADD CONSTRAINT pshai_rupture_simple_fault_fk
-FOREIGN KEY (simple_fault_id) REFERENCES pshai.simple_fault(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.rupture ADD CONSTRAINT pshai_rupture_complex_fault_fk
-FOREIGN KEY (complex_fault_id) REFERENCES pshai.complex_fault(id) ON DELETE RESTRICT;
-
-ALTER TABLE pshai.rupture ADD CONSTRAINT pshai_rupture_input_fk
+ALTER TABLE hzrdi.rupture ADD CONSTRAINT hzrdi_rupture_simple_fault_fk
+FOREIGN KEY (simple_fault_id) REFERENCES hzrdi.simple_fault(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.rupture ADD CONSTRAINT hzrdi_rupture_complex_fault_fk
+FOREIGN KEY (complex_fault_id) REFERENCES hzrdi.complex_fault(id) ON DELETE RESTRICT;
+
+ALTER TABLE hzrdi.rupture ADD CONSTRAINT hzrdi_rupture_input_fk
 FOREIGN KEY (input_id) REFERENCES uiapi.input(id) ON DELETE RESTRICT;
 
-CREATE TRIGGER pshai_rupture_before_insert_update_trig
-BEFORE INSERT OR UPDATE ON pshai.rupture
+CREATE TRIGGER hzrdi_rupture_before_insert_update_trig
+BEFORE INSERT OR UPDATE ON hzrdi.rupture
 FOR EACH ROW EXECUTE PROCEDURE check_rupture_sources();
 
-CREATE TRIGGER pshai_source_before_insert_update_trig
-BEFORE INSERT OR UPDATE ON pshai.source
+CREATE TRIGGER hzrdi_source_before_insert_update_trig
+BEFORE INSERT OR UPDATE ON hzrdi.source
 FOR EACH ROW EXECUTE PROCEDURE check_source_sources();
 
-CREATE TRIGGER pshai_r_rate_mdl_before_insert_update_trig
-BEFORE INSERT OR UPDATE ON pshai.r_rate_mdl
+CREATE TRIGGER hzrdi_r_rate_mdl_before_insert_update_trig
+BEFORE INSERT OR UPDATE ON hzrdi.r_rate_mdl
 FOR EACH ROW EXECUTE PROCEDURE check_only_one_mfd_set();
 
-CREATE TRIGGER pshai_simple_fault_before_insert_update_trig
-BEFORE INSERT OR UPDATE ON pshai.simple_fault
+CREATE TRIGGER hzrdi_simple_fault_before_insert_update_trig
+BEFORE INSERT OR UPDATE ON hzrdi.simple_fault
 FOR EACH ROW EXECUTE PROCEDURE check_only_one_mfd_set();
 
-CREATE TRIGGER pshai_complex_fault_before_insert_update_trig
-BEFORE INSERT OR UPDATE ON pshai.complex_fault
+CREATE TRIGGER hzrdi_complex_fault_before_insert_update_trig
+BEFORE INSERT OR UPDATE ON hzrdi.complex_fault
 FOR EACH ROW EXECUTE PROCEDURE check_only_one_mfd_set();
 
 ALTER TABLE eqcat.catalog ADD CONSTRAINT eqcat_catalog_owner_fk

    rup.si_type, rup.tectonic_region, rup.rake, rup.magnitude,
    rup.magnitude_type, sfault.edge, sfault.outline
FROM
    pshai.rupture rup, pshai.simple_fault sfault
WHERE
    rup.si_type = 'simple'
    AND rup.simple_fault_id = sfault.id;


-- Complex fault geometry
CREATE TABLE pshai.complex_fault (
    id SERIAL PRIMARY KEY,
    owner_id INTEGER NOT NULL,
    -- gml:id

    description VARCHAR,
    last_update timestamp without time zone
        DEFAULT timezone('UTC'::text, now()) NOT NULL
) TABLESPACE hzrdi_ts;
SELECT AddGeometryColumn('hzrdi', 'fault_edge', 'top', 4326, 'LINESTRING', 3);
SELECT AddGeometryColumn('hzrdi', 'fault_edge', 'bottom', 4326, 'LINESTRING', 3);
ALTER TABLE hzrdi.fault_edge ALTER COLUMN top SET NOT NULL;
ALTER TABLE hzrdi.fault_edge ALTER COLUMN bottom SET NOT NULL;


-- complex source view, needed for Opengeo server integration
CREATE VIEW hzrdi.complex_source (
    id, owner_id, input_id, gid, name, description, si_type, tectonic_region,
    rake, top_edge, bottom_edge, fault_outline) AS
SELECT
