From 7ac570f4e94fa70b8b428d6f3050d2bc17f68d35 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 22 Dec 2012 10:54:29 -0600 Subject: [PATCH] auth.signature.is_active is notnull and migration will set default value --- VERSION | 2 +- gluon/dal.py | 17 +++++++---------- gluon/tools.py | 1 + 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index f1b515dc..90d0d982 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.1-alpha.1+timestamp.2012.12.22.10.19.08 +Version 2.4.1-alpha.1+timestamp.2012.12.22.10.53.49 diff --git a/gluon/dal.py b/gluon/dal.py index 8ada281f..3119a051 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -859,7 +859,7 @@ class BaseAdapter(ConnectionPool): type=str(field_type), sql=ftype) - if isinstance(field.default,(str,int,float)): + if field.notnull and not field.default is None: # Caveat: sql_fields and sql_fields_aux # differ for default values. # sql_fields is used to trigger migrations and sql_fields_aux @@ -867,7 +867,7 @@ class BaseAdapter(ConnectionPool): # The reason is that we do not want to trigger # a migration simply because a default value changes. not_null = self.NOT_NULL(field.default, field_type) - ftype = ftype.replace('NOT NULL', not_null) + ftype = ftype.replace('NOT NULL', not_null) sql_fields_aux[field_name] = dict(sql=ftype) # Postgres - PostGIS: # geometry fields are added after the table has been created, not now @@ -995,10 +995,7 @@ class BaseAdapter(ConnectionPool): for key in sql_fields_old: if not key in keys: keys.append(key) - if self.dbengine == 'mssql': - new_add = '; ALTER TABLE %s ADD ' % tablename - else: - new_add = ', ADD ' + new_add = self.concat_add(tablename) metadata_change = False sql_fields_current = copy.copy(sql_fields_old) @@ -1690,7 +1687,7 @@ class BaseAdapter(ConnectionPool): def rollback_prepared(self, key): if self.connection: self.connection.rollback() - def concat_add(self, table): + def concat_add(self, tablename): return ', ADD ' def constraint_name(self, table, fieldname): @@ -2359,9 +2356,6 @@ class MySQLAdapter(BaseAdapter): def rollback_prepared(self,key): self.execute("XA ROLLBACK;") - def concat_add(self,table): - return '; ALTER TABLE %s ADD ' % table - REGEX_URI = re.compile('^(?P[^:@]+)(\:(?P[^@]*))?@(?P[^\:/]+)(\:(?P[0-9]+))?/(?P[^?]+)(\?set_encoding=(?P\w+))?$') def __init__(self,db,uri,pool_size=0,folder=None,db_codec ='UTF-8', @@ -2958,6 +2952,9 @@ class MSSQLAdapter(BaseAdapter): 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } + def concat_add(self,tablename): + return '; ALTER TABLE %s ADD ' % tablename + def varquote(self,name): return varquote_aux(name,'[%s]') diff --git a/gluon/tools.py b/gluon/tools.py index abdc61ba..b4a2a5ec 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -1422,6 +1422,7 @@ class Auth(object): self.signature = db.Table( self.db, 'auth_signature', Field('is_active', 'boolean', + notnull=True, default=True, readable=False, writable=False, label=T('Is Active')),