-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Milestone
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
here's a userland monkeypatch that should be easy to adapt straight into the dialect:
# See: http://www.mail-archive.com/sqlalchemy@googlegroups.com/msg20421.html
def patch_postgresql_table_ddl():
import sqlalchemy.dialects.postgresql.base
class MyPGDDLCompiler(sqlalchemy.dialects.postgresql.base.PGDDLCompiler):
def post_create_table(self, table):
"""Build table-level CREATE options like TABLESPACE."""
table_opts = []
inherits = table.kwargs.get('postgresql_inherits')
if inherits is not None:
if not isinstance(inherits, (list, tuple)):
inherits = (inherits,)
table_opts.append(
'\nINHERITS ( ' +
', '.join(isinstance(i, basestring) and i
or self.process(i)
for i
in inherits) +
' )')
on_commit = table.kwargs.get('postgresql_on_commit')
if on_commit:
table_opts.append(
'\nON COMMIT ' +
on_commit.upper().replace('_', ' '))
with_oids = table.kwargs.get('postgresql_with_oids')
if with_oids is not None:
if with_oids:
w = 'WITH'
else:
w = 'WITHOUT'
table_opts.append('\n%s OIDS' % w)
tablespace = table.kwargs.get('postgresql_tablespace')
if tablespace:
table_opts.append('\nTABLESPACE ' + tablespace)
return ''.join(table_opts)
sqlalchemy.dialects.postgresql.base.PGDDLCompiler = MyPGDDLCompiler
sqlalchemy.dialects.postgresql.base.PGDialect.ddl_compiler = MyPGDDLCompiler
Reactions are currently unavailable