You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: You can decide to only declare some of these functions
249
+
250
+
### Record the changes in a 'modification' table
251
+
252
+
You can also ask PostgresORM to record the details of the modifications of a class
253
+
in a table.
254
+
255
+
To do this you need:
256
+
- Tell the ORM of the class that you want to record the changes
257
+
- A table where to write those modifications
258
+
259
+
#### Declare the following functions in the ORM of the class:
260
+
```
261
+
get_track_changes() = true
262
+
```
263
+
264
+
#### The `Modification` table
265
+
266
+
PostgresORM ships a class `Modification` that inherits from `IEntity`.
267
+
It also has the accompanying ORM mapping module `PostgresORM.ModificationORM`.
268
+
By default, this class is serialized to a table `modification` in the schema `public`.
269
+
270
+
Here is the SQL for the creation of the table if you want to use the default mapping of ModificationORM:
271
+
272
+
```
273
+
CREATE TABLE public.modification
274
+
(
275
+
id uuid NOT NULL DEFAULT uuid_generate_v4(),
276
+
entity_type character varying COLLATE pg_catalog."default",
277
+
entity_id character varying COLLATE pg_catalog."default",
278
+
attrname character varying COLLATE pg_catalog."default",
279
+
oldvalue text COLLATE pg_catalog."default",
280
+
user_id character varying COLLATE pg_catalog."default",
281
+
newvalue text COLLATE pg_catalog."default",
282
+
action_id uuid,
283
+
action_type character varying(10) COLLATE pg_catalog."default",
284
+
creation_time timestamp without time zone,
285
+
CONSTRAINT modification_pkey PRIMARY KEY (id)
286
+
)
287
+
```
288
+
289
+
Suppose the modification table is in a different schema, you can tell PostgresORM where it is by overwriting the functions of `PostgresORM.ModificationORM`.
0 commit comments