jedcunningham commented on code in PR #39246:
URL: https://github.com/apache/airflow/pull/39246#discussion_r1578971118


##########
airflow/migrations/versions/0140_2_9_0_update_trigger_kwargs_type.py:
##########
@@ -38,13 +41,43 @@
 airflow_version = "2.9.0"
 
 
+def get_session() -> sa.orm.Session:
+    conn = op.get_bind()
+    sessionmaker = sa.orm.sessionmaker()
+    return sessionmaker(bind=conn)
+
 def upgrade():
-    """Update trigger kwargs type to string"""
+    """Update trigger kwargs type to string and encrypt"""
     with op.batch_alter_table("trigger") as batch_op:
         batch_op.alter_column("kwargs", type_=sa.Text(), )
 
+    if not context.is_offline_mode():
+        session = get_session()
+        try:
+            for trigger in session.query(Trigger):
+                trigger.kwargs = trigger.kwargs
+            session.commit()
+        finally:
+            session.close()
+
 
 def downgrade():
-    """Unapply update trigger kwargs type to string"""
+    """Unapply update trigger kwargs type to string and encrypt"""
+    if context.is_offline_mode():
+        print(dedent("""
+        ------------
+        --  WARNING: Unable to decrypt trigger kwargs automatically in offline 
mode!

Review Comment:
   This is what it looks like in the generated sql:
   
   ```
   BEGIN;
   
   -- Running downgrade 1949afb29106 -> ee1467d4aa35
   
   
   ------------
   --  WARNING: Unable to decrypt trigger kwargs automatically in offline mode!
   --  If any trigger rows exist when you do an offline downgrade, the 
migration will fail.
   ------------
   
   ALTER TABLE trigger ALTER COLUMN kwargs TYPE JSON USING kwargs::json;
   
   UPDATE alembic_version SET version_num='ee1467d4aa35' WHERE 
alembic_version.version_num = '1949afb29106';
   
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to