fordfrog / apgdiff

Another PostgreSQL Diff Tool
http://www.apgdiff.com
MIT License
355 stars 138 forks source link

Null pointer excetpion release 2.6.0 #255

Open ad-pro opened 5 years ago

ad-pro commented 5 years ago

I tried to generate difference between schemas and got following error:

Exception in thread "main" java.lang.NullPointerException at cz.startnet.utils.pgdiff.PgDiffTriggers.getEnablerOrDisableTriggers(PgDiffTriggers.java:222) at cz.startnet.utils.pgdiff.PgDiffTriggers.disableOrEnableTriggers(PgDiffTriggers.java:256) at cz.startnet.utils.pgdiff.PgDiff.updateSchemas(PgDiff.java:321) at cz.startnet.utils.pgdiff.PgDiff.diffDatabaseSchemas(PgDiff.java:144) at cz.startnet.utils.pgdiff.PgDiff.createDiff(PgDiff.java:46) at cz.startnet.utils.pgdiff.Main.main(Main.java:39)

My java version is: penjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-8u212-b01-1~deb9u1-b01) OpenJDK 64-Bit Server VM (build 25.212-b01, mixed mode)

jalissonmello commented 5 years ago

Can you provide the script or a example to help with the tests?

ad-pro commented 5 years ago

Script could be difficult, I have to send you whole source code of the DB ...

What I have found:

  1. I run it with --ignore-function-whitespace parameter. it generate diff file and crash at:
ALTER TABLE deal_cost_attr
    ADD CONSTRAINT deal_cost_attr_pkey PRIMARY KEY (id);

ALTER TABLE deal_cost_statuses
    ADD CONSTRAINT deal_cost_statuses_pkey PRIMARY KEY (id);

ALTER TABLE deal_costs
    ADD CONSTRAINT deal_costs_pkey PRIMARY KEY (id);

ALTER TABLE deal_cost_attr
    ADD CONSTRAINT deal_cost_attr_sname_key UNIQUE (sname

last line number was 1930.

in the original file this was after:


--
-- Name: deal_cost_attr deal_cost_attr_pkey; Type: CONSTRAINT; Schema: cntr; Owner: mig_admin
--

ALTER TABLE ONLY cntr.deal_cost_attr
    ADD CONSTRAINT deal_cost_attr_pkey PRIMARY KEY (id);

--
-- Name: deal_cost_attr deal_cost_attr_sname_key; Type: CONSTRAINT; Schema: cntr; Owner: mig_admin
--

ALTER TABLE ONLY cntr.deal_cost_attr
    ADD CONSTRAINT deal_cost_attr_sname_key UNIQUE (sname);

last line: 36172.

when I run it without --ignore-function-whitespace parameter it generate diff file till:

CREATE OR REPLACE FUNCTION update_contract(p_id core.t_id, p_sname core.t_s this is line 2556

and in original file this is

ALTER FUNCTION cntr.tmp_migrate_contract_container() OWNER TO mig_admin;

--
-- Name: update_contract(core.t_id, core.t_s_name, core.t_l_name, core.t_s_name, core.t_s_name, core.t_s_name, core.t_s_name, core.t_s_name, core.t_s_name, core.t_tsz, core.t_tsz, core.t_qty, core.t_qty, core.t_s_name, core.t_s_name, core.t_s_name); Type: FUNCTION; Schema: cntr; Owner: postgres
--

CREATE FUNCTION cntr.update_contract(p_id core.t_id, p_sname core.t_s_name, p_name core.t_l_name, p_cp_from_sname core.t_s_name, p_cp_to_sname core.t_s_name, p_place_from core.t_s_name, p_place_to core.t_s_name, p_material core.t_s_name, p_custom_status core.t_s_name, p_tsz_bgn core.t_tsz, p_tsz_end core.t_tsz, p_total_qty_min core.t_qty, p_total_qty_max core.t_qty, p_qty_unit_sname core.t_s_name, p_price_index_func core.t_s_name, p_cmnt core.t_s_name) RETURNS core.t_id
    LANGUAGE plpgsql

line 18129

Hope this will help you a little bit.

d1maxa commented 5 years ago

I kind of fixed it in my fork

sakitA commented 5 years ago

The same thing happen also parsing triggers. I think problem is because of using '' in comment.

version 2.4 gives this error

cz.startnet.utils.pgdiff.parsers.ParserException: Cannot parse string: COMMENT ON COLUMN audit.logged_actions.event_id IS 'Unique identifier for each auditable event';

and this from version 2.6.0

Exception in thread "main" java.lang.NullPointerException
    at cz.startnet.utils.pgdiff.parsers.CommentParser.parseTrigger(CommentParser.java:202)
    at cz.startnet.utils.pgdiff.parsers.CommentParser.parse(CommentParser.java:48)
    at cz.startnet.utils.pgdiff.loader.PgDumpLoader.loadDatabaseSchema(PgDumpLoader.java:260)
    at cz.startnet.utils.pgdiff.loader.PgDumpLoader.loadDatabaseSchema(PgDumpLoader.java:311)
    at cz.startnet.utils.pgdiff.PgDiff.createDiff(PgDiff.java:35)
    at cz.startnet.utils.pgdiff.Main.main(Main.java:39)
sakitA commented 5 years ago

I found the problem. Let assume that we have the below statement

COMMENT ON TRIGGER ex_trig ON schem1.table1 IS 'some comment';

As you can see the above example our trigger name is ex_trig and it belongs to schem1 schema. When code parses trigger name and gets schema name function returns default schema name because of there is no schema information with trigger name. In my case, default schema is public but public schema has not trigger with name ex_trig so that programs give NullPointerException

d1maxa commented 5 years ago

I found the problem. Let assume that we have the below statement

COMMENT ON TRIGGER ex_trig ON schem1.table1 IS 'some comment';

As you can see the above example our trigger name is ex_trig and it belongs to schem1 schema. When code parses trigger name and gets schema name function returns default schema name because of there is no schema information with trigger name. In my case, default schema is public but public schema has not trigger with name ex_trig so that programs give NullPointerException

i fixed it in my fork

sakitA commented 5 years ago

@d1maxa I checked your solution. I did also the same thing also. But i am not sure this is the correct way or not

d1maxa commented 5 years ago

@d1maxa I checked your solution. I did also the same thing also. But i am not sure this is the correct way or not

i'm sure

jalissonmello commented 5 years ago

I have tested @d1maxa solutions with some databases scripts and the problem was solved, at lest for me.