diff options
author | Frazer McLean <frazer@frazermclean.co.uk> | 2016-06-11 21:47:33 +0200 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-03-17 14:02:15 -0400 |
commit | fadb8d61babb76ef7bdbc98279096a8900c7328d (patch) | |
tree | 2e6113d9c9ec665ed7785e4d7273b8830520e7af /lib/sqlalchemy/sql/ddl.py | |
parent | 63a7b2d2d9402b06f9bc7745eed2d98ae9f8b11c (diff) | |
download | sqlalchemy-fadb8d61babb76ef7bdbc98279096a8900c7328d.tar.gz |
Implement comments for tables, columns
Added support for SQL comments on :class:`.Table` and :class:`.Column`
objects, via the new :paramref:`.Table.comment` and
:paramref:`.Column.comment` arguments. The comments are included
as part of DDL on table creation, either inline or via an appropriate
ALTER statement, and are also reflected back within table reflection,
as well as via the :class:`.Inspector`. Supported backends currently
include MySQL, Postgresql, and Oracle.
Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com>
Fixes: #1546
Change-Id: Ib90683850805a2b4ee198e420dc294f32f15d35d
Diffstat (limited to 'lib/sqlalchemy/sql/ddl.py')
-rw-r--r-- | lib/sqlalchemy/sql/ddl.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py index 5463afe99..74c424bff 100644 --- a/lib/sqlalchemy/sql/ddl.py +++ b/lib/sqlalchemy/sql/ddl.py @@ -661,6 +661,30 @@ class DropConstraint(_CreateDropBase): self._create_rule_disable) +class SetTableComment(_CreateDropBase): + """Represent a COMMENT ON TABLE IS statement.""" + + __visit_name__ = "set_table_comment" + + +class DropTableComment(_CreateDropBase): + """Represent a COMMENT ON TABLE IS NULL statement.""" + + __visit_name__ = "drop_table_comment" + + +class SetColumnComment(_CreateDropBase): + """Represent a COMMENT ON COLUMN IS statement.""" + + __visit_name__ = "set_column_comment" + + +class DropColumnComment(_CreateDropBase): + """Represent a COMMENT ON COLUMN IS NULL statement.""" + + __visit_name__ = "drop_column_comment" + + class DDLBase(SchemaVisitor): def __init__(self, connection): self.connection = connection @@ -771,6 +795,14 @@ class SchemaGenerator(DDLBase): for index in table.indexes: self.traverse_single(index) + if self.dialect.supports_comments and not self.dialect.inline_comments: + if table.comment is not None: + self.connection.execute(SetTableComment(table)) + + for column in table.columns: + if column.comment is not None: + self.connection.execute(SetColumnComment(column)) + table.dispatch.after_create( table, self.connection, checkfirst=self.checkfirst, |