You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org> on 2025/03/19 17:52:08 UTC

[PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Antonio-RiveroMartnez opened a new pull request, #32759:
URL: https://github.com/apache/superset/pull/32759

   ### SUMMARY
   With the introduction of FAB 4.6.0 the `ab_permission_view_role` and `ab_user_role` tables are using `ON CASCADE` for deletions, however, this change is only applied in newly created DBs as there's no migration to incorporate such changes into superset.
   
   Without these changes it's not possible to delete Roles due to related data still existing (Integrity error).
   
   This PR is adding a migration to recreate those foreign keys with the proper deletion treatment and thus fixing the role deletion behavior.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   Error:
   ![error](https://github.com/user-attachments/assets/d0c8330e-ad84-41d1-92d9-91a190ce9412)
   
   Fix:
   ![fix](https://github.com/user-attachments/assets/7f928fa6-c393-4c5b-b354-60d428aed18b)
   
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [X] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [X] Migration is atomic, supports rollback & is backwards-compatible
     - [X] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "korbit-ai[bot] (via GitHub)" <gi...@apache.org>.
korbit-ai[bot] commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2003934136


##########
superset/migrations/versions/2025-03-19_17-46_32bf93dfe2a4_add_on_cascade_in_fab_tables.py:
##########
@@ -0,0 +1,102 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from alembic import op
+
+"""Add on cascade to foreign keys in ab_permission_view_role and ab_user_role
+
+Revision ID: 32bf93dfe2a4
+Revises: 94e7a3499973
+Create Date: 2025-03-19 17:46:25.702610
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "32bf93dfe2a4"
+down_revision = "94e7a3499973"
+
+
+def upgrade():
+    op.drop_constraint(
+        "ab_permission_view_role_permission_view_id_fkey",
+        "ab_permission_view_role",
+        type_="foreignkey",
+    )
+    op.drop_constraint(
+        "ab_permission_view_role_role_id_fkey",
+        "ab_permission_view_role",
+        type_="foreignkey",
+    )
+    op.create_foreign_key(
+        None,
+        "ab_permission_view_role",
+        "ab_role",
+        ["role_id"],
+        ["id"],
+        ondelete="CASCADE",
+    )

Review Comment:
   ### Cascading Deletions in RBAC Tables <sub>![category Security](https://img.shields.io/badge/Security-e11d48)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   Adding CASCADE deletion behavior to role-based access control (RBAC) foreign keys could potentially lead to uncontrolled permission changes if a parent record is deleted.
   
   ###### Why this matters
   Automatic cascading deletions in security-related tables may cause unintended removal of permission assignments, potentially creating security gaps or unauthorized access situations if not carefully managed at the application level.
   
   ###### Suggested change βˆ™ *Feature Preview*
   Consider using `ondelete="RESTRICT"` or handling deletions explicitly at the application level with proper security checks:
   ```python
   op.create_foreign_key(
       None,
       "ab_permission_view_role",
       "ab_role",
       ["role_id"],
       ["id"],
       ondelete="RESTRICT",
   )
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/πŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e9ca8294-c6e7-4d43-9312-6ca5734b658e/upvote) [![Incorrect](https://img.shields.io/badge/πŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e9ca8294-c6e7-4d43-9312-6ca5734b658e?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/πŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e9ca8294-c6e7-4d43-9312-6ca5734b658e?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/πŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e9ca8294-c6e7-4d43-9312-6ca5734b658e?what_not_in_standard=true) [![Other](https://img.shields.io/badge/πŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/e9ca8294-c6e7-4d43-9312-6ca5734b658e)
   </details>
   
   <sub>
   
   πŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:2762a7d7-be92-4842-a85c-2d9ac33a10db -->
   
   [](2762a7d7-be92-4842-a85c-2d9ac33a10db)



##########
superset/migrations/versions/2025-03-19_17-46_32bf93dfe2a4_add_on_cascade_in_fab_tables.py:
##########
@@ -0,0 +1,102 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from alembic import op
+
+"""Add on cascade to foreign keys in ab_permission_view_role and ab_user_role
+
+Revision ID: 32bf93dfe2a4
+Revises: 94e7a3499973
+Create Date: 2025-03-19 17:46:25.702610
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = "32bf93dfe2a4"
+down_revision = "94e7a3499973"
+
+
+def upgrade():
+    op.drop_constraint(
+        "ab_permission_view_role_permission_view_id_fkey",
+        "ab_permission_view_role",
+        type_="foreignkey",
+    )
+    op.drop_constraint(
+        "ab_permission_view_role_role_id_fkey",
+        "ab_permission_view_role",
+        type_="foreignkey",
+    )
+    op.create_foreign_key(
+        None,
+        "ab_permission_view_role",
+        "ab_role",
+        ["role_id"],
+        ["id"],
+        ondelete="CASCADE",
+    )
+    op.create_foreign_key(
+        None,
+        "ab_permission_view_role",
+        "ab_permission_view",
+        ["permission_view_id"],
+        ["id"],
+        ondelete="CASCADE",
+    )
+    op.drop_constraint("ab_user_role_user_id_fkey", "ab_user_role", type_="foreignkey")
+    op.drop_constraint("ab_user_role_role_id_fkey", "ab_user_role", type_="foreignkey")
+    op.create_foreign_key(
+        None, "ab_user_role", "ab_user", ["user_id"], ["id"], ondelete="CASCADE"
+    )
+    op.create_foreign_key(
+        None, "ab_user_role", "ab_role", ["role_id"], ["id"], ondelete="CASCADE"
+    )
+
+
+def downgrade():
+    op.drop_constraint("ab_user_role_role_id_fkey", "ab_user_role", type_="foreignkey")
+    op.drop_constraint("ab_user_role_user_id_fkey", "ab_user_role", type_="foreignkey")
+    op.create_foreign_key(
+        "ab_user_role_role_id_fkey", "ab_user_role", "ab_role", ["role_id"], ["id"]
+    )

Review Comment:
   ### Incorrect constraint drop order in downgrade <sub>![category Functionality](https://img.shields.io/badge/Functionality-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The downgrade function drops constraints in a different order than they were created in the upgrade function, which could lead to foreign key violations during the downgrade process.
   
   ###### Why this matters
   If there are existing records in these tables, dropping constraints in a different order than they were created might cause the migration to fail due to referential integrity issues.
   
   ###### Suggested change βˆ™ *Feature Preview*
   Modify the downgrade function to drop and create constraints in the reverse order of the upgrade function:
   ```python
   def downgrade():
       # First handle ab_permission_view_role constraints
       op.drop_constraint(
           "ab_permission_view_role_permission_view_id_fkey",
           "ab_permission_view_role",
           type_="foreignkey",
       )
       op.drop_constraint(
           "ab_permission_view_role_role_id_fkey",
           "ab_permission_view_role",
           type_="foreignkey",
       )
       op.create_foreign_key(
           "ab_permission_view_role_permission_view_id_fkey",
           "ab_permission_view_role",
           "ab_permission_view",
           ["permission_view_id"],
           ["id"],
       )
       op.create_foreign_key(
           "ab_permission_view_role_role_id_fkey",
           "ab_permission_view_role",
           "ab_role",
           ["role_id"],
           ["id"],
       )
   
       # Then handle ab_user_role constraints
       op.drop_constraint("ab_user_role_user_id_fkey", "ab_user_role", type_="foreignkey")
       op.drop_constraint("ab_user_role_role_id_fkey", "ab_user_role", type_="foreignkey")
       op.create_foreign_key(
           "ab_user_role_user_id_fkey", "ab_user_role", "ab_user", ["user_id"], ["id"]
       )
       op.create_foreign_key(
           "ab_user_role_role_id_fkey", "ab_user_role", "ab_role", ["role_id"], ["id"]
       )
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/πŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/22672018-5df6-41e5-b0a6-c9259ee155bb/upvote) [![Incorrect](https://img.shields.io/badge/πŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/22672018-5df6-41e5-b0a6-c9259ee155bb?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/πŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/22672018-5df6-41e5-b0a6-c9259ee155bb?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/πŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/22672018-5df6-41e5-b0a6-c9259ee155bb?what_not_in_standard=true) [![Other](https://img.shields.io/badge/πŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/22672018-5df6-41e5-b0a6-c9259ee155bb)
   </details>
   
   <sub>
   
   πŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:5dd48da8-a6e0-4e84-b6cd-bd920fdef4c7 -->
   
   [](5dd48da8-a6e0-4e84-b6cd-bd920fdef4c7)



##########
superset/migrations/versions/2025-03-19_17-46_32bf93dfe2a4_add_on_cascade_in_fab_tables.py:
##########
@@ -0,0 +1,102 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from alembic import op
+
+"""Add on cascade to foreign keys in ab_permission_view_role and ab_user_role
+
+Revision ID: 32bf93dfe2a4
+Revises: 94e7a3499973
+Create Date: 2025-03-19 17:46:25.702610
+
+"""

Review Comment:
   ### Missing Migration Purpose and Impact <sub>![category Documentation](https://img.shields.io/badge/Documentation-7c3aed)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The migration docstring does not explain the reasoning behind adding CASCADE constraints or its implications.
   
   ###### Why this matters
   Without understanding the purpose and impact of CASCADE constraints, future maintainers might accidentally modify or remove them, potentially leading to data integrity issues.
   
   ###### Suggested change βˆ™ *Feature Preview*
   """Add on cascade to foreign keys in ab_permission_view_role and ab_user_role
   
   Revision ID: 32bf93dfe2a4
   Revises: 94e7a3499973
   Create Date: 2025-03-19 17:46:25.702610
   
   Adds CASCADE constraints to ensure automatic cleanup of related permission_view_role
   and user_role entries when parent records are deleted, preventing orphaned records
   and maintaining referential integrity.
   """
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice Catch](https://img.shields.io/badge/πŸ‘%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/38d8b5d2-becc-458b-b33b-ab5ba6ff33c6/upvote) [![Incorrect](https://img.shields.io/badge/πŸ‘Ž%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/38d8b5d2-becc-458b-b33b-ab5ba6ff33c6?what_not_true=true)  [![Not in Scope](https://img.shields.io/badge/πŸ‘Ž%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/38d8b5d2-becc-458b-b33b-ab5ba6ff33c6?what_out_of_scope=true) [![Not in coding standard](https://img.shields.io/badge/πŸ‘Ž%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/38d8b5d2-becc-458b-b33b-ab5ba6ff33c6?what_not_in_standard=true) [![Other](https://img.shields.io/badge/πŸ‘Ž%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/38d8b5d2-becc-458b-b33b-ab5ba6ff33c6)
   </details>
   
   <sub>
   
   πŸ’¬ Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:3e0f14e4-29f0-4287-af69-c96066d71e54 -->
   
   [](3e0f14e4-29f0-4287-af69-c96066d71e54)



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004018962


##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   Sounds good, will also have to add one for creating the keys since `sqlite` doesn't like constraint AT ALL :( or just use the `batch_alter_table` but since we're working with the utils it might not hurt



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004204579


##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +417,57 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def create_fks_for_table(
+    constraint_name: str,

Review Comment:
   Could you also rename to `fk_name` here? Constraint is more generic term and can be a foreign key, unique key, not null, etc.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004018962


##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   Sounds good, will also have to add one for creating the keys since `sqllite` doesn't like constraint AT ALL :( 



##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   Sounds good, will also have to add one for creating the keys since `sqlite` doesn't like constraint AT ALL :( 



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004013774


##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   I think it would be better in terms of simplicity and to reduce lines of code to modify the original `drop_fks_for_table` to accept an optional list of foreign key names. You can make it clear in the docstring that if a list is not supplied, all foreign keys will be deleted.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004201972


##########
superset/migrations/shared/utils.py:
##########
@@ -207,12 +211,19 @@ def drop_fks_for_table(table_name: str) -> None:
         return  # sqlite doesn't like constraints
 
     if has_table(table_name):
-        foreign_keys = inspector.get_foreign_keys(table_name)
-        for fk in foreign_keys:
+        existing_fks = {fk["name"] for fk in inspector.get_foreign_keys(table_name)}
+
+        # What to delete based on whether the list was passed
+        if constraint_names is not None:
+            constraint_names = list(set(constraint_names) & existing_fks)
+        else:
+            constraint_names = list(existing_fks)
+
+        for fk_name in constraint_names:

Review Comment:
   ```suggestion
           if fk_names is not None:
               fk_names = list(set(fk_names) & existing_fks)
           else:
               fk_names = list(existing_fks)
   
           for fk_name in fk_names:
   ```



##########
superset/migrations/shared/utils.py:
##########
@@ -193,12 +193,16 @@ def has_table(table_name: str) -> bool:
     return table_exists
 
 
-def drop_fks_for_table(table_name: str) -> None:
+def drop_fks_for_table(
+    table_name: str, constraint_names: Optional[list[str]] = None

Review Comment:
   ```suggestion
       table_name: str, fk_names: list[str] | None = None
   ```



##########
superset/migrations/shared/utils.py:
##########
@@ -193,12 +193,16 @@ def has_table(table_name: str) -> bool:
     return table_exists
 
 
-def drop_fks_for_table(table_name: str) -> None:
+def drop_fks_for_table(
+    table_name: str, constraint_names: Optional[list[str]] = None
+) -> None:
     """
-    Drop all foreign key constraints for a table if it exist and the database
-    is not sqlite.
+    Drop specific or all foreign key constraints for a table
+    if they exist and the database is not sqlite.
 
-    :param table_name: The table name to drop foreign key constraints for
+    :param table_name: The table name to drop foreign key constraints from
+    :param constraint_names: Optional list of specific foreign key names to drop.

Review Comment:
   ```suggestion
       :param fk_names: Optional list of specific foreign key names to drop.
   ```



##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +417,57 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def create_fks_for_table(
+    constraint_name: str,

Review Comment:
   Could you also rename to `fk_name` here? Constraint is more generic and can be a foreign key, unique key, not null, etc.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004193875


##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   Ok @michael-s-molina the PR was updated to use the utils now. Thanks



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #32759:
URL: https://github.com/apache/superset/pull/32759#discussion_r2004013774


##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   I think it would be better in terms of simplicity and to reduce lines of code to modify the original drop_fks_for_table to accept an optional list of foreign key names. You can make it clear in the docs string that if a list is not supplied, all foreign keys will be deleted.



##########
superset/migrations/shared/utils.py:
##########
@@ -406,3 +406,33 @@ def drop_index(table_name: str, index_name: str) -> None:
     )
 
     op.drop_index(table_name=table_name, index_name=index_name)
+
+
+def drop_fks_for_table_by_names(table_name: str, constraint_names: list[str]) -> None:

Review Comment:
   I think it would be better in terms of simplicity and to reduce lines of code to modify the original `drop_fks_for_table` to accept an optional list of foreign key names. You can make it clear in the docs string that if a list is not supplied, all foreign keys will be deleted.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "Antonio-RiveroMartnez (via GitHub)" <gi...@apache.org>.
Antonio-RiveroMartnez merged PR #32759:
URL: https://github.com/apache/superset/pull/32759


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(migrations): fix foreign keys to match FAB 4.6.0 tables [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #32759:
URL: https://github.com/apache/superset/pull/32759#issuecomment-2737562025

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/32759?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   All modified and coverable lines are covered by tests :white_check_mark:
   > Project coverage is 65.78%. Comparing base [(`76d897e`)](https://app.codecov.io/gh/apache/superset/commit/76d897eaa2f9e137102bc194c2e3109c29d0348f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`afde445`)](https://app.codecov.io/gh/apache/superset/commit/afde445d0f700779ca18ded2dec59ecee537e457?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 1653 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #32759      +/-   ##
   ==========================================
   + Coverage   60.48%   65.78%   +5.29%     
   ==========================================
     Files        1931      549    -1382     
     Lines       76236    39441   -36795     
     Branches     8568        0    -8568     
   ==========================================
   - Hits        46114    25947   -20167     
   + Misses      28017    13494   -14523     
   + Partials     2105        0    -2105     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/32759/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ” | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/32759/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `48.43% <ΓΈ> (-0.72%)` | :arrow_down: |
   | [javascript](https://app.codecov.io/gh/apache/superset/pull/32759/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/32759/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.92% <ΓΈ> (-0.88%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/32759/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `65.78% <ΓΈ> (+2.28%)` | :arrow_up: |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/32759/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `61.40% <ΓΈ> (+3.76%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/32759?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   <details><summary>πŸš€ New features to boost your workflow: </summary>
   
   - ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - πŸ“¦ [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org