Hi!

In production server, in our product we use postgresql as db engine,
than supports schema name as sqlalchmy's feature. But we have unit-
tests, that must passed without postgresql server.

In code we use schema names and foreign keys. There are a lot of
topics with "sqlite does not support foreign keys to external
database".

I read that Michael Bayer sad do not use ForeignKey() with sqlite. But
we must use it for postgresql.

The question is: may be add some argument for sqlite dialect, that
suppress foreign key constraint?

See the patch for example:


diff -ru sqlalchemy.orig/dialects/sqlite/base.py sqlalchemy/dialects/
sqlite/base.py
--- sqlalchemy.orig/dialects/sqlite/base.py     2010-11-12
17:13:23.000000000 +0300
+++ sqlalchemy/dialects/sqlite/base.py  2010-11-12 17:20:02.000000000
+0300
@@ -272,6 +272,13 @@
                     visit_primary_key_constraint(constraint)


+    def visit_foreign_key_constraint(self, constraint):
+        # Suppress foreign key constraint if configured
+        if getattr(self.dialect, 'suppress_fk_constraint', False):
+            return None
+        return super(SQLiteDDLCompiler, self).\
+                    visit_foreign_key_constraint(constraint)
+
     def visit_create_index(self, create):
         index = create.element
         preparer = self.preparer
@@ -342,7 +349,8 @@
     supports_cast = True
     supports_default_values = True

-    def __init__(self, isolation_level=None, native_datetime=False,
**kwargs):
+    def __init__(self, isolation_level=None, native_datetime=False,
+
suppress_fk_constraint=False, **kwargs):
         default.DefaultDialect.__init__(self, **kwargs)
         if isolation_level and isolation_level not in
('SERIALIZABLE',
                 'READ UNCOMMITTED'):
@@ -350,6 +358,8 @@
                 "Valid isolation levels for sqlite are 'SERIALIZABLE'
and "
                 "'READ UNCOMMITTED'.")
         self.isolation_level = isolation_level
+
+        self.suppress_fk_constraint = suppress_fk_constraint

         # this flag used by pysqlite dialect, and perhaps others in
the
         # future, to indicate the driver is handling date/timestamp

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to