def test_process_schema_rule_mismatched_table(self):

        test_case_buf = """
SET search_path = bial, pg_catalog

--
-- Name: ab_reporting_beta_match_ins; Type: RULE; Schema: bial; Owner: table_owner
--

CREATE RULE ab_reporting_beta_match_ins AS ON INSERT TO weblog_mart_tbls.ab_reporting_beta_match DO INSTEAD INSERT INTO ab_reporting_beta_match VALUES new.search_session_id;
"""
        expected_out = ""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['bial'])
        dump_tables = set([('bial', 'ab_reporting_beta_match')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
Example #2
0
    def test_process_schema_rule_mismatched_table(self):

        test_case_buf = """
SET search_path = bial, pg_catalog

--
-- Name: ab_reporting_beta_match_ins; Type: RULE; Schema: bial; Owner: table_owner
--

CREATE RULE ab_reporting_beta_match_ins AS ON INSERT TO weblog_mart_tbls.ab_reporting_beta_match DO INSTEAD INSERT INTO ab_reporting_beta_match VALUES new.search_session_id;
"""
        expected_out = ""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['bial'])
        dump_tables = set([('bial', 'ab_reporting_beta_match')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
Example #3
0
    def test_process_schema_constraint(self):

        test_case_buf = """
SET search_path = affil, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: affil_linkshare_sku_pkey; Type: CONSTRAINT; Schema: affil; Owner: table_owner; Tablespace: 
--

ALTER TABLE ONLY affil_linkshare_sku
    ADD CONSTRAINT affil_linkshare_sku_pkey PRIMARY KEY (affil_linkshare_sku_id);


--
-- Name: affil_page_landing_hist_pkey; Type: CONSTRAINT; Schema: affil; Owner: table_owner; Tablespace: 
--

ALTER TABLE affil_page_landing_hist
    ADD CONSTRAINT affil_page_landing_hist_pkey PRIMARY KEY (affil_page_landing_hist_id);
"""
        expected_out = """SET search_path = affil, pg_catalog;
SET default_tablespace = '';

SET default_with_oids = false;

--
ALTER TABLE ONLY affil_linkshare_sku
    ADD CONSTRAINT affil_linkshare_sku_pkey PRIMARY KEY (affil_linkshare_sku_id);


--
ALTER TABLE affil_page_landing_hist
    ADD CONSTRAINT affil_page_landing_hist_pkey PRIMARY KEY (affil_page_landing_hist_id);
"""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['affil'])
        dump_tables = set([('affil', 'affil_linkshare_sku'), ('affil','affil_page_landing_hist')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
Example #4
0
    def test_process_schema_index(self):

        test_case_buf = """
SET search_path = weblog_mart_tbls, pg_catalog;

--
-- Name: ak1_property_select_error_loadtime; Type: INDEX; Schema: weblog_mart_tbls; Owner: table_owner; Tablespace: 
--

CREATE INDEX ak1_property_select_error_loadtime ON hrs_property_select_errors USING btree (pse_load_timestamp);


--
-- Name: dim_betagroup_idx; Type: INDEX; Schema: weblog_mart_tbls; Owner: table_owner; Tablespace: 
--

CREATE UNIQUE INDEX dim_betagroup_idx ON weblog_mart_tbls.dim_betagroup USING btree (betagroupid);


--
-- Name: dim_cruise_idx; Type: INDEX; Schema: weblog_mart; Owner: table_owner; Tablespace: 
--

CREATE UNIQUE INDEX dim_cruise_idx ON dim_cruise USING btree (cruiseid);
"""
        expected_out = """SET search_path = weblog_mart_tbls, pg_catalog;
CREATE INDEX ak1_property_select_error_loadtime ON hrs_property_select_errors USING btree (pse_load_timestamp);


--
CREATE UNIQUE INDEX dim_betagroup_idx ON weblog_mart_tbls.dim_betagroup USING btree (betagroupid);


--
"""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['weblog_mart_tbls'])
        dump_tables = set([('weblog_mart_tbls', 'hrs_property_select_errors'), ('weblog_mart_tbls','dim_betagroup')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
    def test_process_schema_trigger(self):

        test_case_buf = """
SET search_path = adt, pg_catalog;

--
-- Name: adt_contact_record_encrypt; Type: TRIGGER; Schema: adt; Owner: table_owner
--

CREATE TRIGGER adt_contact_record_encrypt
    BEFORE INSERT OR UPDATE ON adt_contact_record
    FOR EACH ROW
    EXECUTE PROCEDURE adt_contact_record_encrypt();


SET search_path = air, pg_catalog;

--
-- Name: air_itinerary_encrypt; Type: TRIGGER; Schema: air; Owner: table_owner
--

CREATE TRIGGER air_itinerary_encrypt
    BEFORE INSERT OR UPDATE ON air_itinerary
    FOR EACH ROW
    EXECUTE PROCEDURE air_itinerary_encrypt();
"""
        expected_out = """SET search_path = air, pg_catalog;
CREATE TRIGGER air_itinerary_encrypt
    BEFORE INSERT OR UPDATE ON air_itinerary
    FOR EACH ROW
    EXECUTE PROCEDURE air_itinerary_encrypt();
"""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['air'])
        dump_tables = set([('air', 'air_itinerary')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
Example #6
0
    def test_process_schema_trigger(self):

        test_case_buf = """
SET search_path = adt, pg_catalog;

--
-- Name: adt_contact_record_encrypt; Type: TRIGGER; Schema: adt; Owner: table_owner
--

CREATE TRIGGER adt_contact_record_encrypt
    BEFORE INSERT OR UPDATE ON adt_contact_record
    FOR EACH ROW
    EXECUTE PROCEDURE adt_contact_record_encrypt();


SET search_path = air, pg_catalog;

--
-- Name: air_itinerary_encrypt; Type: TRIGGER; Schema: air; Owner: table_owner
--

CREATE TRIGGER air_itinerary_encrypt
    BEFORE INSERT OR UPDATE ON air_itinerary
    FOR EACH ROW
    EXECUTE PROCEDURE air_itinerary_encrypt();
"""
        expected_out = """SET search_path = air, pg_catalog;
CREATE TRIGGER air_itinerary_encrypt
    BEFORE INSERT OR UPDATE ON air_itinerary
    FOR EACH ROW
    EXECUTE PROCEDURE air_itinerary_encrypt();
"""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['air'])
        dump_tables = set([('air', 'air_itinerary')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
Example #7
0
    def test_process_schema_rule(self):

        test_case_buf = """
SET search_path = bial, pg_catalog;

--
-- Name: ab_reporting_beta_match_ins; Type: RULE; Schema: bial; Owner: table_owner
--

CREATE RULE ab_reporting_beta_match_ins AS ON INSERT TO ab_reporting_beta_match DO INSTEAD INSERT INTO weblog_mart_tbls.ab_reporting_beta_match VALUES new.search_session_id;


--
-- Name: RULE ab_reporting_beta_match_ins ON ab_reporting_beta_match; Type: COMMENT; Schema: bial; Owner: table_owner
--

COMMENT ON RULE ab_reporting_beta_match_ins ON ab_reporting_beta_match IS 'version:20110607_1553 generated on 2012-11-29 11:55:23.938893-06';


--
-- Name: ab_reporting_beta_match_upd; Type: RULE; Schema: bial; Owner: table_owner
--

CREATE RULE ab_reporting_beta_match_upd AS ON UPDATE TO ab_reporting_beta_match_1 DO INSTEAD UPDATE weblog_mart_tbls.ab_reporting_beta_match = SET checkin_date = new.checkin_date;
"""
        expected_out = """SET search_path = bial, pg_catalog;
CREATE RULE ab_reporting_beta_match_ins AS ON INSERT TO ab_reporting_beta_match DO INSTEAD INSERT INTO weblog_mart_tbls.ab_reporting_beta_match VALUES new.search_session_id;


--
"""

        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)

        dump_schemas = set(['bial'])
        dump_tables = set([('bial', 'ab_reporting_beta_match')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin:
                process_schema(dump_schemas, dump_tables, fdin, fdout)

        with open(out_name, 'r') as fd:
            results = fd.read()

        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
    def test_cyrillic_char_schema_filter_index(self):

        test_case_buf = """--
-- Greenplum Database database dump
--

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

SET search_path = user_schema_a, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;


SET search_path = "Ж_schema", pg_catalog;

--
-- Name: a_pkey; Type: CONSTRAINT; Schema: Ж_schema; Owner: user_role_b; Tablespace: 
--

ALTER TABLE ONLY "Ж"
    ADD CONSTRAINT a_pkey PRIMARY KEY (a);


SET search_path = "Ж_schema", pg_catalog;

--
-- Name: user_table_idx; Type: INDEX; Schema: Ж_schema; Owner: user_role_b; Tablespace: 
--

CREATE INDEX user_table_idx ON "Ж" USING btree (b);


--
-- Greenplum Database database dump complete
--
"""

        expected_out = """SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

SET default_tablespace = '';

SET default_with_oids = false;


SET search_path = "Ж_schema", pg_catalog;
ALTER TABLE ONLY "Ж"
    ADD CONSTRAINT a_pkey PRIMARY KEY (a);


SET search_path = "Ж_schema", pg_catalog;
CREATE INDEX user_table_idx ON "Ж" USING btree (b);


"""
        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)
        
        dump_schemas = set(['Ж_schema'])
        dump_tables = set([('Ж_schema', 'Ж')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin: 
                process_schema(dump_schemas, dump_tables, fdin, fdout)
        
        with open(out_name, 'r') as fd:
            results = fd.read()
        
        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)
Example #9
0
    def test_cyrillic_char_schema_filter_index(self):

        test_case_buf = """--
-- Greenplum Database database dump
--

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

SET search_path = user_schema_a, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;


SET search_path = "Ж_schema", pg_catalog;

--
-- Name: a_pkey; Type: CONSTRAINT; Schema: Ж_schema; Owner: user_role_b; Tablespace: 
--

ALTER TABLE ONLY "Ж"
    ADD CONSTRAINT a_pkey PRIMARY KEY (a);


SET search_path = "Ж_schema", pg_catalog;

--
-- Name: user_table_idx; Type: INDEX; Schema: Ж_schema; Owner: user_role_b; Tablespace: 
--

CREATE INDEX user_table_idx ON "Ж" USING btree (b);


--
-- Greenplum Database database dump complete
--
"""

        expected_out = """SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

SET default_tablespace = '';

SET default_with_oids = false;


SET search_path = "Ж_schema", pg_catalog;
ALTER TABLE ONLY "Ж"
    ADD CONSTRAINT a_pkey PRIMARY KEY (a);


SET search_path = "Ж_schema", pg_catalog;
CREATE INDEX user_table_idx ON "Ж" USING btree (b);


--
-- Greenplum Database database dump complete
--
"""
        in_name = os.path.join(os.getcwd(), 'infile')
        out_name = os.path.join(os.getcwd(), 'outfile')
        with open(in_name, 'w') as fd:
            fd.write(test_case_buf)
        
        dump_schemas = set(['Ж_schema'])
        dump_tables = set([('Ж_schema', 'Ж')])
        with open(out_name, 'w') as fdout:
            with open(in_name, 'r') as fdin: 
                process_schema(dump_schemas, dump_tables, fdin, fdout)
        
        with open(out_name, 'r') as fd:
            results = fd.read()
        
        self.assertEquals(results, expected_out)
        os.remove(in_name)
        os.remove(out_name)