Skip to content

Commit aa082da

Browse files
committed
Remove deprecated class IAppUser
1 parent 85d553b commit aa082da

File tree

7 files changed

+91
-83
lines changed

7 files changed

+91
-83
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PostgresORM"
22
uuid = "748b5efa-ed57-4836-b183-a38105a77fdd"
33
authors = ["Vincent Laugier <vincent.laugier@gmail.com>"]
4-
version = "0.1.5"
4+
version = "0.1.6"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

docs/src/getting-started.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,67 @@ PostgresORM.Tool.generate_julia_code(dbconn,out_dir)
227227
228228
close(dbconn)
229229
```
230+
231+
## How to record changes
232+
233+
### Record the changes in the modified class itself
234+
You can ask PostgresORM to record the following information inside the class itself :
235+
- the creator of an instance,
236+
- the last editor of an instance,
237+
- the creation time of an instance,
238+
- the last edition time of an instance
239+
240+
To do this you need to declare the following functions in the ORM of the class:
241+
```
242+
get_creator_property() = :your_creator_prop
243+
get_editor_property() = :your_lastEditor_prop
244+
get_creation_time_property() = :your_creationTime_prop
245+
get_update_time_property() = :your_updateTime_prop
246+
```
247+
248+
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`.
290+
Eg.
291+
```
292+
PostgresORM.ModificationORM.get_schema_name() = "my_schema"
293+
```

src/Controller/ModificationORM.jl

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/Controller/coreORM.utils.part1.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ function util_dict2entity(props_dict::Dict{Symbol,T},
526526

527527
# Check that the elements type is not abstract
528528
if isabstracttype(eltype(ptype))
529-
throw(DomainError("Cannot instantiate $ptype because it's a vector of abstract elements. "
529+
throw(DomainError("Cannot instantiate type[$ptype] of property[:$fsymbol] because it's a vector of abstract elements. "
530530
* " Please set a non-abstract vector in 'types_override'"
531531
* " in the ORM[$(PostgresORM.get_orm(dummy_object))]"))
532532
end
@@ -570,11 +570,11 @@ function util_get_property_real_type(datatype::DataType, propname::Symbol)
570570

571571
# Check if there is a type override for this property, if not we
572572
# use the property type
573+
573574
if (isdefined(orm_module,:types_override)
574575
&& propname in collect(keys(orm_module.types_override)))
575576
ptype = PostgresORM.get_orm(dummy_object).types_override[propname]
576577
end
577-
578578
return ptype
579579
end
580580

src/PostgresORM.jl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module PostgresORM
22

33
# Exposed types of PostgresORM
4-
export IEntity, IAppUser, Modification
4+
export IEntity, IEntity, Modification
55

66
# Exposed functions of PostgresORM
77
export get_orm, create_entity!,create_in_bulk_using_copy,retrieve_entity,
@@ -22,6 +22,13 @@ module PostgresORM
2222
include("./model/abstract_types.jl")
2323
include("./model/Modification.jl")
2424

25+
module ModificationORM
26+
using ..PostgresORM
27+
# using ..PostgresORMUtil
28+
# using ..Controller
29+
include("./ModificationORM.jl")
30+
end
31+
2532
# This is a failed attempt to put the API in the module.
2633
# It works, but despite Revise, the web server does not take into account the
2734
# changes. Therefore we prefer to have it put in the main module so that we
@@ -85,12 +92,12 @@ module PostgresORM
8592
include("./Controller/coreORM.delete.jl")
8693
include("./Controller/coreORM.utils.part2.jl")
8794

88-
module ModificationORM
89-
using ..PostgresORM
90-
using ..PostgresORMUtil
91-
using ..Controller
92-
include("./Controller/ModificationORM.jl")
93-
end
95+
# module ModificationORM
96+
# using ..PostgresORM
97+
# using ..PostgresORMUtil
98+
# using ..Controller
99+
# include("./Controller/ModificationORM.jl")
100+
# end
94101

95102
end # module Controller
96103

src/exposed-functions-from-submodules.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
create_entity!(new_object::IEntity,
44
dbconn::LibPQ.Connection;
5-
creator::Union{IAppUser,Missing} = missing)
5+
creator::Union{IEntity,Missing} = missing)
66
77
Persists an instance to the database.
88
Properties of type vector of IEntity are not persisted
@@ -15,7 +15,7 @@ modification table
1515
"""
1616
function create_entity!(new_object::IEntity,
1717
dbconn::LibPQ.Connection;
18-
creator::Union{IAppUser,Missing} = missing)
18+
creator::Union{IEntity,Missing} = missing)
1919

2020
Controller.create_entity!(new_object,
2121
dbconn;
@@ -82,7 +82,7 @@ end
8282
"""
8383
update_entity!(updated_object::IEntity,
8484
dbconn::LibPQ.Connection;
85-
editor::Union{IAppUser,Missing} = missing)
85+
editor::Union{IEntity,Missing} = missing)
8686
8787
Updates an instance to the database.
8888
Properties of type vector of IEntity are not updated
@@ -95,7 +95,7 @@ modification table
9595
"""
9696
function update_entity!(updated_object::IEntity,
9797
dbconn::LibPQ.Connection;
98-
editor::Union{IAppUser,Missing} = missing
98+
editor::Union{IEntity,Missing} = missing
9999
)
100100
Controller.update_entity!(updated_object,
101101
dbconn;
@@ -107,15 +107,15 @@ end
107107
update_vector_property!(updated_object::IEntity,
108108
updated_property::Symbol,
109109
dbconn::Union{Missing, LibPQ.Connection};
110-
editor::Union{Missing, IAppUser} = missing)
110+
editor::Union{Missing, IEntity} = missing)
111111
112112
Updates a property of type vector of IEntity
113113
114114
"""
115115
function update_vector_property!(updated_object::IEntity,
116116
updated_property::Symbol,
117117
dbconn::Union{Missing, LibPQ.Connection};
118-
editor::Union{Missing, IAppUser} = missing)
118+
editor::Union{Missing, IEntity} = missing)
119119

120120
Controller.update_vector_property!(updated_object,
121121
updated_property,
@@ -127,13 +127,13 @@ end
127127
"""
128128
delete_entity(deleted_object::IEntity,
129129
dbconn::LibPQ.Connection;
130-
editor::Union{IAppUser,Missing} = missing)
130+
editor::Union{IEntity,Missing} = missing)
131131
132132
Deletes an entity on the basis of its ID
133133
"""
134134
function delete_entity(deleted_object::IEntity,
135135
dbconn::LibPQ.Connection;
136-
editor::Union{IAppUser,Missing} = missing
136+
editor::Union{IEntity,Missing} = missing
137137
)
138138
Controller.delete_entity(deleted_object,
139139
dbconn;
@@ -144,13 +144,13 @@ end
144144
"""
145145
delete_entity_alike(filter_object::IEntity,
146146
dbconn::LibPQ.Connection;
147-
editor::Union{IAppUser,Missing} = missing)
147+
editor::Union{IEntity,Missing} = missing)
148148
149149
Deletes all entities matching the the filter
150150
"""
151151
function delete_entity_alike(filter_object::IEntity,
152152
dbconn::LibPQ.Connection;
153-
editor::Union{IAppUser,Missing} = missing
153+
editor::Union{IEntity,Missing} = missing
154154
)
155155
Controller.delete_entity_alike(filter_object,
156156
dbconn;

src/model/abstract_types.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
#
44
abstract type IEntity end
55
abstract type IModification <: IEntity end
6-
abstract type IAppUser <: IEntity end # DEPRECATED, kept because some applications
7-
# where inheriting from this class

0 commit comments

Comments
 (0)