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

fix: add migration to remove old ckeditor table #61

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

Conversation

earthcomfy
Copy link

@earthcomfy earthcomfy commented Feb 18, 2025

This PR attempts to add a migration file to remove the old ckeditor table.
Fixes #60

Summary by Sourcery

Bug Fixes:

  • Removes a stale database table from a previous version of the application to avoid conflicts.

Copy link
Contributor

sourcery-ai bot commented Feb 18, 2025

Reviewer's Guide by Sourcery

This pull request adds a migration to remove the old djangocms_text_ckeditor_text table. The migration checks if the table exists and drops it if it does, using a database-specific command to handle potential dependencies.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added a data migration to remove the old CKEditor table.
  • Implemented a function drop_table_if_exists to conditionally drop the table.
  • Used schema_editor.connection.introspection.table_names() to check for the table's existence.
  • Included a database-specific command for PostgreSQL to handle CASCADE deletion.
  • Added a migration that runs the drop_table_if_exists function.
  • Added a no-op reverse code to prevent issues during migration rollback.
djangocms_text/migrations/0004_remove_old_ckeditor_table.py

Possibly linked issues

  • #123: The PR fixes the issue by adding a migration to remove the old ckeditor table.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @earthcomfy - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a comment to explain why the table needs to be dropped.
  • It might be safer to check if the table exists within the drop_table_if_exists function using apps.get_model rather than relying on schema_editor.connection.introspection.table_names().
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

README.rst Outdated
@@ -59,7 +59,7 @@ Upgrading from djangocms-text-ckeditor
--------------------------------------

djangocms-text's migrations automatically migrate existing text plugins
from djangocms-text-ckeditor. All you have to do is:
from djangocms-text-ckeditor and clean up old tables. All you have to do is:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (typo): Add a comma after 'djangocms-text-ckeditor'.

The sentence would read better with a comma after 'djangocms-text-ckeditor'.

Suggested change
from djangocms-text-ckeditor and clean up old tables. All you have to do is:
from djangocms-text-ckeditor, and clean up old tables. All you have to do is:

@earthcomfy
Copy link
Author

I used schema_editor because it provides a Django-agnostic way to manage database schema changes. Also, the previous migration file uses it.

@DmytroLitvinov
Copy link
Contributor

HI there,
Should it be really in the package's migration instead of mentioning it in case someone is migrated?

My concern is that it automatically drops the tables.

@earthcomfy
Copy link
Author

@DmytroLitvinov I brought this idea in the issue and thought we wanted to move forward with this approach. @fsbraun

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 81.30%. Comparing base (30f539b) to head (ff8b8ca).

Files with missing lines Patch % Lines
..._text/migrations/0004_remove_old_ckeditor_table.py 50.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
- Coverage   81.63%   81.30%   -0.34%     
==========================================
  Files          17       18       +1     
  Lines         942      952      +10     
  Branches      105      107       +2     
==========================================
+ Hits          769      774       +5     
- Misses        130      135       +5     
  Partials       43       43              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fsbraun
Copy link
Member

fsbraun commented Feb 18, 2025

@DmytroLitvinov Any regular migration would replace the old model by the new one retaining already existing data (if possible). This is also the case for this migration. I would second adding it. (Thanks, @earthcomfy )

It might be worthwhile mentioning that one can avoid the old tables to be dropped if migrations are run up to 0003 and 0004 is faked. Maybe we can add this to the migration guide in the readme? The issue of doing this will be potential constraints.

@fsbraun
Copy link
Member

fsbraun commented Feb 18, 2025

@earthcomfy Why is the CASCADE command important for Postgres? Can you comment how you tested this (with Postgres and which databases)?

@earthcomfy
Copy link
Author

@fsbraun I tested this by creating a test project inside my branch. I first added djangocms_text_ckeditor into my installed apps and when I run migrate it creates the djangocms_text_ckeditor_text table. Then I replaced the installation with djangocms_text and run migrate. This applies all the migration files including the drop table and the table no longer exists.

I also tested this both with sqlite and postgres.

I added cascade because of the description mentioned in the issue. In PostgreSQL, to drop a table that is referenced by a view or a foreign-key constraint of another table, we have to use cascade. That is my thought process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot delete text plugins or publish CMS pages after upgrading from djangocms-text-ckeditor
3 participants