1. Patching Data¶
All metadata related to patching can be found in the schema REDPAT.
Patching data consists of 5 steps. The first three are needed to create the necessary metadata while the last two will create the actual data.
1.1. Start a Patch¶
To start a patch and assign a patch-id use the script API_REDPAT.START. The only variable you can provide is a description for the patch.
Example
1EXECUTE SCRIPT API_REDPAT.START(
2 'test_patch' -- p_description
3);
After having issued the command above an entry appears in the table PAT_PATCHES whew you can find the patch-id of the patch that was just created.
PAT_ID |
PAT_SCHEMA |
DESCRIPTION |
STARTED |
PREPARED |
APPLIED |
ABORTED |
SESSION_ID |
---|---|---|---|---|---|---|---|
25 |
PAT_25 |
test_patch |
2024-12-19 15:36:05 |
(null) |
(null) |
(null) |
1841261043324747777 |
In the view REDPAT.PAT_STATUS the patch status shows STARTED. The individual object status is ADDED in this stage and can be seen from PAT_OBJECT_STATUS.
1.2. Add Objects to be Patched¶
Next define all objects that should be part of the patch. Provide the newly created patch-id, schema name and table name of the objects subject to patching to the script API_REDPAT.ADD_OBJECT. In addition, a where-clause may be provided if only specific data of the object should be prepared for change.
Note
The patch basically applies to all BDomains available in the PSA table. Use the where-clause to fetch a subset into the patching area.
Example
1EXECUTE SCRIPT API_REDPAT.ADD_OBJECT(
2 25 -- p_patch_id
3 ,'DBITSA' -- p_obj_schema
4 ,'TEST_PERSON' -- p_obj_table
5 ,'FirstName = 'Jane'' -- p_where
6);
This command adds an entry to the table PAT_OBJECTS.
PAT_OBJECT_ID |
PAT_ID |
PAT_SRC_OBJ_SCHEMA |
PAT_SRC_OBJ_NAME |
PAT_OBJ_SCHEMA |
PAT_OBJ_NAME |
PAT_WHERE |
PAT_SESSION_ID |
---|---|---|---|---|---|---|---|
7 |
25 |
DBITSA |
TEST_PERSON |
PAT_25 |
TEST_PERSON |
FirstName = ‘Jane’ |
1841261043324747777 |
1.3. Add Patch Users¶
Define which users have the right to edit a patch by simply adding these user to the patch executing API_REDPAT.ADD_USER.
Example
1EXECUTE SCRIPT API_REDPAT.ADD_USER(
2 25 -- p_patch_id
3 ,'TESTUSER' -- p_user
4);
This command adds an entry to the table PAT_USERS.
PAT_ID |
PAT_USER |
---|---|
25 |
TESTUSER |
1.4. Prepare the Patch¶
Next you prepare the patch by providing the patch-id to the script API_REDPAT.PREPARE. Issuing this command will start an asynchronous background process which creates a dedicated patch schema containing all objects that fit the where-clause. It may take up to one minute until this process starts.
Example
1EXECUTE SCRIPT API_REDPAT.PREPARE(
2 25 -- p_patch_id
3);
The patch users are provided with all necessary grants for inserting, updateting and deleting data in he patch set. The patch status swichtes to PREPARING first and finally to PREPARED. The individual object status goes from ADDED to PREP_SCHEDULED over PREPARING to PREPARED.
Note
As soon as a patch is PREPARED, no more objects or users can be added to or removed from the patch. For additional changes you may restart the patch by using API_REDPAT.RESTART.
If the prepare function throws an error, you can also use the function API_REDPAT.RESTART to set the patch back to STARTED. Such an error can happen if for example the where-clause was not set properly. After the restart you can remove and add objects from and to the patch using the scripts API_REDPAT.ADD_OBJECT and API_REDPAT.REMOVE_OBJECT again. Furthermore, you can modify the where-clause of an object using the script API_REDPAT.MODIFY_OBJECT.
1.5. Patch the Data¶
Apply your DMLs in the patch area. The patch schema can be found in PAT_STATUS or PAT_PATCHES in the column PAT_SCHEMA.
1.6. Apply the Patch¶
After having finished your changes execute the script API_REDPAT.APPLY. The access to the patch area ist revoked immediately and an asynchronous background process is triggered which takes care of the transfer to historization. The patch status changes from PREPARED to APPLYING and finally to APPLIED while the objects status goes from PREPARED to APPLIED.
Example
1EXECUTE SCRIPT API_REDPAT.APPLY(
2 25 -- p_patch_id
3);
1.7. Abort a Patch¶
As long as the patch ist in status STARTED or PREPARED you may abort it completely by API_REDPAT.ABORT. Related metadata and the patch area will be removed.