Index: openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d2-1.3.1d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d2-1.3.1d3.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d2-1.3.1d3.sql 10 Nov 2017 17:21:05 -0000 1.1 +++ openacs-4/packages/forums/sql/oracle/upgrade/upgrade-1.3.1d2-1.3.1d3.sql 13 Nov 2017 12:52:59 -0000 1.2 @@ -16,12 +16,18 @@ add column forum_id integer constraint forum_read_forum_id_fk references forums_forums (forum_id) - on delete cascade - constraint forums_read_forum_id_nn - not null; + on delete cascade; +-- populate reference to forum in table +update forums_reading_info i set forum_id = ( + select forum_id + from forums_messages + where message_id = i.root_message_id); + create index forums_reading_info_forum_forum_index on forums_reading_info (forum_id); +ALTER TABLE forums_reading_info ( forum_id NOT NULL); + -- this was a sort of materialized view, but consistency checks made -- code complicated. Redefined as a view create or replace view forums_reading_info_user as Index: openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d2-1.3.1d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d2-1.3.1d3.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d2-1.3.1d3.sql 10 Nov 2017 17:21:05 -0000 1.1 +++ openacs-4/packages/forums/sql/postgresql/upgrade/upgrade-1.3.1d2-1.3.1d3.sql 13 Nov 2017 12:52:59 -0000 1.2 @@ -10,18 +10,23 @@ -- data model -drop table forums_reading_info_user; +drop table if exists forums_reading_info_user; alter table forums_reading_info add column forum_id integer constraint forum_read_forum_id_fk references forums_forums (forum_id) - on delete cascade - constraint forums_read_forum_id_nn - not null; + on delete cascade; +-- populate reference to forum in table +update forums_reading_info i set forum_id = ( + select forum_id + from forums_messages + where message_id = i.root_message_id); + create index forums_reading_info_forum_forum_index on forums_reading_info (forum_id); +alter table forums_reading_info alter column forum_id set not null; -- this was a sort of materialized view, but consistency checks made -- code complicated. Redefined as a view