forked from technoweenie/acts_as_versioned
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
58 lines (31 loc) · 1.8 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
This is a clone of the acts_as_versioned git project. I am in the process of adding in temporal logic.
It stores the effective_start and effective_end dates of records so that the version history can be searched for what happened at an exact point in history.
Below is the details for acts_as_versioned which still works today.
= acts_as_temporal
This library adds simple versioning to an ActiveRecord module. ActiveRecord is required.
as well as temporal capabilities
It will set timestamps for the effectivity of a record.
on initial create the versioned record
the effective_start field will be set to current time or to whatever effective_date method is set to.
the effective_end field will be set to max integer which is some time in the year 2038 (another y2k but waiting to happen)
on update the versioned record
the previous version record's effective_end field will be set to the current time or to whatever effective_date method is set to.
the new versioned record will act like the initial create
It turns all fields into integers for easier quering
This can be converted by
Time.at(1221627600)
and back with
Time.now.to_i
version | effective_start | effective_end
1 | 1221627600 | 1222405201
2 | 1222405201 | 2147483202
so this allows you to write a between query on the version table to find what the state was at a point in time.
VersionedModel.find(:all, :conditions => ["effective_start <= ? AND effective_end > ?", point_in_time, point_in_time])
the model looks the same as acts_as_versioned except I added the following
t.column effective_start, :integer
t.column effective_end, :integer
== Resources
Install
* ./script/plugin install git://github.com/pbrumm/acts_as_temporal.git/
More details on approach
http://en.wikipedia.org/wiki/Temporal_database