File: Versioning.html

package info (click to toggle)
sqlobject 3.1.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,280 kB
  • ctags: 17,912
  • sloc: python: 16,713; sh: 18; makefile: 13
file content (157 lines) | stat: -rw-r--r-- 5,975 bytes parent folder | download
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="content-type">
<title></title>
    <link href="layout.css" type="text/css" rel="stylesheet">
  </head>
  <body>
    <div id="page">
      <h1 class="doc-title"><a></a></h1>
      <div id="navcontainer">
		    <ul id="navlist">
          <li class="pagenav">
            <ul>
              <li class="page_item">
                <a href="index.html" title="Project Home / Index">SQLObject</a>
              </li>
              <li class="page_item">
                <a href="module-index.html" title="sqlobject package and module reference">Modules</a>
              </li>
              <li>
                <a href="community.html" title="Mailing List">Discuss</a>
              </li>
	      <li>
	        <a href="SQLObject.html">Documentation</a>
	      </li>
            </ul>
          </li>
        </ul>
      </div>
      <hr>
      <div id="content"><div class="rst-doc">
  <h1 class="pudge-member-page-heading"></h1>
  <table rules="none" frame="void" class="docinfo">
<col class="docinfo-name">
<col class="docinfo-content">
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td>David Turner, The Open Planning Project</td></tr>
</tbody>
</table>
  <div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a href="#versioning" class="reference internal" id="id2">Versioning</a><ul>
<li><a href="#why" class="reference internal" id="id3">Why</a></li>
<li><a href="#how" class="reference internal" id="id4">How</a></li>
<li><a href="#inheritance" class="reference internal" id="id5">Inheritance</a></li>
<li><a href="#version-tables" class="reference internal" id="id6">Version Tables</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="versioning">
<h1><a href="#id2" class="toc-backref">Versioning</a></h1>
<div class="section" id="why">
<h2><a href="#id3" class="toc-backref">Why</a></h2>
<p>You have a table where rows can be altered, such as a table of wiki
pages.  You want to retain a history of changes for auditing, backup,
or tracking purposes.</p>
<p>You could write a decorator that stores old versions and manage all
access to this object through it.  Or you could take advantage of the
event system in SQLObject 0.8+ and just catch row accesses to the
object.  SQLObject's versioning module does this for you.  And it even
works with inheritance!</p>
</div>
<div class="section" id="how">
<h2><a href="#id4" class="toc-backref">How</a></h2>
<p>Here's how to set it up:</p>
<pre class="literal-block">
class MyClass(SQLObject):
    name = StringCol()
    versions = Versioning()
</pre>
<p>To use it, just create an instance as usual:</p>
<pre class="literal-block">
mc = MyClass(name='fleem')
</pre>
<p>Then make some changes and check out the results:</p>
<pre class="literal-block">
mc.set(name='morx')
assert mc.versions[0].name == 'fleem'
</pre>
<p>You can also restore to a previous version:</p>
<pre class="literal-block">
mc.versions[0].restore()
assert mc.name == "fleem"
</pre>
</div>
<div class="section" id="inheritance">
<h2><a href="#id5" class="toc-backref">Inheritance</a></h2>
<p>There are three ways versioning can be used with <a href="Inheritance.html" class="reference external">inheritance</a>:</p>
<ol class="arabic">
<li><p class="first">Parent versioned, children unversioned:</p>
<pre class="literal-block">
class Base(InheritableSQLObject):
    name = StringCol()
    versions = Versioning()

class Child(Base):
    toy = StringCol()
</pre>
</li>
</ol>
<p>In this case, when changes are made to an instance of Base, new
versions are created.  But when changes are made to an instance of
Child, no new versions are created.</p>
<ol start="2" class="arabic simple">
<li>Children versioned, parents unversioned.</li>
</ol>
<p>In this case, when changes are made to an instance of Child, new
versions are created.  But when changes are made to an instance of
Base, no new versions are created.  The version data for Child
contains all of the columns from child and from base, so that a full
restore is possible.</p>
<ol start="3" class="arabic simple">
<li>Both children and parents versioned.</li>
</ol>
<p>In this case, changes to either Child or Base instances create new
versions, but in different tables.  Child versions still contain all
Base data, and a change to a Child only creates a new Child version, not
a new Base version.</p>
</div>
<div class="section" id="version-tables">
<h2><a href="#id6" class="toc-backref">Version Tables</a></h2>
<p>Versions are stored in a special table which is created when the table
for a versioned class is created.  Version tables are not altered when
the main table is altered, so if you add a column to your main class,
you will need to manually add the column to your version table.</p>
<a href="https://sourceforge.net/projects/sqlobject" class="reference external image-reference"><img src="https://sourceforge.net/sflogo.php?group_id=74338&amp;type=10" alt="Get SQLObject at SourceForge.net. Fast, secure and Free Open Source software downloads" style="width: 80px; height: 15px;" class="noborder align-center"></a>
</div>
</div>
</div></div>
      <div id="footer">
        <p style="float: left;">
          built with 
          <a href="http://lesscode.org/projects/pudge/">pudge/0.1.3</a> |
		      original design by 
          <a href="http://blog.ratterobert.com/">ratter / robert</a>
	      </p>
        <div>
        <br> <!--
        <a name="search">
          <form method="get" id="searchform" 
                action="http://lesscode.org/blog/index.php">
            <div>
              <input type="text" value="" name="s" id="s" />
              <input type="submit" id="searchsubmit" value="Search" />
            </div>
          </form>
        </a> -->
        <br>
        </div>
      </div>
    </div>
  </body>
</html>