Skip to content

Commit

Permalink
Fix a bug in the 3.0 to devel upgrade procedure. Because of the log o…
Browse files Browse the repository at this point in the history
…bjects renaming, the upgrade procedure must create new schemas and functions. But they became linked to the extension. As a result, they could not be later dropped, for instance when processing an emaj_drop_group() function. In the upgrade procedure, drop these objects from the emaj EXTENSION just after their creation. Improve the regression test scenario to cover this case.
  • Loading branch information
beaud76 committed May 3, 2019
1 parent 4a062d2 commit d1b9275
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 34 deletions.
3 changes: 3 additions & 0 deletions sql/emaj--3.0.0--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ $do$
EXECUTE 'CREATE SCHEMA ' || quote_ident(r_schema.log_schema);
EXECUTE 'GRANT ALL ON SCHEMA ' || quote_ident(r_schema.log_schema) || ' TO emaj_adm';
EXECUTE 'GRANT USAGE ON SCHEMA ' || quote_ident(r_schema.log_schema) || ' TO emaj_viewer';
EXECUTE 'ALTER EXTENSION emaj DROP SCHEMA ' || quote_ident(r_schema.log_schema);
-- and record the schema creation into the emaj_schema and the emaj_hist tables
INSERT INTO emaj.emaj_schema (sch_name) VALUES (r_schema.log_schema);
END LOOP;
Expand Down Expand Up @@ -197,6 +198,8 @@ $do$
quote_ident(r_rel.new_log_schema) || '.' || quote_ident(r_rel.new_log_table),
quote_ident(r_rel.new_log_schema) || '.' || quote_ident(r_rel.new_log_sequence),
quote_ident(r_rel.new_log_schema) || '.' || quote_ident(r_rel.new_log_function));
-- remove the log function from the extension
EXECUTE 'ALTER EXTENSION emaj DROP FUNCTION ' || quote_ident(r_rel.new_log_schema) || '.' || quote_ident(r_rel.new_log_function) || '()';
-- if the group is in IDLE state, disable the just recreated trigger
IF NOT r_rel.group_is_logging THEN
EXECUTE 'ALTER TABLE ' || quote_ident(r_rel.rel_schema) || '.' || quote_ident(r_rel.rel_tblseq) || ' DISABLE TRIGGER emaj_log_trg';
Expand Down
28 changes: 26 additions & 2 deletions test/10/expected/after_upg_while_logging.out
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ select emaj.emaj_delete_before_mark_group('myGroup1','M4');

-----------------------------
-- Step 8 : for myGroup6, perform a table change and verify that no log trigger has been called
-- and finaly drop the group
-----------------------------
insert into mySchema6.table_with_51_characters_long_name_____0_________0a values (1),(2);
select count(*) from emaj_myschema6."table_with_51_characters_long_name_____0_________0#1_log";
Expand Down Expand Up @@ -236,6 +237,18 @@ select emaj.emaj_rollback_group('myGroup6', 'Start G6');
1
(1 row)

select emaj.emaj_stop_group('myGroup6');
emaj_stop_group
-----------------
3
(1 row)

select emaj.emaj_drop_group('myGroup6');
emaj_drop_group
-----------------
3
(1 row)

-----------------------------
-- test end: check and reset history
-----------------------------
Expand Down Expand Up @@ -278,7 +291,9 @@ select time_id, time_last_emaj_gid, time_event from emaj.emaj_time_stamp order b
34 | 117 | M
35 | 117 | M
36 | 123 | R
(36 rows)
37 | 123 | M
38 | 123 | D
(38 rows)

select hist_function, hist_event, hist_object,
regexp_replace(regexp_replace(regexp_replace(hist_wording,
Expand Down Expand Up @@ -554,7 +569,16 @@ select hist_function, hist_event, hist_object,
ROLLBACK_TABLE | END | myschema6.table_with_51_characters_long_name_____0_________0a | 4 rolled back primary keys | postgres
ROLLBACK_GROUP | NOTICE | Rollback id 11 | 1 / 3 tables effectively processed. | postgres
ROLLBACK_GROUP | END | myGroup6 | Rollback_id 11, 1 tables and 0 sequences effectively processed | postgres
(265 rows)
STOP_GROUP | BEGIN | myGroup6 | | postgres
LOCK_GROUP | BEGIN | myGroup6 | | postgres
LOCK_GROUP | END | myGroup6 | 3 tables locked, 0 deadlock(s) | postgres
SET_MARK_GROUP | BEGIN | myGroup6 | STOP_% | postgres
SET_MARK_GROUP | END | myGroup6 | STOP_% | postgres
STOP_GROUP | END | myGroup6 | 3 tables/sequences processed | postgres
DROP_GROUP | BEGIN | myGroup6 | | postgres
DROP_GROUP | LOG_SCHEMA DROPPED | emaj_myschema6 | | postgres
DROP_GROUP | END | myGroup6 | 3 tables/sequences processed | postgres
(274 rows)

--
reset role;
Expand Down
28 changes: 26 additions & 2 deletions test/95/expected/after_upg_while_logging.out
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ select emaj.emaj_delete_before_mark_group('myGroup1','M4');

-----------------------------
-- Step 8 : for myGroup6, perform a table change and verify that no log trigger has been called
-- and finaly drop the group
-----------------------------
insert into mySchema6.table_with_51_characters_long_name_____0_________0a values (1),(2);
select count(*) from emaj_myschema6."table_with_51_characters_long_name_____0_________0#1_log";
Expand Down Expand Up @@ -234,6 +235,18 @@ select emaj.emaj_rollback_group('myGroup6', 'Start G6');
1
(1 row)

select emaj.emaj_stop_group('myGroup6');
emaj_stop_group
-----------------
3
(1 row)

select emaj.emaj_drop_group('myGroup6');
emaj_drop_group
-----------------
3
(1 row)

-----------------------------
-- test end: check and reset history
-----------------------------
Expand Down Expand Up @@ -276,7 +289,9 @@ select time_id, time_last_emaj_gid, time_event from emaj.emaj_time_stamp order b
34 | 117 | M
35 | 117 | M
36 | 123 | R
(36 rows)
37 | 123 | M
38 | 123 | D
(38 rows)

select hist_function, hist_event, hist_object,
regexp_replace(regexp_replace(regexp_replace(hist_wording,
Expand Down Expand Up @@ -552,7 +567,16 @@ select hist_function, hist_event, hist_object,
ROLLBACK_TABLE | END | myschema6.table_with_51_characters_long_name_____0_________0a | 4 rolled back primary keys | postgres
ROLLBACK_GROUP | NOTICE | Rollback id 11 | 1 / 3 tables effectively processed. | postgres
ROLLBACK_GROUP | END | myGroup6 | Rollback_id 11, 1 tables and 0 sequences effectively processed | postgres
(265 rows)
STOP_GROUP | BEGIN | myGroup6 | | postgres
LOCK_GROUP | BEGIN | myGroup6 | | postgres
LOCK_GROUP | END | myGroup6 | 3 tables locked, 0 deadlock(s) | postgres
SET_MARK_GROUP | BEGIN | myGroup6 | STOP_% | postgres
SET_MARK_GROUP | END | myGroup6 | STOP_% | postgres
STOP_GROUP | END | myGroup6 | 3 tables/sequences processed | postgres
DROP_GROUP | BEGIN | myGroup6 | | postgres
DROP_GROUP | LOG_SCHEMA DROPPED | emaj_myschema6 | | postgres
DROP_GROUP | END | myGroup6 | 3 tables/sequences processed | postgres
(274 rows)

--
reset role;
Expand Down

0 comments on commit d1b9275

Please sign in to comment.