File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
src/sqlalchemy_declarative_extensions/dialects/postgresql Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,9 @@ def to_sql_create(self, replace=False):
195195 components .append (quote_name (self .execute ) + f"({ ',' .join (args_quoted )} )" )
196196 return " " .join (components ) + ";"
197197
198+ def to_sql_drop (self ):
199+ return f"DROP TRIGGER { quote_name (self .name )} ON { quote_name (self .on )} ;"
200+
198201 def to_sql_update (self , connection : Connection | None = None ):
199202 if connection is not None :
200203 assert connection .dialect .server_version_info
Original file line number Diff line number Diff line change @@ -25,13 +25,20 @@ class Foo(Base):
2525 id = Column (types .Integer (), primary_key = True )
2626
2727
28+ class TableWithSpecialName (Base ):
29+ __tablename__ = "user" # This name will trip up unquoted identifiers
30+
31+ id = Column (types .Integer (), primary_key = True )
32+
33+
2834register_sqlalchemy_events (Base .metadata , triggers = True )
2935
3036pg = create_postgres_fixture (engine_kwargs = {"echo" : True }, session = True )
3137
3238
3339def test_drop (pg ):
3440 pg .execute (text ("CREATE TABLE foo (id integer primary key);" ))
41+ pg .execute (text ('CREATE TABLE "user" (id integer primary key);' ))
3542 pg .execute (
3643 text (
3744 """
@@ -49,17 +56,28 @@ def test_drop(pg):
4956 "WHEN (pg_trigger_depth() < 1) EXECUTE PROCEDURE gimme();"
5057 )
5158 )
59+ pg .execute (
60+ text (
61+ 'CREATE TRIGGER "Quoted Name" AFTER INSERT ON "user" FOR EACH ROW '
62+ "WHEN (pg_trigger_depth() < 1) EXECUTE PROCEDURE gimme();"
63+ )
64+ )
65+
5266 pg .commit ()
5367
5468 Base .metadata .create_all (bind = pg .connection ())
5569 pg .commit ()
5670
5771 pg .add (Foo (id = 5 ))
72+ pg .add (TableWithSpecialName (id = 6 ))
5873 pg .commit ()
5974
6075 result = [r .id for r in pg .query (Foo ).all ()]
6176 assert result == [5 ]
6277
78+ quoted_result = [r .id for r in pg .query (TableWithSpecialName ).all ()]
79+ assert quoted_result == [6 ]
80+
6381 connection = pg .connection ()
6482 diff = compare_triggers (connection , Base .metadata .info ["triggers" ])
6583 assert diff == []
You can’t perform that action at this time.
0 commit comments