This file is indexed.

/usr/share/doc/python-migrate/html/changeset.html is in python-migrate 0.8.2-3ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Database schema migrations &mdash; SQLAlchemy Migrate 0.7.3.dev documentation</title>
    
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.7.3.dev',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="SQLAlchemy Migrate 0.7.3.dev documentation" href="index.html" />
    <link rel="next" title="Repository migration (0.4.5 -&gt; 0.5.4)" href="tools.html" />
    <link rel="prev" title="Database schema versioning workflow" href="versioning.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tools.html" title="Repository migration (0.4.5 -&gt; 0.5.4)"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="versioning.html" title="Database schema versioning workflow"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">SQLAlchemy Migrate 0.7.3.dev documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="database-schema-migrations">
<h1>Database schema migrations<a class="headerlink" href="#database-schema-migrations" title="Permalink to this headline"></a></h1>
<p>Importing <a class="reference internal" href="api.html#module-migrate.changeset" title="migrate.changeset: Database changeset management"><tt class="xref py py-mod docutils literal"><span class="pre">migrate.changeset</span></tt></a> adds some new methods to existing SQLAlchemy
objects, as well as creating functions of its own. Most operations can be done
either by a method or a function. Methods match SQLAlchemy&#8217;s existing API and
are more intuitive when the object is available; functions allow one to make
changes when only the name of an object is available (for example, adding a
column to a table in the database without having to load that table into
Python).</p>
<p>Changeset operations can be used independently of SQLAlchemy Migrate&#8217;s
<a class="reference internal" href="versioning.html#versioning-system"><em>versioning</em></a>.</p>
<p>For more information, see the API documentation for <a class="reference internal" href="api.html#module-migrate.changeset" title="migrate.changeset: Database changeset management"><tt class="xref py py-mod docutils literal"><span class="pre">migrate.changeset</span></tt></a>.</p>
<p id="summary-changeset-api">Here are some direct links to the relevent sections of the API documentations:</p>
<ul class="simple">
<li><a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.create" title="migrate.changeset.schema.ChangesetColumn.create"><tt class="xref py py-meth docutils literal"><span class="pre">Create</span> <span class="pre">a</span> <span class="pre">column</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.drop" title="migrate.changeset.schema.ChangesetColumn.drop"><tt class="xref py py-meth docutils literal"><span class="pre">Drop</span> <span class="pre">a</span> <span class="pre">column</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.alter" title="migrate.changeset.schema.ChangesetColumn.alter"><tt class="xref py py-meth docutils literal"><span class="pre">Alter</span> <span class="pre">a</span> <span class="pre">column</span></tt></a> (follow a link for list of supported changes)</li>
<li><a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetTable.rename" title="migrate.changeset.schema.ChangesetTable.rename"><tt class="xref py py-meth docutils literal"><span class="pre">Rename</span> <span class="pre">a</span> <span class="pre">table</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetIndex.rename" title="migrate.changeset.schema.ChangesetIndex.rename"><tt class="xref py py-meth docutils literal"><span class="pre">Rename</span> <span class="pre">an</span> <span class="pre">index</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.PrimaryKeyConstraint" title="migrate.changeset.constraint.PrimaryKeyConstraint"><tt class="xref py py-meth docutils literal"><span class="pre">Create</span> <span class="pre">primary</span> <span class="pre">key</span> <span class="pre">constraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.PrimaryKeyConstraint.drop" title="migrate.changeset.constraint.PrimaryKeyConstraint.drop"><tt class="xref py py-meth docutils literal"><span class="pre">Drop</span> <span class="pre">primary</span> <span class="pre">key</span> <span class="pre">constraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.ForeignKeyConstraint.create" title="migrate.changeset.constraint.ForeignKeyConstraint.create"><tt class="xref py py-meth docutils literal"><span class="pre">Create</span> <span class="pre">foreign</span> <span class="pre">key</span> <span class="pre">contraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.ForeignKeyConstraint.drop" title="migrate.changeset.constraint.ForeignKeyConstraint.drop"><tt class="xref py py-meth docutils literal"><span class="pre">Drop</span> <span class="pre">foreign</span> <span class="pre">key</span> <span class="pre">constraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.UniqueConstraint.create" title="migrate.changeset.constraint.UniqueConstraint.create"><tt class="xref py py-meth docutils literal"><span class="pre">Create</span> <span class="pre">unique</span> <span class="pre">key</span> <span class="pre">contraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.UniqueConstraint.drop" title="migrate.changeset.constraint.UniqueConstraint.drop"><tt class="xref py py-meth docutils literal"><span class="pre">Drop</span> <span class="pre">unique</span> <span class="pre">key</span> <span class="pre">constraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.CheckConstraint.create" title="migrate.changeset.constraint.CheckConstraint.create"><tt class="xref py py-meth docutils literal"><span class="pre">Create</span> <span class="pre">check</span> <span class="pre">key</span> <span class="pre">contraint</span></tt></a></li>
<li><a class="reference internal" href="api.html#migrate.changeset.constraint.CheckConstraint.drop" title="migrate.changeset.constraint.CheckConstraint.drop"><tt class="xref py py-meth docutils literal"><span class="pre">Drop</span> <span class="pre">check</span> <span class="pre">key</span> <span class="pre">constraint</span></tt></a></li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Many of the schema modification methods above take an <tt class="docutils literal"><span class="pre">alter_metadata</span></tt>
keyword parameter. This parameter defaults to <cite>True</cite>.</p>
</div>
<p>The following sections give examples of how to make various kinds of schema
changes.</p>
<div class="section" id="column">
<h2>Column<a class="headerlink" href="#column" title="Permalink to this headline"></a></h2>
<p>Given a standard SQLAlchemy table:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span> <span class="o">=</span> <span class="n">Table</span><span class="p">(</span><span class="s">&#39;mytable&#39;</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">primary_key</span><span class="o">=</span><span class="bp">True</span><span class="p">),</span>
<span class="p">)</span>
<span class="n">table</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>
</pre></div>
</div>
<p id="column-create">You can create a column with <a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.create" title="migrate.changeset.schema.ChangesetColumn.create"><tt class="xref py py-meth docutils literal"><span class="pre">create()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">col</span> <span class="o">=</span> <span class="n">Column</span><span class="p">(</span><span class="s">&#39;col1&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">&#39;foobar&#39;</span><span class="p">)</span>
<span class="n">col</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">table</span><span class="p">,</span> <span class="n">populate_default</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="c"># Column is added to table based on its name</span>
<span class="k">assert</span> <span class="n">col</span> <span class="ow">is</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col1</span>

<span class="c"># col1 is populated with &#39;foobar&#39; because of `populate_default`</span>
</pre></div>
</div>
<div class="admonition note" id="column-drop">
<p class="first admonition-title">Note</p>
<p>You can pass <cite>primary_key_name</cite>, <cite>index_name</cite> and <cite>unique_name</cite> to the
<a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.create" title="migrate.changeset.schema.ChangesetColumn.create"><tt class="xref py py-meth docutils literal"><span class="pre">create()</span></tt></a> method to issue <tt class="docutils literal"><span class="pre">ALTER</span> <span class="pre">TABLE</span> <span class="pre">ADD</span>
<span class="pre">CONSTRAINT</span></tt> after changing the column.</p>
<p>For multi columns constraints and other advanced configuration, check the
<a class="reference internal" href="#constraint-tutorial"><em>constraint tutorial</em></a>.</p>
<div class="last versionadded">
<p><span class="versionmodified">New in version 0.6.0.</span></p>
</div>
</div>
<p>You can drop a column with <a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.drop" title="migrate.changeset.schema.ChangesetColumn.drop"><tt class="xref py py-meth docutils literal"><span class="pre">drop()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">col</span><span class="o">.</span><span class="n">drop</span><span class="p">()</span>
</pre></div>
</div>
<p id="column-alter">You can alter a column with <a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.alter" title="migrate.changeset.schema.ChangesetColumn.alter"><tt class="xref py py-meth docutils literal"><span class="pre">alter()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">col</span><span class="o">.</span><span class="n">alter</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&#39;col2&#39;</span><span class="p">)</span>

<span class="c"># Renaming a column affects how it&#39;s accessed by the table object</span>
<span class="k">assert</span> <span class="n">col</span> <span class="ow">is</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col2</span>

<span class="c"># Other properties can be modified as well</span>
<span class="n">col</span><span class="o">.</span><span class="n">alter</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">String</span><span class="p">(</span><span class="mi">42</span><span class="p">),</span> <span class="n">default</span><span class="o">=</span><span class="s">&quot;life, the universe, and everything&quot;</span><span class="p">,</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

<span class="c"># Given another column object, col1.alter(col2), col1 will be changed to match col2</span>
<span class="n">col</span><span class="o">.</span><span class="n">alter</span><span class="p">(</span><span class="n">Column</span><span class="p">(</span><span class="s">&#39;col3&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">(</span><span class="mi">77</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="bp">True</span><span class="p">))</span>
<span class="k">assert</span> <span class="n">col</span><span class="o">.</span><span class="n">nullable</span>
<span class="k">assert</span> <span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">col3</span> <span class="ow">is</span> <span class="n">col</span>
</pre></div>
</div>
<div class="deprecated">
<p><span class="versionmodified">Deprecated since version 0.6.0: </span>Passing a <tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt> to
<a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetColumn.alter" title="migrate.changeset.schema.ChangesetColumn.alter"><tt class="xref py py-meth docutils literal"><span class="pre">ChangesetColumn.alter()</span></tt></a> is deprecated. Pass in explicit
parameters, such as <cite>name</cite> for a new column name and <cite>type</cite> for a
new column type, instead. Do <strong>not</strong> include any parameters that
are not changed.</p>
</div>
</div>
<div class="section" id="table">
<span id="table-rename"></span><h2>Table<a class="headerlink" href="#table" title="Permalink to this headline"></a></h2>
<p>SQLAlchemy includes support for <a class="reference external" href="http://www.sqlalchemy.org/docs/core/schema.html#creating-and-dropping-database-tables">creating and dropping</a> tables..</p>
<p>Tables can be renamed with <a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetTable.rename" title="migrate.changeset.schema.ChangesetTable.rename"><tt class="xref py py-meth docutils literal"><span class="pre">rename()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">table</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="s">&#39;newtablename&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="index">
<span id="index-rename"></span><h2>Index<a class="headerlink" href="#index" title="Permalink to this headline"></a></h2>
<p>SQLAlchemy supports <a class="reference external" href="http://www.sqlalchemy.org/docs/core/schema.html#indexes">creating and dropping</a> indexes.</p>
<p>Indexes can be renamed using
<a class="reference internal" href="api.html#migrate.changeset.schema.ChangesetIndex.rename" title="migrate.changeset.schema.ChangesetIndex.rename"><tt class="xref py py-meth docutils literal"><span class="pre">rename()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">index</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="s">&#39;newindexname&#39;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="constraint">
<span id="constraint-tutorial"></span><h2>Constraint<a class="headerlink" href="#constraint" title="Permalink to this headline"></a></h2>
<p>SQLAlchemy supports creating or dropping constraints at the same time a table
is created or dropped. SQLAlchemy Migrate adds support for creating and
dropping <tt class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></tt>,
<tt class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></tt>,
<tt class="xref py py-class docutils literal"><span class="pre">CheckConstraint</span></tt> and
<tt class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></tt> constraints independently using
<tt class="docutils literal"><span class="pre">ALTER</span> <span class="pre">TABLE</span></tt> statements.</p>
<p>The following rundowns are true for all constraints classes:</p>
<ol class="arabic">
<li><p class="first">Make sure you import the relevant constraint class from <a class="reference internal" href="index.html#module-migrate" title="migrate"><tt class="xref py py-mod docutils literal"><span class="pre">migrate</span></tt></a> and
not from <tt class="xref py py-mod docutils literal"><span class="pre">sqlalchemy</span></tt>, for example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">migrate.changeset.constraint</span> <span class="kn">import</span> <span class="n">ForeignKeyConstraint</span>
</pre></div>
</div>
<p>The classes in that module have the extra
<a class="reference internal" href="api.html#migrate.changeset.constraint.ConstraintChangeset.create" title="migrate.changeset.constraint.ConstraintChangeset.create"><tt class="xref py py-meth docutils literal"><span class="pre">create()</span></tt></a> and <a class="reference internal" href="api.html#migrate.changeset.constraint.ConstraintChangeset.drop" title="migrate.changeset.constraint.ConstraintChangeset.drop"><tt class="xref py py-meth docutils literal"><span class="pre">drop()</span></tt></a>
methods.</p>
</li>
<li><p class="first">You can also use constraints as in SQLAlchemy. In this case passing table
argument explicitly is required:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">cons</span> <span class="o">=</span> <span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="s">&#39;num&#39;</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="p">)</span>

<span class="c"># Create the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>

<span class="c"># Drop the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">drop</span><span class="p">()</span>
</pre></div>
</div>
<p>You can also pass in <tt class="xref py py-class docutils literal"><span class="pre">Column</span></tt> objects (and table
argument can be left out):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">cons</span> <span class="o">=</span> <span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="n">col1</span><span class="p">,</span> <span class="n">col2</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">Some dialects support <tt class="docutils literal"><span class="pre">CASCADE</span></tt> option when dropping constraints:</p>
<blockquote>
<div><div class="highlight-python"><div class="highlight"><pre><span class="n">cons</span> <span class="o">=</span> <span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="n">col1</span><span class="p">,</span> <span class="n">col2</span><span class="p">)</span>

<span class="c"># Create the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>

<span class="c"># Drop the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">drop</span><span class="p">(</span><span class="n">cascade</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</div></blockquote>
</li>
</ol>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">SQLAlchemy Migrate will try to guess the name of the constraints for
databases, but if it&#8217;s something other than the default, you&#8217;ll need to
give its name. Best practice is to always name your constraints. Note that
Oracle requires that you state the name of the constraint to be created or
dropped.</p>
</div>
<div class="section" id="examples">
<h3>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h3>
<p>Primary key constraints:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">migrate.changeset.constraint</span> <span class="kn">import</span> <span class="n">PrimaryKeyConstraint</span>

<span class="n">cons</span> <span class="o">=</span> <span class="n">PrimaryKeyConstraint</span><span class="p">(</span><span class="n">col1</span><span class="p">,</span> <span class="n">col2</span><span class="p">)</span>

<span class="c"># Create the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>

<span class="c"># Drop the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">drop</span><span class="p">()</span>
</pre></div>
</div>
<p>Foreign key constraints:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">migrate.changeset.constraint</span> <span class="kn">import</span> <span class="n">ForeignKeyConstraint</span>

<span class="n">cons</span> <span class="o">=</span> <span class="n">ForeignKeyConstraint</span><span class="p">([</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">fkey</span><span class="p">],</span> <span class="p">[</span><span class="n">othertable</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="p">])</span>

<span class="c"># Create the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>

<span class="c"># Drop the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">drop</span><span class="p">()</span>
</pre></div>
</div>
<p>Check constraints:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">migrate.changeset.constraint</span> <span class="kn">import</span> <span class="n">CheckConstraint</span>

<span class="n">cons</span> <span class="o">=</span> <span class="n">CheckConstraint</span><span class="p">(</span><span class="s">&#39;id &gt; 3&#39;</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="p">[</span><span class="n">table</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">id</span><span class="p">])</span>

<span class="c"># Create the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>

<span class="c"># Drop the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">drop</span><span class="p">()</span>
</pre></div>
</div>
<p>Unique constraints:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">migrate.changeset.constraint</span> <span class="kn">import</span> <span class="n">UniqueConstraint</span>

<span class="n">cons</span> <span class="o">=</span> <span class="n">UniqueConstraint</span><span class="p">(</span><span class="s">&#39;id&#39;</span><span class="p">,</span> <span class="s">&#39;age&#39;</span><span class="p">,</span> <span class="n">table</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">table</span><span class="p">)</span>

<span class="c"># Create the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">create</span><span class="p">()</span>

<span class="c"># Drop the constraint</span>
<span class="n">cons</span><span class="o">.</span><span class="n">drop</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Database schema migrations</a><ul>
<li><a class="reference internal" href="#column">Column</a></li>
<li><a class="reference internal" href="#table">Table</a></li>
<li><a class="reference internal" href="#index">Index</a></li>
<li><a class="reference internal" href="#constraint">Constraint</a><ul>
<li><a class="reference internal" href="#examples">Examples</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="versioning.html"
                        title="previous chapter">Database schema versioning workflow</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="tools.html"
                        title="next chapter">Repository migration (0.4.5 -&gt; 0.5.4)</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/changeset.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="tools.html" title="Repository migration (0.4.5 -&gt; 0.5.4)"
             >next</a> |</li>
        <li class="right" >
          <a href="versioning.html" title="Database schema versioning workflow"
             >previous</a> |</li>
        <li><a href="index.html">SQLAlchemy Migrate 0.7.3.dev documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2011, Evan Rosson, Jan Dittberner, Domen Kožar, Chris Withers.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
    </div>
  </body>
</html>