You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2023/09/01 23:02:24 UTC

[GitHub] [superset] eschutho opened a new pull request, #25164: DRAFT: change constraint alters to non blocking

eschutho opened a new pull request, #25164:
URL: https://github.com/apache/superset/pull/25164

   <!---
   Please write the PR title following the conventions at https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   Testing to see if this will be a more performant/non blocking migration 
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### 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
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] 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


[GitHub] [superset] eschutho closed pull request #25164: fix: change constraint alters to non blocking for postgres

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho closed pull request #25164: fix: change constraint alters to non blocking for postgres
URL: https://github.com/apache/superset/pull/25164


-- 
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


[GitHub] [superset] michael-s-molina commented on pull request #25164: fix: change constraint alters to non blocking for postgres

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

   @eschutho Thank you for the improvement. I'll run this in our staging environment to test the change. Assuming it works, https://github.com/apache/superset/pull/24939, https://github.com/apache/superset/pull/24938, https://github.com/apache/superset/pull/24628, https://github.com/apache/superset/pull/24488 all add `ON DELETE CASCADE` constraints. Can you extract the non-blocking logic from the migrations and move it to [migrations/shared/constraints.py](https://github.com/apache/superset/blob/master/superset/migrations/shared/constraints.py)? Can you also use `batch_alter_table` like [redefine](https://github.com/apache/superset/blob/d0305445b2782264834821c3f1276d74c1b5f99f/superset/migrations/shared/constraints.py#L23) does?


-- 
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


[GitHub] [superset] michael-s-molina commented on pull request #25164: fix: change constraint alters to non blocking for postgres

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

   @eschutho There's also a typo in one script name:
   
   `__dd_on_delete_cascade_for_embedded_dashboards`
   
   I think you meant `_add_on_delete_cascade_for_embedded_dashboards`


-- 
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


[GitHub] [superset] eschutho commented on pull request #25164: fix: change constraint alters to non blocking for postgres

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on PR #25164:
URL: https://github.com/apache/superset/pull/25164#issuecomment-1707293718

   thanks for the review @michael-s-molina. Since this is only improving Postgres, I'm thinking of just closing the Pr and running it locally unless others feel there's a benefit to the codebase for others. 


-- 
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


[GitHub] [superset] eschutho commented on a diff in pull request #25164: DRAFT: change constraint alters to non blocking for postgres

Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho commented on code in PR #25164:
URL: https://github.com/apache/superset/pull/25164#discussion_r1313659916


##########
superset/migrations/versions/2023-08-09_15-39_4448fa6deeb1__dd_on_delete_cascade_for_embedded_dashboards.py.py:
##########
@@ -40,9 +44,50 @@
 
 def upgrade():
     for foreign_key in foreign_keys:
-        redefine(foreign_key, on_delete="CASCADE")
+        bind = op.get_bind()
+        insp = Inspector.from_engine(bind)
+        db_dialect = bind.engine.url.drivername
+
+        if db_dialect == "postgresql":
+            if constraint := generic_find_fk_constraint_name(
+                table=foreign_key.table,
+                columns=set(foreign_key.remote_cols),
+                referenced=foreign_key.referent_table,
+                insp=insp,
+            ):
+                # rename the constraint so that we can drop it later- non-blocking
+                # this only works on postgres
+                op.execute(
+                    f"ALTER TABLE {foreign_key.table} RENAME CONSTRAINT {constraint} TO {foreign_key.constraint_name}_old"
+                )
+
+            # create the new constraint- uses a non-blocking ALTER TABLE Not Valid property
+            op.create_foreign_key(
+                constraint_name=foreign_key.constraint_name,
+                source_table=foreign_key.table,
+                referent_table=foreign_key.referent_table,
+                local_cols=foreign_key.local_cols,
+                remote_cols=foreign_key.remote_cols,
+                ondelete="CASCADE",
+                postgresql_not_valid=True,
+            )
+
+            # validate the constraint- non-blocking
+            op.execute(
+                f"ALTER TABLE {foreign_key.table} VALIDATE CONSTRAINT {foreign_key.constraint_name}"
+            )
+
+            # drop the old constraint which isn't needed anymore- non-blocking
+            if constraint:
+                op.drop_constraint(
+                    f"{foreign_key.constraint_name}_old",
+                    foreign_key.table,
+                    type_="foreignkey",
+                )
+        else:
+            redefine(foreign_key, on_delete="CASCADE")
 
 
 def downgrade():
     for foreign_key in foreign_keys:
-        redefine(foreign_key)
+        pass

Review Comment:
   todo



-- 
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