This file is indexed.

/usr/share/doc/alembic/html/ops.html is in alembic 0.9.3-2ubuntu1.

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
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
<!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>Operation Reference &#8212; Alembic 0.9.3 documentation</title>
    <link rel="stylesheet" href="_static/nature_override.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/changelog.css" type="text/css" />
    <link rel="stylesheet" href="_static/sphinx_paramlinks.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '0.9.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </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="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Cookbook" href="cookbook.html" />
    <link rel="prev" title="Working with Branches" href="branches.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <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="cookbook.html" title="Cookbook"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="branches.html" title="Working with Branches"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Alembic 0.9.3 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="operation-reference">
<span id="ops"></span><h1>Operation Reference<a class="headerlink" href="#operation-reference" title="Permalink to this headline"></a></h1>
<p>This file provides documentation on Alembic migration directives.</p>
<p>The directives here are used within user-defined migration files,
within the <code class="docutils literal"><span class="pre">upgrade()</span></code> and <code class="docutils literal"><span class="pre">downgrade()</span></code> functions, as well as
any functions further invoked by those.</p>
<p>All directives exist as methods on a class called <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a>.
When migration scripts are run, this object is made available
to the script via the <code class="docutils literal"><span class="pre">alembic.op</span></code> datamember, which is
a <em>proxy</em> to an actual instance of <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a>.
Currently, <code class="docutils literal"><span class="pre">alembic.op</span></code> is a real Python module, populated
with individual proxies for each method on <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a>,
so symbols can be imported safely from the <code class="docutils literal"><span class="pre">alembic.op</span></code> namespace.</p>
<p>The <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> system is also fully extensible.  See
<a class="reference internal" href="api/operations.html#operation-plugins"><span class="std std-ref">Operation Plugins</span></a> for details on this.</p>
<p>A key design philosophy to the <a class="reference internal" href="api/operations.html#alembic-operations-toplevel"><span class="std std-ref">Operation Directives</span></a> methods is that
to the greatest degree possible, they internally generate the
appropriate SQLAlchemy metadata, typically involving
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code> and <code class="xref py py-class docutils literal"><span class="pre">Constraint</span></code>
objects.  This so that migration instructions can be
given in terms of just the string names and/or flags involved.
The exceptions to this
rule include the <a class="reference internal" href="#alembic.operations.Operations.add_column" title="alembic.operations.Operations.add_column"><code class="xref py py-meth docutils literal"><span class="pre">add_column()</span></code></a> and <a class="reference internal" href="#alembic.operations.Operations.create_table" title="alembic.operations.Operations.create_table"><code class="xref py py-meth docutils literal"><span class="pre">create_table()</span></code></a>
directives, which require full <code class="xref py py-class docutils literal"><span class="pre">Column</span></code>
objects, though the table metadata is still generated here.</p>
<p>The functions here all require that a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a> has been
configured within the <code class="docutils literal"><span class="pre">env.py</span></code> script first, which is typically
via <a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure" title="alembic.runtime.environment.EnvironmentContext.configure"><code class="xref py py-meth docutils literal"><span class="pre">EnvironmentContext.configure()</span></code></a>.   Under normal
circumstances they are called from an actual migration script, which
itself would be invoked by the <a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.run_migrations" title="alembic.runtime.environment.EnvironmentContext.run_migrations"><code class="xref py py-meth docutils literal"><span class="pre">EnvironmentContext.run_migrations()</span></code></a>
method.</p>
<span class="target" id="module-alembic.operations"></span><dl class="class">
<dt id="alembic.operations.Operations">
<em class="property">class </em><code class="descclassname">alembic.operations.</code><code class="descname">Operations</code><span class="sig-paren">(</span><em>migration_context</em>, <em>impl=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations" title="Permalink to this definition"></a></dt>
<dd><p>Define high level migration operations.</p>
<p>Each operation corresponds to some schema migration operation,
executed against a particular <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>
which in turn represents connectivity to a database,
or a file output stream.</p>
<p>While <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> is normally configured as
part of the <a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.run_migrations" title="alembic.runtime.environment.EnvironmentContext.run_migrations"><code class="xref py py-meth docutils literal"><span class="pre">EnvironmentContext.run_migrations()</span></code></a>
method called from an <code class="docutils literal"><span class="pre">env.py</span></code> script, a standalone
<a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> instance can be
made for use cases external to regular Alembic
migrations by passing in a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic.migration</span> <span class="k">import</span> <span class="n">MigrationContext</span>
<span class="kn">from</span> <span class="nn">alembic.operations</span> <span class="k">import</span> <span class="n">Operations</span>

<span class="n">conn</span> <span class="o">=</span> <span class="n">myengine</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">MigrationContext</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">conn</span><span class="p">)</span>
<span class="n">op</span> <span class="o">=</span> <span class="n">Operations</span><span class="p">(</span><span class="n">ctx</span><span class="p">)</span>

<span class="n">op</span><span class="o">.</span><span class="n">alter_column</span><span class="p">(</span><span class="s2">&quot;t&quot;</span><span class="p">,</span> <span class="s2">&quot;c&quot;</span><span class="p">,</span> <span class="n">nullable</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<p>Note that as of 0.8, most of the methods on this class are produced
dynamically using the <a class="reference internal" href="#alembic.operations.Operations.register_operation" title="alembic.operations.Operations.register_operation"><code class="xref py py-meth docutils literal"><span class="pre">Operations.register_operation()</span></code></a>
method.</p>
<p>Construct a new <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.params.migration_context"></span><strong>migration_context</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.params.migration_context"></a> – a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>
instance.</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="alembic.operations.Operations.add_column">
<code class="descname">add_column</code><span class="sig-paren">(</span><em>table_name</em>, <em>column</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.add_column" title="Permalink to this definition"></a></dt>
<dd><p>Issue an “add column” instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">String</span>

<span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s1">&#39;organization&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The provided <code class="xref py py-class docutils literal"><span class="pre">Column</span></code> object can also
specify a <code class="xref py py-class docutils literal"><span class="pre">ForeignKey</span></code>, referencing
a remote table name.  Alembic will automatically generate a stub
“referenced” table and emit a second ALTER statement in order
to add the constraint separately:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">ForeignKey</span>

<span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s1">&#39;organization&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;account_id&#39;</span><span class="p">,</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">ForeignKey</span><span class="p">(</span><span class="s1">&#39;accounts.id&#39;</span><span class="p">))</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that this statement uses the <code class="xref py py-class docutils literal"><span class="pre">Column</span></code>
construct as is from the SQLAlchemy library.  In particular,
default values to be created on the database side are
specified using the <code class="docutils literal"><span class="pre">server_default</span></code> parameter, and not
<code class="docutils literal"><span class="pre">default</span></code> which only specifies Python-side defaults:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">func</span>

<span class="c1"># specify &quot;DEFAULT NOW&quot; along with the column add</span>
<span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s1">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.add_column.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.add_column.params.table_name"></a> – String name of the parent table.</li>
<li><span class="target" id="alembic.operations.Operations.add_column.params.column"></span><strong>column</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.add_column.params.column"></a> – a <code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Column</span></code> object
representing the new column.</li>
<li><span class="target" id="alembic.operations.Operations.add_column.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.add_column.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.alter_column">
<code class="descname">alter_column</code><span class="sig-paren">(</span><em>table_name</em>, <em>column_name</em>, <em>nullable=None</em>, <em>server_default=False</em>, <em>new_column_name=None</em>, <em>type_=None</em>, <em>existing_type=None</em>, <em>existing_server_default=False</em>, <em>existing_nullable=None</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.alter_column" title="Permalink to this definition"></a></dt>
<dd><p>Issue an “alter column” instruction using the
current migration context.</p>
<p>Generally, only that aspect of the column which
is being changed, i.e. name, type, nullability,
default, needs to be specified.  Multiple changes
can also be specified at once and the backend should
“do the right thing”, emitting each change either
separately or together as the backend allows.</p>
<p>MySQL has special requirements here, since MySQL
cannot ALTER a column without a full specification.
When producing MySQL-compatible migration files,
it is recommended that the <code class="docutils literal"><span class="pre">existing_type</span></code>,
<code class="docutils literal"><span class="pre">existing_server_default</span></code>, and <code class="docutils literal"><span class="pre">existing_nullable</span></code>
parameters be present, if not being altered.</p>
<p>Type changes which are against the SQLAlchemy
“schema” types <code class="xref py py-class docutils literal"><span class="pre">Boolean</span></code>
and  <code class="xref py py-class docutils literal"><span class="pre">Enum</span></code> may also
add or drop constraints which accompany those
types on backends that don’t support them natively.
The <code class="docutils literal"><span class="pre">existing_type</span></code> argument is
used in this case to identify and remove a previous
constraint that was bound to the type object.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.alter_column.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.table_name"></a> – string name of the target table.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.column_name"></span><strong>column_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.column_name"></a> – string name of the target column,
as it exists before the operation begins.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.nullable"></span><strong>nullable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.nullable"></a> – Optional; specify <code class="docutils literal"><span class="pre">True</span></code> or <code class="docutils literal"><span class="pre">False</span></code>
to alter the column’s nullability.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.server_default"></span><strong>server_default</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.server_default"></a> – Optional; specify a string
SQL expression, <code class="xref py py-func docutils literal"><span class="pre">text()</span></code>,
or <code class="xref py py-class docutils literal"><span class="pre">DefaultClause</span></code> to indicate
an alteration to the column’s default value.
Set to <code class="docutils literal"><span class="pre">None</span></code> to have the default removed.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.new_column_name"></span><strong>new_column_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.new_column_name"></a> – Optional; specify a string name here to
indicate the new name within a column rename operation.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.type_"></span><strong>type_</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.type_"></a> – Optional; a <code class="xref py py-class docutils literal"><span class="pre">TypeEngine</span></code>
type object to specify a change to the column’s type.
For SQLAlchemy types that also indicate a constraint (i.e.
<code class="xref py py-class docutils literal"><span class="pre">Boolean</span></code>, <code class="xref py py-class docutils literal"><span class="pre">Enum</span></code>),
the constraint is also generated.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.autoincrement"></span><strong>autoincrement</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.autoincrement"></a> – set the <code class="docutils literal"><span class="pre">AUTO_INCREMENT</span></code> flag of the column;
currently understood by the MySQL dialect.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_type"></span><strong>existing_type</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_type"></a> – Optional; a
<code class="xref py py-class docutils literal"><span class="pre">TypeEngine</span></code>
type object to specify the previous type.   This
is required for all MySQL column alter operations that
don’t otherwise specify a new type, as well as for
when nullability is being changed on a SQL Server
column.  It is also used if the type is a so-called
SQLlchemy “schema” type which may define a constraint (i.e.
<code class="xref py py-class docutils literal"><span class="pre">Boolean</span></code>,
<code class="xref py py-class docutils literal"><span class="pre">Enum</span></code>),
so that the constraint can be dropped.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_server_default"></span><strong>existing_server_default</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_server_default"></a> – Optional; The existing
default value of the column.   Required on MySQL if
an existing default is not being changed; else MySQL
removes the default.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_nullable"></span><strong>existing_nullable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_nullable"></a> – Optional; the existing nullability
of the column.  Required on MySQL if the existing nullability
is not being changed; else MySQL sets this to NULL.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.existing_autoincrement"></span><strong>existing_autoincrement</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.existing_autoincrement"></a> – Optional; the existing autoincrement
of the column.  Used for MySQL’s system of altering a column
that specifies <code class="docutils literal"><span class="pre">AUTO_INCREMENT</span></code>.</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.alter_column.params.postgresql_using"></span><strong>postgresql_using</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.alter_column.params.postgresql_using"></a><p>String argument which will indicate a
SQL expression to render within the Postgresql-specific USING clause
within ALTER COLUMN.    This string is taken directly as raw SQL which
must explicitly include any necessary quoting or escaping of tokens
within the expression.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.8.</span></p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.batch_alter_table">
<code class="descname">batch_alter_table</code><span class="sig-paren">(</span><em>table_name</em>, <em>schema=None</em>, <em>recreate='auto'</em>, <em>copy_from=None</em>, <em>table_args=()</em>, <em>table_kwargs={}</em>, <em>reflect_args=()</em>, <em>reflect_kwargs={}</em>, <em>naming_convention=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.batch_alter_table" title="Permalink to this definition"></a></dt>
<dd><p>Invoke a series of per-table migrations in batch.</p>
<p>Batch mode allows a series of operations specific to a table
to be syntactically grouped together, and allows for alternate
modes of table migration, in particular the “recreate” style of
migration required by SQLite.</p>
<p>“recreate” style is as follows:</p>
<ol class="arabic simple">
<li>A new table is created with the new specification, based on the
migration directives within the batch, using a temporary name.</li>
<li>the data copied from the existing table to the new table.</li>
<li>the existing table is dropped.</li>
<li>the new table is renamed to the existing table name.</li>
</ol>
<p>The directive by default will only use “recreate” style on the
SQLite backend, and only if directives are present which require
this form, e.g. anything other than <code class="docutils literal"><span class="pre">add_column()</span></code>.   The batch
operation on other backends will proceed using standard ALTER TABLE
operations.</p>
<p>The method is used as a context manager, which returns an instance
of <a class="reference internal" href="#alembic.operations.BatchOperations" title="alembic.operations.BatchOperations"><code class="xref py py-class docutils literal"><span class="pre">BatchOperations</span></code></a>; this object is the same as
<a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> except that table names and schema names
are omitted.  E.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">op</span><span class="o">.</span><span class="n">batch_alter_table</span><span class="p">(</span><span class="s2">&quot;some_table&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">batch_op</span><span class="p">:</span>
    <span class="n">batch_op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="n">Column</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">))</span>
    <span class="n">batch_op</span><span class="o">.</span><span class="n">drop_column</span><span class="p">(</span><span class="s1">&#39;bar&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The operations within the context manager are invoked at once
when the context is ended.   When run against SQLite, if the
migrations include operations not supported by SQLite’s ALTER TABLE,
the entire table will be copied to a new one with the new
specification, moving all data across as well.</p>
<p>The copy operation by default uses reflection to retrieve the current
structure of the table, and therefore <a class="reference internal" href="#alembic.operations.Operations.batch_alter_table" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-meth docutils literal"><span class="pre">batch_alter_table()</span></code></a>
in this mode requires that the migration is run in “online” mode.
The <code class="docutils literal"><span class="pre">copy_from</span></code> parameter may be passed which refers to an existing
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object, which will bypass this reflection step.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The table copy operation will currently not copy
CHECK constraints, and may not copy UNIQUE constraints that are
unnamed, as is possible on SQLite.   See the section
<a class="reference internal" href="batch.html#sqlite-batch-constraints"><span class="std std-ref">Dealing with Constraints</span></a> for workarounds.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.table_name"></a> – name of table</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.schema"></a> – optional schema name.</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.recreate"></span><strong>recreate</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.recreate"></a> – under what circumstances the table should be
recreated. At its default of <code class="docutils literal"><span class="pre">&quot;auto&quot;</span></code>, the SQLite dialect will
recreate the table if any operations other than <code class="docutils literal"><span class="pre">add_column()</span></code>,
<code class="docutils literal"><span class="pre">create_index()</span></code>, or <code class="docutils literal"><span class="pre">drop_index()</span></code> are
present. Other options include <code class="docutils literal"><span class="pre">&quot;always&quot;</span></code> and <code class="docutils literal"><span class="pre">&quot;never&quot;</span></code>.</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.copy_from"></span><strong>copy_from</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from"></a><p>optional <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object
that will act as the structure of the table being copied.  If omitted,
table reflection is used to retrieve the structure of the table.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.6: </span>Fully implemented the
<a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">copy_from</span></code></a>
parameter.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p><a class="reference internal" href="batch.html#batch-offline-mode"><span class="std std-ref">Working in Offline Mode</span></a></p>
<p><a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_args" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">reflect_args</span></code></a></p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_kwargs" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">reflect_kwargs</span></code></a></p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.reflect_args"></span><strong>reflect_args</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_args"></a><p>a sequence of additional positional arguments that
will be applied to the table structure being reflected / copied;
this may be used to pass column and constraint overrides to the
table that will be reflected, in lieu of passing the whole
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code> using
<a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">copy_from</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.1.</span></p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.reflect_kwargs"></span><strong>reflect_kwargs</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.reflect_kwargs"></a><p>a dictionary of additional keyword arguments
that will be applied to the table structure being copied; this may be
used to pass additional table and reflection options to the table that
will be reflected, in lieu of passing the whole
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code> using
<a class="reference internal" href="#alembic.operations.Operations.batch_alter_table.params.copy_from" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-paramref docutils literal"><span class="pre">copy_from</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.1.</span></p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.table_args"></span><strong>table_args</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.table_args"></a> – a sequence of additional positional arguments that
will be applied to the new <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> when
created, in addition to those copied from the source table.
This may be used to provide additional constraints such as CHECK
constraints that may not be reflected.</li>
<li><span class="target" id="alembic.operations.Operations.batch_alter_table.params.table_kwargs"></span><strong>table_kwargs</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.table_kwargs"></a> – a dictionary of additional keyword arguments
that will be applied to the new <code class="xref py py-class docutils literal"><span class="pre">Table</span></code>
when created, in addition to those copied from the source table.
This may be used to provide for additional table options that may
not be reflected.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.batch_alter_table.params.naming_convention"></span><strong>naming_convention</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.batch_alter_table.params.naming_convention"></a><p>a naming convention dictionary of the form
described at <a class="reference internal" href="naming.html#autogen-naming-conventions"><span class="std std-ref">Integration of Naming Conventions into Operations, Autogenerate</span></a> which will be applied
to the <code class="xref py py-class docutils literal"><span class="pre">MetaData</span></code> during the reflection
process.  This is typically required if one wants to drop SQLite
constraints, as these constraints will not have names when
reflected on this backend.  Requires SQLAlchemy <strong>0.9.4</strong> or greater.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="batch.html#dropping-sqlite-foreign-keys"><span class="std std-ref">Dropping Unnamed or Named Foreign Key Constraints</span></a></p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.1.</span></p>
</div>
</td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">batch mode requires SQLAlchemy 0.8 or above.</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="batch.html#batch-migrations"><span class="std std-ref">Running “Batch” Migrations for SQLite and Other Databases</span></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.bulk_insert">
<code class="descname">bulk_insert</code><span class="sig-paren">(</span><em>table</em>, <em>rows</em>, <em>multiinsert=True</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.bulk_insert" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “bulk insert” operation using the current
migration context.</p>
<p>This provides a means of representing an INSERT of multiple rows
which works equally well in the context of executing on a live
connection as well as that of generating a SQL script.   In the
case of a SQL script, the values are rendered inline into the
statement.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">date</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="k">import</span> <span class="n">table</span><span class="p">,</span> <span class="n">column</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">String</span><span class="p">,</span> <span class="n">Integer</span><span class="p">,</span> <span class="n">Date</span>

<span class="c1"># Create an ad-hoc table to use for the insert statement.</span>
<span class="n">accounts_table</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s1">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">column</span><span class="p">(</span><span class="s1">&#39;id&#39;</span><span class="p">,</span> <span class="n">Integer</span><span class="p">),</span>
    <span class="n">column</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">),</span>
    <span class="n">column</span><span class="p">(</span><span class="s1">&#39;create_date&#39;</span><span class="p">,</span> <span class="n">Date</span><span class="p">)</span>
<span class="p">)</span>

<span class="n">op</span><span class="o">.</span><span class="n">bulk_insert</span><span class="p">(</span><span class="n">accounts_table</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;John Smith&#39;</span><span class="p">,</span>
                <span class="s1">&#39;create_date&#39;</span><span class="p">:</span><span class="n">date</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">5</span><span class="p">)},</span>
        <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;Ed Williams&#39;</span><span class="p">,</span>
                <span class="s1">&#39;create_date&#39;</span><span class="p">:</span><span class="n">date</span><span class="p">(</span><span class="mi">2007</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">27</span><span class="p">)},</span>
        <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;Wendy Jones&#39;</span><span class="p">,</span>
                <span class="s1">&#39;create_date&#39;</span><span class="p">:</span><span class="n">date</span><span class="p">(</span><span class="mi">2008</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">15</span><span class="p">)},</span>
    <span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<p>When using –sql mode, some datatypes may not render inline
automatically, such as dates and other special types.   When this
issue is present, <a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">Operations.inline_literal()</span></code></a> may be used:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">op</span><span class="o">.</span><span class="n">bulk_insert</span><span class="p">(</span><span class="n">accounts_table</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;John Smith&#39;</span><span class="p">,</span>
                <span class="s1">&#39;create_date&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s2">&quot;2010-10-05&quot;</span><span class="p">)},</span>
        <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;Ed Williams&#39;</span><span class="p">,</span>
                <span class="s1">&#39;create_date&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s2">&quot;2007-05-27&quot;</span><span class="p">)},</span>
        <span class="p">{</span><span class="s1">&#39;id&#39;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;Wendy Jones&#39;</span><span class="p">,</span>
                <span class="s1">&#39;create_date&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s2">&quot;2008-08-15&quot;</span><span class="p">)},</span>
    <span class="p">],</span>
    <span class="n">multiinsert</span><span class="o">=</span><span class="kc">False</span>
<span class="p">)</span>
</pre></div>
</div>
<p>When using <a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">Operations.inline_literal()</span></code></a> in conjunction with
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">Operations.bulk_insert()</span></code></a>, in order for the statement to work
in “online” (e.g. non –sql) mode, the
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert.params.multiinsert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-paramref docutils literal"><span class="pre">multiinsert</span></code></a>
flag should be set to <code class="docutils literal"><span class="pre">False</span></code>, which will have the effect of
individual INSERT statements being emitted to the database, each
with a distinct VALUES clause, so that the “inline” values can
still be rendered, rather than attempting to pass the values
as bound parameters.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.4: </span><a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">Operations.inline_literal()</span></code></a> can now
be used with <a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">Operations.bulk_insert()</span></code></a>, and the
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert.params.multiinsert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-paramref docutils literal"><span class="pre">multiinsert</span></code></a> flag has
been added to assist in this usage when running in “online”
mode.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.bulk_insert.params.table"></span><strong>table</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.bulk_insert.params.table"></a> – a table object which represents the target of the INSERT.</li>
<li><span class="target" id="alembic.operations.Operations.bulk_insert.params.rows"></span><strong>rows</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.bulk_insert.params.rows"></a> – a list of dictionaries indicating rows.</li>
<li><span class="target" id="alembic.operations.Operations.bulk_insert.params.multiinsert"></span><strong>multiinsert</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.bulk_insert.params.multiinsert"></a><p>when at its default of True and –sql mode is not
enabled, the INSERT statement will be executed using
“executemany()” style, where all elements in the list of
dictionaries are passed as bound parameters in a single
list.   Setting this to False results in individual INSERT
statements being emitted per parameter set, and is needed
in those cases where non-literal values are present in the
parameter sets.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.4.</span></p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_check_constraint">
<code class="descname">create_check_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>condition</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_check_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create check constraint” instruction using the
current migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="k">import</span> <span class="n">column</span><span class="p">,</span> <span class="n">func</span>

<span class="n">op</span><span class="o">.</span><span class="n">create_check_constraint</span><span class="p">(</span>
    <span class="s2">&quot;ck_user_name_len&quot;</span><span class="p">,</span>
    <span class="s2">&quot;user&quot;</span><span class="p">,</span>
    <span class="n">func</span><span class="o">.</span><span class="n">len</span><span class="p">(</span><span class="n">column</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">))</span> <span class="o">&gt;</span> <span class="mi">5</span>
<span class="p">)</span>
</pre></div>
</div>
<p>CHECK constraints are usually against a SQL expression, so ad-hoc
table metadata is usually needed.   The function will convert the given
arguments into a <code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.CheckConstraint</span></code> bound
to an anonymous table in order to emit the CREATE statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.name"></a> – Name of the check constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<span class="xref std std-ref">sqla:constraint_naming_conventions</span>,
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.table_name"></a> – String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.condition"></span><strong>condition</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.condition"></a> – SQL expression that’s the condition of the
constraint. Can be a string or SQLAlchemy expression language
structure.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.deferrable"></a> – optional bool. If set, emit DEFERRABLE or
NOT DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.initially"></a> – optional string. If set, emit INITIALLY &lt;value&gt;
when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_check_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_check_constraint.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>source -&gt; table_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_exclude_constraint">
<code class="descname">create_exclude_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>*elements</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_exclude_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue an alter to create an EXCLUDE constraint using the
current migration context.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This method is Postgresql specific, and additionally
requires at least SQLAlchemy 1.0.</p>
</div>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>

<span class="n">op</span><span class="o">.</span><span class="n">create_exclude_constraint</span><span class="p">(</span>
    <span class="s2">&quot;user_excl&quot;</span><span class="p">,</span>
    <span class="s2">&quot;user&quot;</span><span class="p">,</span>

    <span class="p">(</span><span class="s2">&quot;period&quot;</span><span class="p">,</span> <span class="s1">&#39;&amp;&amp;&#39;</span><span class="p">),</span>
    <span class="p">(</span><span class="s2">&quot;group&quot;</span><span class="p">,</span> <span class="s1">&#39;=&#39;</span><span class="p">),</span>
    <span class="n">where</span><span class="o">=</span><span class="p">(</span><span class="s2">&quot;group != &#39;some group&#39;&quot;</span><span class="p">)</span>

<span class="p">)</span>
</pre></div>
</div>
<p>Note that the expressions work the same way as that of
the <code class="docutils literal"><span class="pre">ExcludeConstraint</span></code> object itself; if plain strings are
passed, quoting rules must be applied manually.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.name"></a> – Name of the constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.table_name"></a> – String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.elements"></span><strong>elements</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.elements"></a> – exclude conditions.</li>
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.where"></span><strong>where</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.where"></a> – SQL expression or SQL string with optional WHERE
clause.</li>
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.deferrable"></a> – optional bool. If set, emit DEFERRABLE or
NOT DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.initially"></a> – optional string. If set, emit INITIALLY &lt;value&gt;
when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_exclude_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_exclude_constraint.params.schema"></a> – Optional schema name to operate within.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.9.0.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_foreign_key">
<code class="descname">create_foreign_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>source_table</em>, <em>referent_table</em>, <em>local_cols</em>, <em>remote_cols</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>match=None</em>, <em>source_schema=None</em>, <em>referent_schema=None</em>, <em>**dialect_kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_foreign_key" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create foreign key” instruction using the
current migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_foreign_key</span><span class="p">(</span>
            <span class="s2">&quot;fk_user_address&quot;</span><span class="p">,</span> <span class="s2">&quot;address&quot;</span><span class="p">,</span>
            <span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">])</span>
</pre></div>
</div>
<p>This internally generates a <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object
containing the necessary columns, then generates a new
<code class="xref py py-class docutils literal"><span class="pre">ForeignKeyConstraint</span></code>
object which it then associates with the
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code>.
Any event listeners associated with this action will be fired
off normally.   The <code class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></code>
construct is ultimately used to generate the ALTER statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.name"></a> – Name of the foreign key constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<span class="xref std std-ref">sqla:constraint_naming_conventions</span>,
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.source_table"></span><strong>source_table</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.source_table"></a> – String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.referent_table"></span><strong>referent_table</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.referent_table"></a> – String name of the destination table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.local_cols"></span><strong>local_cols</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.local_cols"></a> – a list of string column names in the
source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.remote_cols"></span><strong>remote_cols</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.remote_cols"></a> – a list of string column names in the
remote table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.onupdate"></span><strong>onupdate</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.onupdate"></a> – Optional string. If set, emit ON UPDATE &lt;value&gt; when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.ondelete"></span><strong>ondelete</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.ondelete"></a> – Optional string. If set, emit ON DELETE &lt;value&gt; when
issuing DDL for this constraint. Typical values include CASCADE,
DELETE and RESTRICT.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.deferrable"></a> – optional bool. If set, emit DEFERRABLE or NOT
DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.source_schema"></span><strong>source_schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.source_schema"></a> – Optional schema name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_foreign_key.params.referent_schema"></span><strong>referent_schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_foreign_key.params.referent_schema"></a> – Optional schema name of the destination table.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>source -&gt; source_table</li>
<li>referent -&gt; referent_table</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_index">
<code class="descname">create_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>table_name</em>, <em>columns</em>, <em>schema=None</em>, <em>unique=False</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_index" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create index” instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s1">&#39;ik_test&#39;</span><span class="p">,</span> <span class="s1">&#39;t1&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>Functional indexes can be produced by using the
<code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.text()</span></code> construct:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">text</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_index</span><span class="p">(</span><span class="s1">&#39;ik_test&#39;</span><span class="p">,</span> <span class="s1">&#39;t1&#39;</span><span class="p">,</span> <span class="p">[</span><span class="n">text</span><span class="p">(</span><span class="s1">&#39;lower(foo)&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.7: </span>support for making use of the
<code class="xref py py-func docutils literal"><span class="pre">text()</span></code> construct in
conjunction with
<a class="reference internal" href="#alembic.operations.Operations.create_index" title="alembic.operations.Operations.create_index"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_index()</span></code></a> in
order to produce functional expressions within CREATE INDEX.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_index.params.index_name"></span><strong>index_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.index_name"></a> – name of the index.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.table_name"></a> – name of the owning table.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.columns"></a> – a list consisting of string column names and/or
<code class="xref py py-func docutils literal"><span class="pre">text()</span></code> constructs.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.unique"></span><strong>unique</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.unique"></a> – If True, create a unique index.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.quote"></span><strong>quote</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.quote"></a> – Force quoting of this column’s name on or off, corresponding
to <code class="docutils literal"><span class="pre">True</span></code> or <code class="docutils literal"><span class="pre">False</span></code>. When left at its default
of <code class="docutils literal"><span class="pre">None</span></code>, the column identifier will be quoted according to
whether the name is case sensitive (identifiers with at least one
upper case character are treated as case sensitive), or if it’s a
reserved word. This flag is only needed to force quoting of a
reserved word which is not known by the SQLAlchemy dialect.</li>
<li><span class="target" id="alembic.operations.Operations.create_index.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_index.params.**kw"></a> – Additional keyword arguments not mentioned above are
dialect specific, and passed in the form
<code class="docutils literal"><span class="pre">&lt;dialectname&gt;_&lt;argname&gt;</span></code>.
See the documentation regarding an individual dialect at
<span class="xref std std-ref">dialect_toplevel</span> for detail on documented arguments.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; index_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_primary_key">
<code class="descname">create_primary_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>columns</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_primary_key" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create primary key” instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_primary_key</span><span class="p">(</span>
            <span class="s2">&quot;pk_my_table&quot;</span><span class="p">,</span> <span class="s2">&quot;my_table&quot;</span><span class="p">,</span>
            <span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">,</span> <span class="s2">&quot;version&quot;</span><span class="p">]</span>
        <span class="p">)</span>
</pre></div>
</div>
<p>This internally generates a <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object
containing the necessary columns, then generates a new
<code class="xref py py-class docutils literal"><span class="pre">PrimaryKeyConstraint</span></code>
object which it then associates with the
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code>.
Any event listeners associated with this action will be fired
off normally.   The <code class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></code>
construct is ultimately used to generate the ALTER statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.name"></a> – Name of the primary key constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<span class="xref std std-ref">sqla:constraint_naming_conventions</span>
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.table_name"></a> – String name of the target table.</li>
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.columns"></a> – a list of string column names to be applied to the
primary key constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_primary_key.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_primary_key.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>cols -&gt; columns</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_table">
<code class="descname">create_table</code><span class="sig-paren">(</span><em>table_name</em>, <em>*columns</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_table" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create table” instruction using the current migration
context.</p>
<p>This directive receives an argument list similar to that of the
traditional <code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Table</span></code> construct, but without the
metadata:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">,</span> <span class="n">Column</span>
<span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>

<span class="n">op</span><span class="o">.</span><span class="n">create_table</span><span class="p">(</span>
    <span class="s1">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#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="kc">True</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="kc">False</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;description&#39;</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">(</span><span class="mi">200</span><span class="p">)),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<p>Note that <a class="reference internal" href="#alembic.operations.Operations.create_table" title="alembic.operations.Operations.create_table"><code class="xref py py-meth docutils literal"><span class="pre">create_table()</span></code></a> accepts
<code class="xref py py-class docutils literal"><span class="pre">Column</span></code>
constructs directly from the SQLAlchemy library.  In particular,
default values to be created on the database side are
specified using the <code class="docutils literal"><span class="pre">server_default</span></code> parameter, and not
<code class="docutils literal"><span class="pre">default</span></code> which only specifies Python-side defaults:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">Column</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">func</span>

<span class="c1"># specify &quot;DEFAULT NOW&quot; along with the &quot;timestamp&quot; column</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_table</span><span class="p">(</span><span class="s1">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#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="kc">True</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>
</pre></div>
</div>
<p>The function also returns a newly created
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object, corresponding to the table
specification given, which is suitable for
immediate SQL operations, in particular
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">Operations.bulk_insert()</span></code></a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">INTEGER</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">,</span> <span class="n">Column</span>
<span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>

<span class="n">account_table</span> <span class="o">=</span> <span class="n">op</span><span class="o">.</span><span class="n">create_table</span><span class="p">(</span>
    <span class="s1">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#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="kc">True</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">VARCHAR</span><span class="p">(</span><span class="mi">50</span><span class="p">),</span> <span class="n">nullable</span><span class="o">=</span><span class="kc">False</span><span class="p">),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;description&#39;</span><span class="p">,</span> <span class="n">NVARCHAR</span><span class="p">(</span><span class="mi">200</span><span class="p">)),</span>
    <span class="n">Column</span><span class="p">(</span><span class="s1">&#39;timestamp&#39;</span><span class="p">,</span> <span class="n">TIMESTAMP</span><span class="p">,</span> <span class="n">server_default</span><span class="o">=</span><span class="n">func</span><span class="o">.</span><span class="n">now</span><span class="p">())</span>
<span class="p">)</span>

<span class="n">op</span><span class="o">.</span><span class="n">bulk_insert</span><span class="p">(</span>
    <span class="n">account_table</span><span class="p">,</span>
    <span class="p">[</span>
        <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;A1&quot;</span><span class="p">,</span> <span class="s2">&quot;description&quot;</span><span class="p">:</span> <span class="s2">&quot;account 1&quot;</span><span class="p">},</span>
        <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;A2&quot;</span><span class="p">,</span> <span class="s2">&quot;description&quot;</span><span class="p">:</span> <span class="s2">&quot;account 2&quot;</span><span class="p">},</span>
    <span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><span class="target" id="alembic.operations.Operations.create_table.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.table_name"></a> – Name of the table</li>
<li><span class="target" id="alembic.operations.Operations.create_table.params.*columns"></span><strong>*columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.*columns"></a> – collection of <code class="xref py py-class docutils literal"><span class="pre">Column</span></code>
objects within
the table, as well as optional <code class="xref py py-class docutils literal"><span class="pre">Constraint</span></code>
objects
and <code class="xref py py-class docutils literal"><span class="pre">Index</span></code> objects.</li>
<li><span class="target" id="alembic.operations.Operations.create_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.create_table.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_table.params.**kw"></a> – Other keyword arguments are passed to the underlying
<code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Table</span></code> object created for the command.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><p>the <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object corresponding
to the parameters given.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>- the <code class="xref py py-class docutils literal"><span class="pre">Table</span></code>
object is returned.</p>
</div>
</p>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; table_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.create_unique_constraint">
<code class="descname">create_unique_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>columns</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.create_unique_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create unique constraint” instruction using the
current migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="n">op</span><span class="o">.</span><span class="n">create_unique_constraint</span><span class="p">(</span><span class="s2">&quot;uq_user_name&quot;</span><span class="p">,</span> <span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
</pre></div>
</div>
<p>This internally generates a <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> object
containing the necessary columns, then generates a new
<code class="xref py py-class docutils literal"><span class="pre">UniqueConstraint</span></code>
object which it then associates with the
<code class="xref py py-class docutils literal"><span class="pre">Table</span></code>.
Any event listeners associated with this action will be fired
off normally.   The <code class="xref py py-class docutils literal"><span class="pre">AddConstraint</span></code>
construct is ultimately used to generate the ALTER statement.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.name"></span><strong>name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.name"></a> – Name of the unique constraint.  The name is necessary
so that an ALTER statement can be emitted.  For setups that
use an automated naming scheme such as that described at
<span class="xref std std-ref">sqla:constraint_naming_conventions</span>,
<code class="docutils literal"><span class="pre">name</span></code> here can be <code class="docutils literal"><span class="pre">None</span></code>, as the event listener will
apply the name to the constraint object when it is associated
with the table.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.table_name"></a> – String name of the source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.columns"></span><strong>columns</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.columns"></a> – a list of string column names in the
source table.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.deferrable"></span><strong>deferrable</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.deferrable"></a> – optional bool. If set, emit DEFERRABLE or
NOT DEFERRABLE when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.initially"></span><strong>initially</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.initially"></a> – optional string. If set, emit INITIALLY &lt;value&gt;
when issuing DDL for this constraint.</li>
<li><span class="target" id="alembic.operations.Operations.create_unique_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.create_unique_constraint.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>source -&gt; table_name</li>
<li>local_cols -&gt; columns</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_column">
<code class="descname">drop_column</code><span class="sig-paren">(</span><em>table_name</em>, <em>column_name</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_column" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “drop column” instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">drop_column</span><span class="p">(</span><span class="s1">&#39;organization&#39;</span><span class="p">,</span> <span class="s1">&#39;account_id&#39;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_column.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.table_name"></a> – name of table</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.column_name"></span><strong>column_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.column_name"></a> – name of column</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.mssql_drop_check"></span><strong>mssql_drop_check</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.mssql_drop_check"></a> – Optional boolean.  When <code class="docutils literal"><span class="pre">True</span></code>, on
Microsoft SQL Server only, first
drop the CHECK constraint on the column using a
SQL-script-compatible
block that selects into a &#64;variable from sys.check_constraints,
then exec’s a separate DROP CONSTRAINT for that constraint.</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.mssql_drop_default"></span><strong>mssql_drop_default</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.mssql_drop_default"></a> – Optional boolean.  When <code class="docutils literal"><span class="pre">True</span></code>, on
Microsoft SQL Server only, first
drop the DEFAULT constraint on the column using a
SQL-script-compatible
block that selects into a &#64;variable from sys.default_constraints,
then exec’s a separate DROP CONSTRAINT for that default.</li>
<li><span class="target" id="alembic.operations.Operations.drop_column.params.mssql_drop_foreign_key"></span><strong>mssql_drop_foreign_key</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_column.params.mssql_drop_foreign_key"></a><p>Optional boolean.  When <code class="docutils literal"><span class="pre">True</span></code>, on
Microsoft SQL Server only, first
drop a single FOREIGN KEY constraint on the column using a
SQL-script-compatible
block that selects into a &#64;variable from
sys.foreign_keys/sys.foreign_key_columns,
then exec’s a separate DROP CONSTRAINT for that default.  Only
works if the column has exactly one FK constraint which refers to
it, at the moment.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.2.</span></p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_constraint">
<code class="descname">drop_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>table_name</em>, <em>type_=None</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Drop a constraint of the given name, typically via DROP CONSTRAINT.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.constraint_name"></span><strong>constraint_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.constraint_name"></a> – name of the constraint.</li>
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.table_name"></a> – table name.</li>
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.type_"></span><strong>type_</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.type_"></a> – optional, required on MySQL.  can be
‘foreignkey’, ‘primary’, ‘unique’, or ‘check’.</li>
<li><span class="target" id="alembic.operations.Operations.drop_constraint.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_constraint.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_index">
<code class="descname">drop_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>table_name=None</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_index" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “drop index” instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">drop_index</span><span class="p">(</span><span class="s2">&quot;accounts&quot;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_index.params.index_name"></span><strong>index_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_index.params.index_name"></a> – name of the index.</li>
<li><span class="target" id="alembic.operations.Operations.drop_index.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_index.params.table_name"></a> – name of the owning table.  Some
backends such as Microsoft SQL Server require this.</li>
<li><span class="target" id="alembic.operations.Operations.drop_index.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_index.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; index_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.drop_table">
<code class="descname">drop_table</code><span class="sig-paren">(</span><em>table_name</em>, <em>schema=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.drop_table" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “drop table” instruction using the current
migration context.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">drop_table</span><span class="p">(</span><span class="s2">&quot;accounts&quot;</span><span class="p">)</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.drop_table.params.table_name"></span><strong>table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_table.params.table_name"></a> – Name of the table</li>
<li><span class="target" id="alembic.operations.Operations.drop_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_table.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
<li><span class="target" id="alembic.operations.Operations.drop_table.params.**kw"></span><strong>**kw</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.drop_table.params.**kw"></a> – Other keyword arguments are passed to the underlying
<code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.schema.Table</span></code> object created for the command.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; table_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.execute">
<code class="descname">execute</code><span class="sig-paren">(</span><em>sqltext</em>, <em>execution_options=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.execute" title="Permalink to this definition"></a></dt>
<dd><p>Execute the given SQL using the current migration context.</p>
<p>In a SQL script context, the statement is emitted directly to the
output stream.   There is <em>no</em> return result, however, as this
function is oriented towards generating a change script
that can run in “offline” mode.  For full interaction
with a connected database, use the “bind” available
from the context:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>
<span class="n">connection</span> <span class="o">=</span> <span class="n">op</span><span class="o">.</span><span class="n">get_bind</span><span class="p">()</span>
</pre></div>
</div>
<p>Also note that any parameterized statement here <em>will not work</em>
in offline mode - INSERT, UPDATE and DELETE statements which refer
to literal values would need to render
inline expressions.   For simple use cases, the
<a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">inline_literal()</span></code></a> function can be used for <strong>rudimentary</strong>
quoting of string values.  For “bulk” inserts, consider using
<a class="reference internal" href="#alembic.operations.Operations.bulk_insert" title="alembic.operations.Operations.bulk_insert"><code class="xref py py-meth docutils literal"><span class="pre">bulk_insert()</span></code></a>.</p>
<p>For example, to emit an UPDATE statement which is equally
compatible with both online and offline mode:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sqlalchemy.sql</span> <span class="k">import</span> <span class="n">table</span><span class="p">,</span> <span class="n">column</span>
<span class="kn">from</span> <span class="nn">sqlalchemy</span> <span class="k">import</span> <span class="n">String</span>
<span class="kn">from</span> <span class="nn">alembic</span> <span class="k">import</span> <span class="n">op</span>

<span class="n">account</span> <span class="o">=</span> <span class="n">table</span><span class="p">(</span><span class="s1">&#39;account&#39;</span><span class="p">,</span>
    <span class="n">column</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="n">String</span><span class="p">)</span>
<span class="p">)</span>
<span class="n">op</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span>
    <span class="n">account</span><span class="o">.</span><span class="n">update</span><span class="p">()</span><span class="o">.</span>\
        <span class="n">where</span><span class="p">(</span><span class="n">account</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">name</span><span class="o">==</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s1">&#39;account 1&#39;</span><span class="p">))</span><span class="o">.</span>\
        <span class="n">values</span><span class="p">({</span><span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="n">op</span><span class="o">.</span><span class="n">inline_literal</span><span class="p">(</span><span class="s1">&#39;account 2&#39;</span><span class="p">)})</span>
        <span class="p">)</span>
</pre></div>
</div>
<p>Note above we also used the SQLAlchemy
<code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.table()</span></code>
and <code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.column()</span></code> constructs to
make a brief, ad-hoc table construct just for our UPDATE
statement.  A full <code class="xref py py-class docutils literal"><span class="pre">Table</span></code> construct
of course works perfectly fine as well, though note it’s a
recommended practice to at least ensure the definition of a
table is self-contained within the migration script, rather
than imported from a module that may break compatibility with
older migrations.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.execute.params.sql"></span><strong>sql</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.execute.params.sql"></a> – Any legal SQLAlchemy expression, including:</td>
</tr>
</tbody>
</table>
<ul class="simple">
<li>a string</li>
<li>a <code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.text()</span></code> construct.</li>
<li>a <code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.insert()</span></code> construct.</li>
<li>a <code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.update()</span></code>,
<code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.insert()</span></code>,
or <code class="xref py py-func docutils literal"><span class="pre">sqlalchemy.sql.expression.delete()</span></code>  construct.</li>
<li>Pretty much anything that’s “executable” as described
in <span class="xref std std-ref">sqlexpression_toplevel</span>.</li>
</ul>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.Operations.execute.params.execution_options"></span><strong>execution_options</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.execute.params.execution_options"></a> – Optional dictionary of
execution options, will be passed to
<code class="xref py py-meth docutils literal"><span class="pre">sqlalchemy.engine.Connection.execution_options()</span></code>.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.f">
<code class="descname">f</code><span class="sig-paren">(</span><em>name</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.f" title="Permalink to this definition"></a></dt>
<dd><p>Indicate a string name that has already had a naming convention
applied to it.</p>
<p>This feature combines with the SQLAlchemy <code class="docutils literal"><span class="pre">naming_convention</span></code> feature
to disambiguate constraint names that have already had naming
conventions applied to them, versus those that have not.  This is
necessary in the case that the <code class="docutils literal"><span class="pre">&quot;%(constraint_name)s&quot;</span></code> token
is used within a naming convention, so that it can be identified
that this particular name should remain fixed.</p>
<p>If the <a class="reference internal" href="#alembic.operations.Operations.f" title="alembic.operations.Operations.f"><code class="xref py py-meth docutils literal"><span class="pre">Operations.f()</span></code></a> is used on a constraint, the naming
convention will not take effect:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">op</span><span class="o">.</span><span class="n">add_column</span><span class="p">(</span><span class="s1">&#39;t&#39;</span><span class="p">,</span> <span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="n">Boolean</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">op</span><span class="o">.</span><span class="n">f</span><span class="p">(</span><span class="s1">&#39;ck_bool_t_x&#39;</span><span class="p">)))</span>
</pre></div>
</div>
<p>Above, the CHECK constraint generated will have the name
<code class="docutils literal"><span class="pre">ck_bool_t_x</span></code> regardless of whether or not a naming convention is
in use.</p>
<p>Alternatively, if a naming convention is in use, and ‘f’ is not used,
names will be converted along conventions.  If the <code class="docutils literal"><span class="pre">target_metadata</span></code>
contains the naming convention
<code class="docutils literal"><span class="pre">{&quot;ck&quot;:</span> <span class="pre">&quot;ck_bool_%(table_name)s_%(constraint_name)s&quot;}</span></code>, then the
output of the following:</p>
<blockquote>
<div>op.add_column(‘t’, ‘x’, Boolean(name=’x’))</div></blockquote>
<p>will be:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">CONSTRAINT</span> <span class="n">ck_bool_t_x</span> <span class="n">CHECK</span> <span class="p">(</span><span class="n">x</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">)))</span>
</pre></div>
</div>
<p>The function is rendered in the output of autogenerate when
a particular constraint name is already converted, for SQLAlchemy
version <strong>0.9.4 and greater only</strong>.   Even though <code class="docutils literal"><span class="pre">naming_convention</span></code>
was introduced in 0.9.2, the string disambiguation service is new
as of 0.9.4.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.6.4.</span></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.get_bind">
<code class="descname">get_bind</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.get_bind" title="Permalink to this definition"></a></dt>
<dd><p>Return the current ‘bind’.</p>
<p>Under normal circumstances, this is the
<code class="xref py py-class docutils literal"><span class="pre">Connection</span></code> currently being used
to emit SQL to the database.</p>
<p>In a SQL script context, this value is <code class="docutils literal"><span class="pre">None</span></code>. [TODO: verify this]</p>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.get_context">
<code class="descname">get_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.get_context" title="Permalink to this definition"></a></dt>
<dd><p>Return the <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a> object that’s
currently in use.</p>
</dd></dl>

<dl class="classmethod">
<dt id="alembic.operations.Operations.implementation_for">
<em class="property">classmethod </em><code class="descname">implementation_for</code><span class="sig-paren">(</span><em>op_cls</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.implementation_for" title="Permalink to this definition"></a></dt>
<dd><p>Register an implementation for a given <a class="reference internal" href="api/operations.html#alembic.operations.ops.MigrateOperation" title="alembic.operations.ops.MigrateOperation"><code class="xref py py-class docutils literal"><span class="pre">MigrateOperation</span></code></a>.</p>
<p>This is part of the operation extensibility API.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/operations.html#operation-plugins"><span class="std std-ref">Operation Plugins</span></a> - example of use</p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.inline_literal">
<code class="descname">inline_literal</code><span class="sig-paren">(</span><em>value</em>, <em>type_=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.inline_literal" title="Permalink to this definition"></a></dt>
<dd><p>Produce an ‘inline literal’ expression, suitable for
using in an INSERT, UPDATE, or DELETE statement.</p>
<p>When using Alembic in “offline” mode, CRUD operations
aren’t compatible with SQLAlchemy’s default behavior surrounding
literal values,
which is that they are converted into bound values and passed
separately into the <code class="docutils literal"><span class="pre">execute()</span></code> method of the DBAPI cursor.
An offline SQL
script needs to have these rendered inline.  While it should
always be noted that inline literal values are an <strong>enormous</strong>
security hole in an application that handles untrusted input,
a schema migration is not run in this context, so
literals are safe to render inline, with the caveat that
advanced types like dates may not be supported directly
by SQLAlchemy.</p>
<p>See <a class="reference internal" href="#alembic.operations.Operations.execute" title="alembic.operations.Operations.execute"><code class="xref py py-meth docutils literal"><span class="pre">execute()</span></code></a> for an example usage of
<a class="reference internal" href="#alembic.operations.Operations.inline_literal" title="alembic.operations.Operations.inline_literal"><code class="xref py py-meth docutils literal"><span class="pre">inline_literal()</span></code></a>.</p>
<p>The environment can also be configured to attempt to render
“literal” values inline automatically, for those simple types
that are supported by the dialect; see
<a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.literal_binds" title="alembic.runtime.environment.EnvironmentContext.configure"><code class="xref py py-paramref docutils literal"><span class="pre">EnvironmentContext.configure.literal_binds</span></code></a> for this
more recently added feature.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.inline_literal.params.value"></span><strong>value</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.inline_literal.params.value"></a> – The value to render.  Strings, integers, and simple
numerics should be supported.   Other types like boolean,
dates, etc. may or may not be supported yet by various
backends.</li>
<li><span class="target" id="alembic.operations.Operations.inline_literal.params.type_"></span><strong>type_</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.inline_literal.params.type_"></a> – optional - a <code class="xref py py-class docutils literal"><span class="pre">sqlalchemy.types.TypeEngine</span></code>
subclass stating the type of this value.  In SQLAlchemy
expressions, this is usually derived automatically
from the Python type of the value itself, as well as
based on the context in which the value is used.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/runtime.html#alembic.runtime.environment.EnvironmentContext.configure.params.literal_binds" title="alembic.runtime.environment.EnvironmentContext.configure"><code class="xref py py-paramref docutils literal"><span class="pre">EnvironmentContext.configure.literal_binds</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.invoke">
<code class="descname">invoke</code><span class="sig-paren">(</span><em>operation</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.invoke" title="Permalink to this definition"></a></dt>
<dd><p>Given a <a class="reference internal" href="api/operations.html#alembic.operations.ops.MigrateOperation" title="alembic.operations.ops.MigrateOperation"><code class="xref py py-class docutils literal"><span class="pre">MigrateOperation</span></code></a>, invoke it in terms of
this <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> instance.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.0.</span></p>
</div>
</dd></dl>

<dl class="classmethod">
<dt id="alembic.operations.Operations.register_operation">
<em class="property">classmethod </em><code class="descname">register_operation</code><span class="sig-paren">(</span><em>name</em>, <em>sourcename=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.register_operation" title="Permalink to this definition"></a></dt>
<dd><p>Register a new operation for this class.</p>
<p>This method is normally used to add new operations
to the <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> class, and possibly the
<a class="reference internal" href="#alembic.operations.BatchOperations" title="alembic.operations.BatchOperations"><code class="xref py py-class docutils literal"><span class="pre">BatchOperations</span></code></a> class as well.   All Alembic migration
operations are implemented via this system, however the system
is also available as a public API to facilitate adding custom
operations.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.8.0.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="api/operations.html#operation-plugins"><span class="std std-ref">Operation Plugins</span></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.Operations.rename_table">
<code class="descname">rename_table</code><span class="sig-paren">(</span><em>old_table_name</em>, <em>new_table_name</em>, <em>schema=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.Operations.rename_table" title="Permalink to this definition"></a></dt>
<dd><p>Emit an ALTER TABLE to rename a table.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><span class="target" id="alembic.operations.Operations.rename_table.params.old_table_name"></span><strong>old_table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.rename_table.params.old_table_name"></a> – old name.</li>
<li><span class="target" id="alembic.operations.Operations.rename_table.params.new_table_name"></span><strong>new_table_name</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.rename_table.params.new_table_name"></a> – new name.</li>
<li><span class="target" id="alembic.operations.Operations.rename_table.params.schema"></span><strong>schema</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.Operations.rename_table.params.schema"></a><p>Optional schema name to operate within.  To control
quoting of the schema outside of the default behavior, use
the SQLAlchemy construct
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.7.0: </span>‘schema’ can now accept a
<code class="xref py py-class docutils literal"><span class="pre">quoted_name</span></code> construct.</p>
</div>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="alembic.operations.BatchOperations">
<em class="property">class </em><code class="descclassname">alembic.operations.</code><code class="descname">BatchOperations</code><span class="sig-paren">(</span><em>migration_context</em>, <em>impl=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations" title="Permalink to this definition"></a></dt>
<dd><p>Modifies the interface <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a> for batch mode.</p>
<p>This basically omits the <code class="docutils literal"><span class="pre">table_name</span></code> and <code class="docutils literal"><span class="pre">schema</span></code> parameters
from associated methods, as these are a given when running under batch
mode.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.batch_alter_table" title="alembic.operations.Operations.batch_alter_table"><code class="xref py py-meth docutils literal"><span class="pre">Operations.batch_alter_table()</span></code></a></p>
</div>
<p>Note that as of 0.8, most of the methods on this class are produced
dynamically using the <a class="reference internal" href="#alembic.operations.Operations.register_operation" title="alembic.operations.Operations.register_operation"><code class="xref py py-meth docutils literal"><span class="pre">Operations.register_operation()</span></code></a>
method.</p>
<p>Construct a new <a class="reference internal" href="#alembic.operations.Operations" title="alembic.operations.Operations"><code class="xref py py-class docutils literal"><span class="pre">Operations</span></code></a></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><span class="target" id="alembic.operations.BatchOperations.params.migration_context"></span><strong>migration_context</strong><a class="paramlink headerlink reference internal" href="#alembic.operations.BatchOperations.params.migration_context"></a> – a <a class="reference internal" href="api/runtime.html#alembic.runtime.migration.MigrationContext" title="alembic.runtime.migration.MigrationContext"><code class="xref py py-class docutils literal"><span class="pre">MigrationContext</span></code></a>
instance.</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="alembic.operations.BatchOperations.add_column">
<code class="descname">add_column</code><span class="sig-paren">(</span><em>column</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.add_column" title="Permalink to this definition"></a></dt>
<dd><p>Issue an “add column” instruction using the current
batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.add_column" title="alembic.operations.Operations.add_column"><code class="xref py py-meth docutils literal"><span class="pre">Operations.add_column()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.alter_column">
<code class="descname">alter_column</code><span class="sig-paren">(</span><em>column_name</em>, <em>nullable=None</em>, <em>server_default=False</em>, <em>new_column_name=None</em>, <em>type_=None</em>, <em>existing_type=None</em>, <em>existing_server_default=False</em>, <em>existing_nullable=None</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.alter_column" title="Permalink to this definition"></a></dt>
<dd><p>Issue an “alter column” instruction using the current
batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.alter_column" title="alembic.operations.Operations.alter_column"><code class="xref py py-meth docutils literal"><span class="pre">Operations.alter_column()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_check_constraint">
<code class="descname">create_check_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>condition</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_check_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create check constraint” instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">source</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_check_constraint" title="alembic.operations.Operations.create_check_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_check_constraint()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_exclude_constraint">
<code class="descname">create_exclude_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>*elements</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_exclude_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create exclude constraint” instruction using the
current batch migration context.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This method is Postgresql specific, and additionally
requires at least SQLAlchemy 1.0.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 0.9.0.</span></p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_exclude_constraint" title="alembic.operations.Operations.create_exclude_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_exclude_constraint()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_foreign_key">
<code class="descname">create_foreign_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>referent_table</em>, <em>local_cols</em>, <em>remote_cols</em>, <em>referent_schema=None</em>, <em>onupdate=None</em>, <em>ondelete=None</em>, <em>deferrable=None</em>, <em>initially=None</em>, <em>match=None</em>, <em>**dialect_kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_foreign_key" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create foreign key” instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">source</span></code> and <code class="docutils literal"><span class="pre">source_schema</span></code>
arguments from the call.</p>
<p>e.g.:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">batch_alter_table</span><span class="p">(</span><span class="s2">&quot;address&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">batch_op</span><span class="p">:</span>
    <span class="n">batch_op</span><span class="o">.</span><span class="n">create_foreign_key</span><span class="p">(</span>
                <span class="s2">&quot;fk_user_address&quot;</span><span class="p">,</span>
                <span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;user_id&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">])</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_foreign_key" title="alembic.operations.Operations.create_foreign_key"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_foreign_key()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
<li>referent -&gt; referent_table</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_index">
<code class="descname">create_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>columns</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_index" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create index” instruction using the
current batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_index" title="alembic.operations.Operations.create_index"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_index()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_primary_key">
<code class="descname">create_primary_key</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>columns</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_primary_key" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create primary key” instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">table_name</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_primary_key" title="alembic.operations.Operations.create_primary_key"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_primary_key()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.create_unique_constraint">
<code class="descname">create_unique_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>columns</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.create_unique_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “create unique constraint” instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">source</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.create_unique_constraint" title="alembic.operations.Operations.create_unique_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.create_unique_constraint()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.drop_column">
<code class="descname">drop_column</code><span class="sig-paren">(</span><em>column_name</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.drop_column" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “drop column” instruction using the current
batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.drop_column" title="alembic.operations.Operations.drop_column"><code class="xref py py-meth docutils literal"><span class="pre">Operations.drop_column()</span></code></a></p>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.drop_constraint">
<code class="descname">drop_constraint</code><span class="sig-paren">(</span><em>constraint_name</em>, <em>type_=None</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.drop_constraint" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “drop constraint” instruction using the
current batch migration context.</p>
<p>The batch form of this call omits the <code class="docutils literal"><span class="pre">table_name</span></code> and <code class="docutils literal"><span class="pre">schema</span></code>
arguments from the call.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.drop_constraint" title="alembic.operations.Operations.drop_constraint"><code class="xref py py-meth docutils literal"><span class="pre">Operations.drop_constraint()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; constraint_name</li>
</ul>
</div>
</dd></dl>

<dl class="method">
<dt id="alembic.operations.BatchOperations.drop_index">
<code class="descname">drop_index</code><span class="sig-paren">(</span><em>index_name</em>, <em>**kw</em><span class="sig-paren">)</span><a class="headerlink" href="#alembic.operations.BatchOperations.drop_index" title="Permalink to this definition"></a></dt>
<dd><p>Issue a “drop index” instruction using the
current batch migration context.</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<p class="last"><a class="reference internal" href="#alembic.operations.Operations.drop_index" title="alembic.operations.Operations.drop_index"><code class="xref py py-meth docutils literal"><span class="pre">Operations.drop_index()</span></code></a></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.8.0: </span>The following positional argument names
have been changed:</p>
<ul class="simple">
<li>name -&gt; index_name</li>
</ul>
</div>
</dd></dl>

</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
  <h4>Previous topic</h4>
  <p class="topless"><a href="branches.html"
                        title="previous chapter">Working with Branches</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="cookbook.html"
                        title="next chapter">Cookbook</a></p>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <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="cookbook.html" title="Cookbook"
             >next</a> |</li>
        <li class="right" >
          <a href="branches.html" title="Working with Branches"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Alembic 0.9.3 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2010-2017, Mike Bayer.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.5.
    </div>
  </body>
</html>