Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add and use UUIDMixin for most models #30398

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Sep 26, 2024

Proof of concept for adding uuid to most table. This is just a DRAFT for now but could be used to sprinkly uuids to all models

Needed to roll out:

  • check uuids are populated properly, write a script that loops through and assigns some if needed (?)
  • apply to all relevant models

@@ -102,7 +102,7 @@ class KeyValue(Model): # pylint: disable=too-few-public-methods
value = Column(utils.MediumText(), nullable=False)


class CssTemplate(Model, AuditMixinNullable):
class CssTemplate(Model, AuditMixinNullable, UUIDMixin):
Copy link
Member

@villebro villebro Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already incorrect, but in general it's idiomatic to place the mixin before the main class to ensure correct MRO (otherwise functionality in the main class may overwrite functionality in the mixin):

Suggested change
class CssTemplate(Model, AuditMixinNullable, UUIDMixin):
class CssTemplate(AuditMixinNullable, UUIDMixin, Model):

superset/models/core.py Outdated Show resolved Hide resolved
superset/models/helpers.py Show resolved Hide resolved
@github-actions github-actions bot added i18n Namespace | Anything related to localization api Related to the REST API doc Namespace | Anything related to documentation embedded plugins dependencies:npm github_actions Pull requests that update GitHub Actions code packages i18n:brazilian labels Nov 27, 2024
@github-actions github-actions bot removed i18n Namespace | Anything related to localization api Related to the REST API doc Namespace | Anything related to documentation embedded plugins dependencies:npm github_actions Pull requests that update GitHub Actions code packages i18n:brazilian labels Nov 27, 2024
@mistercrunch mistercrunch marked this pull request as ready for review November 27, 2024 00:35
@dosubot dosubot bot added the change:backend Requires changing the backend label Nov 27, 2024
@mistercrunch
Copy link
Member Author

Setting this as ready for review as we may want to repeat this pattern, and having UuidMixin around for use is a win



def upgrade():
op.add_column(
Copy link
Member

@michael-s-molina michael-s-molina Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mistercrunch could you make sure the migration checks if the column exists when upgrading and downgrading?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to create a utility for adding/removing columns that always performs this check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem like a decent idea, though wondering how to best to this. Not sure if false-negative or swallowed errors on db migrations is a thing, personally I don't think I've ever seen it. I've seen migrations that fail half-way through and bad states, but always with a clear error message.

Taking a step back and thinking about improving migrations-related code / process. One thing I'd like seen is collapsing/cleaning database migrations.

$ find superset/migrations/versions/|wc  -l
     980

Currently we have 980 migrations, I could collapse since say 1.0.0 or 2.0.0 and end up with much less migrations. Not sure if worth our while.

Maybe a more important thing I could spend a cycle or two on would be to clean the mismatches. When running alembic, it becomes evident that there's a lot of differences between what's declared in models and what's in the physical database, resulting on a vanilla alembic run generating lots of output.

If I was to align 100% on alembic, we could have a CI script that prevents deriving away between what's declared and how it gets stamped in the database.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if false-negative or swallowed errors on db migrations is a thing, personally I don't think I've ever seen it.

I think we should not swallow the errors. It's more about making sure that migrations are more resilient. Dropping a column that does not exist or adding a column that matches the one in the database (same config) should not throw errors. We could log warnings instead so that admins are aware.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more important thing I could spend a cycle or two on would be to clean the mismatches. When running alembic, it becomes evident that there's a lot of differences between what's declared in models and what's in the physical database, resulting on a vanilla alembic run generating lots of output.

If I was to align 100% on alembic, we could have a CI script that prevents deriving away between what's declared and how it gets stamped in the database.

That's a good idea 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:backend Requires changing the backend preset-io review:draft risk:db-migration PRs that require a DB migration size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants