]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add MINVALUE support to Sequence()
authorjakeogh <github.com@v6y.net>
Sat, 27 Jun 2015 08:40:44 +0000 (08:40 +0000)
committerjakeogh <github.com@v6y.net>
Sat, 27 Jun 2015 08:40:44 +0000 (08:40 +0000)
lib/sqlalchemy/engine/interfaces.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/schema.py
test/sql/test_defaults.py

index 73a8b4635172e9e4a9a8c390696dcd9b6a5d97b1..a581448677c273a01ba220e73d184360091a9af3 100644 (file)
@@ -252,7 +252,7 @@ class Dialect(object):
 
         sequence
           a dictionary of the form
-              {'name' : str, 'start' :int, 'increment': int}
+              {'name' : str, 'start' :int, 'increment': int, 'minvalue': int}
 
         Additional column attributes may be present.
         """
@@ -1147,4 +1147,4 @@ class ExceptionContext(object):
 
     .. versionadded:: 1.0.3
 
-    """
\ No newline at end of file
+    """
index e9c3d0efabe2eb81687a0fe0f3af606670be44db..b8cf32dffee7fc9f707e5df2435e5f70c7b0434c 100644 (file)
@@ -2299,6 +2299,8 @@ class DDLCompiler(Compiled):
             text += " INCREMENT BY %d" % create.element.increment
         if create.element.start is not None:
             text += " START WITH %d" % create.element.start
+        if create.element.minvalue is not None:
+            text += " MINVALUE %d" % create.element.minvalue
         return text
 
     def visit_drop_sequence(self, drop):
index a8989627d0b378d0e1bd299f13b9ed68d26de0a6..d49bc2e179faa3dc562de0e7dab17b188028fc5e 100644 (file)
@@ -2040,8 +2040,8 @@ class Sequence(DefaultGenerator):
 
     is_sequence = True
 
-    def __init__(self, name, start=None, increment=None, schema=None,
-                 optional=False, quote=None, metadata=None,
+    def __init__(self, name, start=None, increment=None, minvalue=None,
+                 schema=None, optional=False, quote=None, metadata=None,
                  quote_schema=None,
                  for_update=False):
         """Construct a :class:`.Sequence` object.
@@ -2057,6 +2057,11 @@ class Sequence(DefaultGenerator):
          the database as the value of the "INCREMENT BY" clause.  If ``None``,
          the clause is omitted, which on most platforms indicates an
          increment of 1.
+        :param minvalue: the minimum value of the sequence.  This
+         value is used when the CREATE SEQUENCE command is emitted to
+         the database as the value of the "MINVALUE" clause.  If ``None``,
+         the clause is omitted, which on most platforms indicates a
+         minvalue of 1.
         :param schema: Optional schema name for the sequence, if located
          in a schema other than the default.
         :param optional: boolean value, when ``True``, indicates that this
@@ -2101,6 +2106,7 @@ class Sequence(DefaultGenerator):
         self.name = quoted_name(name, quote)
         self.start = start
         self.increment = increment
+        self.minvalue = minvalue
         self.optional = optional
         if metadata is not None and schema is None and metadata.schema:
             self.schema = schema = metadata.schema
index c154daa22e9952ed828ed0cec6295a9c0fc5fa97..9aebfc010e8b1a42c2ba90bc3b847ee068e2bf10 100644 (file)
@@ -792,6 +792,11 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
             "CREATE SEQUENCE foo_seq INCREMENT BY 2 START WITH 5",
         )
 
+        self.assert_compile(
+            CreateSequence(Sequence('foo_seq', increment=2, start=0, minvalue=0)),
+            "CREATE SEQUENCE foo_seq INCREMENT BY 2 START WITH 0 MINVALUE 0",
+        )
+
         self.assert_compile(
             DropSequence(Sequence('foo_seq')),
             "DROP SEQUENCE foo_seq",