]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Dialect option `postgresql_concurrently` to `Index` construct.
authorIuri de Silvio <iurisilvio@gmail.com>
Thu, 26 Feb 2015 00:05:31 +0000 (21:05 -0300)
committerIuri de Silvio <iurisilvio@gmail.com>
Thu, 26 Feb 2015 00:05:31 +0000 (21:05 -0300)
lib/sqlalchemy/dialects/postgresql/base.py
test/dialect/postgresql/test_compiler.py

index 1935d0cadcf4b6903cf788c446f6511ed0411421..c819f36c3d160b3b2e06ad68185379397ba47d4f 100644 (file)
@@ -1459,7 +1459,13 @@ class PGDDLCompiler(compiler.DDLCompiler):
         text = "CREATE "
         if index.unique:
             text += "UNIQUE "
-        text += "INDEX %s ON %s " % (
+        text += "INDEX "
+
+        concurrently = index.dialect_options['postgresql']['concurrently']
+        if concurrently:
+            text += "CONCURRENTLY "
+
+        text += "%s ON %s " % (
             self._prepared_index_name(index,
                                       include_schema=False),
             preparer.format_table(index.table)
@@ -1812,7 +1818,8 @@ class PGDialect(default.DefaultDialect):
         (schema.Index, {
             "using": False,
             "where": None,
-            "ops": {}
+            "ops": {},
+            "concurrently": False,
         }),
         (schema.Table, {
             "ignore_search_path": False,
index 5717df9f76f314c000039aebeebe699b6bfcf9e9..aa3f80fdce0fbff312a400d5b09c04325e845e49 100644 (file)
@@ -389,6 +389,16 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
             "CREATE INDEX test_idx1 ON testtbl ((data + 5))"
         )
 
+    def test_create_index_concurrently(self):
+        m = MetaData()
+        tbl = Table('testtbl', m, Column('data', Integer))
+
+        idx1 = Index('test_idx1', tbl.c.data, postgresql_concurrently=True)
+        self.assert_compile(
+            schema.CreateIndex(idx1),
+            "CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data)"
+        )
+
     def test_exclude_constraint_min(self):
         m = MetaData()
         tbl = Table('testtbl', m,