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

index a581448677c273a01ba220e73d184360091a9af3..1779f6d48607c0fdd2b40a87a7f3051bba1dad21 100644 (file)
@@ -252,7 +252,7 @@ class Dialect(object):
 
         sequence
           a dictionary of the form
-              {'name' : str, 'start' :int, 'increment': int, 'minvalue': int}
+              {'name' : str, 'start' :int, 'increment': int, 'minvalue': int, 'maxvalue': int}
 
         Additional column attributes may be present.
         """
index b8cf32dffee7fc9f707e5df2435e5f70c7b0434c..b3fee60ec0f28d2d8125267369436f7546489f41 100644 (file)
@@ -2301,6 +2301,8 @@ class DDLCompiler(Compiled):
             text += " START WITH %d" % create.element.start
         if create.element.minvalue is not None:
             text += " MINVALUE %d" % create.element.minvalue
+        if create.element.maxvalue is not None:
+            text += " MAXVALUE %d" % create.element.maxvalue
         return text
 
     def visit_drop_sequence(self, drop):
index d49bc2e179faa3dc562de0e7dab17b188028fc5e..ef84d268087b733532cc7fa7c709d3fe17e8e2cb 100644 (file)
@@ -2041,8 +2041,8 @@ class Sequence(DefaultGenerator):
     is_sequence = True
 
     def __init__(self, name, start=None, increment=None, minvalue=None,
-                 schema=None, optional=False, quote=None, metadata=None,
-                 quote_schema=None,
+                 maxvalue=None, schema=None, optional=False, quote=None,
+                 metadata=None, quote_schema=None,
                  for_update=False):
         """Construct a :class:`.Sequence` object.
 
@@ -2061,7 +2061,14 @@ class Sequence(DefaultGenerator):
          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.
+         minvalue of 1 and -2^63-1 for ascending and descending sequences,
+         respectively.
+        :param maxvalue: the maximum value of the sequence.  This
+         value is used when the CREATE SEQUENCE command is emitted to
+         the database as the value of the "MAXVALUE" clause.  If ``None``,
+         the clause is omitted, which on most platforms indicates a
+         maxvalue of 2^63-1 and -1 for ascending and descending sequences,
+         respectively.
         :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
index 9aebfc010e8b1a42c2ba90bc3b847ee068e2bf10..b218aa53f934ef032474b0f0295045947afad1a8 100644 (file)
@@ -793,10 +793,17 @@ class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
         )
 
         self.assert_compile(
-            CreateSequence(Sequence('foo_seq', increment=2, start=0, minvalue=0)),
+            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(
+            CreateSequence(Sequence(
+                            'foo_seq', increment=2, start=1, maxvalue=5)),
+            "CREATE SEQUENCE foo_seq INCREMENT BY 2 START WITH 0 MAXVALUE 5",
+        )
+
         self.assert_compile(
             DropSequence(Sequence('foo_seq')),
             "DROP SEQUENCE foo_seq",