NOTE: If you want your custom table to be used in stagprop, Make sure table name doesnot exceed 18 CHAR length.
The stagingprop utility propagates staged data and managed files from the production-ready data to the production server. If you have customized your database schema by creating new tables and you want to stage these custom tables, perform the following steps for each custom table you want to stage.
Step 1 : Identify scope of table
To enabling custom tables for staging first we need to identify scope of table based on following three criteria :insert into STGMERTAB values ('10003','x_attributes,NULL,NULL)
In both the staging server and the production server, insert the customized table into the STGSITETAB, STGMERTAB, or STGMRSTTAB table, depending on the scope of the table.
If you are inserting customized parent and child tables, ensure the TABNBR column value for the child tables are higher than the TABNBR column value for the parent tables.
Step 2 : Creating triggers for custom tables
We need to add SQL statements to create and drop triggers for the new table to the following files:
- WC_installdir/schema/db2/wcs.stage.trigger.sql
- WC_installdir/schema/db2/wcs.droptrigger.sql
Gather the following information about the custom table:
- table name
- table scope (site, merchant, or mixed site and merchant)
- primary or unique key columns
- An INSERT trigger to capture insert operations on the custom table.
- An UPDATE trigger to capture update operation on the custom table.
- A DELETE trigger to capture delete operations on the custom table.
Trigger naming convention
The trigger naming convention is a guideline to ensure that new triggers for custom tables have unique names.
For DB2 : WebSphere Commerce names a trigger by incrementing that last number of the last trigger in the db2/wcs.stage.trigger.sql file. Do not use this naming convention for your new triggers as your custom trigger names could conflict with any new triggers introduced by WebSphere Commerce in fix packs or later releases.
INSERT trigger example(DB2)
This trigger logs INSERT actions in the STAGLOG table after an INSERT action happens on the CATGROUP table.
Create trigger STAG0098
AFTER INSERT ON catgroup REFERENCING NEW AS N
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
INSERT INTO staglog
( stgrfnbr
, stgstmp
, stgtable
, stgop
, stgmenbr
, stgkey1name
, stgokey1
, stgnkey1
)
VALUES (
NEXTVAL FOR STAGESEQ
, CURRENT TIMESTAMP
, 'catgroup'
, 'I'
, 1
, 'catgroup_id'
, N.catgroup_id
, N.catgroup_id
);
END#
UPDATE trigger example (DB2)
This trigger logs UPDATE actions in the STAGLOG table after an UPDATE action happens on the CATGROUP table.Create trigger STAG0099
AFTER UPDATE ON catgroup REFERENCING NEW AS N OLD AS O
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
INSERT INTO staglog
( stgrfnbr
, stgstmp
, stgtable
, stgop
, stgmenbr
, stgkey1name
, stgokey1
, stgnkey1
)
VALUES (
NEXTVAL FOR STAGESEQ
, CURRENT TIMESTAMP
, 'catgroup'
, 'U'
, 1
, 'catgroup_id'
, O.catgroup_id
, N.catgroup_id
);
END#
DELETE trigger example
This trigger logs DELETE actions in the STAGLOG table after a DELETE action happens on the CATGROUP table.
Create trigger STAG0100
AFTER DELETE ON catgroup REFERENCING OLD AS O
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
INSERT INTO staglog
( stgrfnbr
, stgstmp
, stgtable
, stgop
, stgmenbr
, stgkey1name
, stgokey1
)
VALUES (
NEXTVAL FOR STAGESEQ
, CURRENT TIMESTAMP
, 'catgroup'
, 'D'
, 1
, 'catgroup_id'
, O.catgroup_id
);
END#
Manually run the wcs.stage.trigger.sql script file to generate the triggers on the relevant table.
Note: To verify the triggers defined, you run the following SQL statements to query the system table ALL_TRIGGERS:
select * from all_triggers;
No comments:
Post a Comment