From: jakeogh Date: Sat, 27 Jun 2015 08:40:44 +0000 (+0000) Subject: add MINVALUE support to Sequence() X-Git-Tag: rel_1_0_7~14^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f31c288b65281511338c518bdf7fbe78c985af58;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git add MINVALUE support to Sequence() --- diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 73a8b46351..a581448677 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -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 + """ diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e9c3d0efab..b8cf32dffe 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -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): diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py index a8989627d0..d49bc2e179 100644 --- a/lib/sqlalchemy/sql/schema.py +++ b/lib/sqlalchemy/sql/schema.py @@ -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 diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py index c154daa22e..9aebfc010e 100644 --- a/test/sql/test_defaults.py +++ b/test/sql/test_defaults.py @@ -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",