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

Remove tags_list from models and ingestion_server #956

Merged
merged 3 commits into from
Apr 27, 2023
Merged

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Mar 20, 2023

Needs #1029 to be deployed and the tags_list column is dropped from the database

Fixes

Fixes #704 by @obulat

Description

This PR removes tags_list from models and from the ingestion_server. This should be done after the column is dropped from the database.

Testing Instructions

If you run #1029, and then repeat the steps outlined in the comment with this PR rebased onto #1029 and #1029 (instead of this PR and main), you should not see errors in logs.

Checklist

  • My pull request has a descriptive title (not a vague title like
    Update index.md).
  • My pull request targets the default branch of the repository (main) or
    a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible
    errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat requested review from a team as code owners March 20, 2023 12:13
@github-actions github-actions bot added 🧱 stack: api Related to the Django API 🧱 stack: ingestion server Related to the ingestion/data refresh server labels Mar 20, 2023
@github-actions
Copy link

github-actions bot commented Mar 20, 2023

Full-stack documentation: Ready

https://WordPress.github.io/openverse/_preview/956

Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.

You can check the GitHub pages deployment action list to see the current status of the deployments.

@obulat obulat added 🟨 priority: medium Not blocking but should be addressed soon 🧰 goal: internal improvement Improvement that benefits maintainers, not users 💻 aspect: code Concerns the software code in the repository labels Mar 20, 2023
@sarayourfriend
Copy link
Collaborator

sarayourfriend commented Mar 20, 2023

@obulat Why doesn't this change require a migration (removing the field)?

@obulat
Copy link
Contributor Author

obulat commented Mar 21, 2023

@obulat Why doesn't this change require a migration (removing the field)?

I don't know. @dhruvkb, do you know why?

@github-actions github-actions bot added the 🧱 stack: frontend Related to the Nuxt frontend label Mar 22, 2023
@github-actions
Copy link

github-actions bot commented Mar 22, 2023

Size Change: -1 B (0%)

Total Size: 848 kB

ℹ️ View Unchanged
Filename Size Change
./frontend/.nuxt/dist/client/235.js 273 B 0 B
./frontend/.nuxt/dist/client/235.modern.js 278 B 0 B
./frontend/.nuxt/dist/client/236.js 1.85 kB 0 B
./frontend/.nuxt/dist/client/app.js 125 kB 0 B
./frontend/.nuxt/dist/client/app.modern.js 117 kB -1 B (0%)
./frontend/.nuxt/dist/client/commons/app.js 90.3 kB 0 B
./frontend/.nuxt/dist/client/commons/app.modern.js 78.5 kB 0 B
./frontend/.nuxt/dist/client/components/loading-icon.js 750 B 0 B
./frontend/.nuxt/dist/client/components/loading-icon.modern.js 757 B 0 B
./frontend/.nuxt/dist/client/components/table-sort-icon.js 515 B 0 B
./frontend/.nuxt/dist/client/components/table-sort-icon.modern.js 518 B 0 B
./frontend/.nuxt/dist/client/components/v-all-results-grid.js 5.63 kB 0 B
./frontend/.nuxt/dist/client/components/v-all-results-grid.modern.js 5.48 kB 0 B
./frontend/.nuxt/dist/client/components/v-audio-cell.js 392 B 0 B
./frontend/.nuxt/dist/client/components/v-audio-cell.modern.js 397 B 0 B
./frontend/.nuxt/dist/client/components/v-audio-details.js 1.83 kB 0 B
./frontend/.nuxt/dist/client/components/v-audio-details.modern.js 1.8 kB 0 B
./frontend/.nuxt/dist/client/components/v-audio-track-skeleton.js 1.02 kB 0 B
./frontend/.nuxt/dist/client/components/v-audio-track-skeleton.modern.js 1.02 kB 0 B
./frontend/.nuxt/dist/client/components/v-audio-track.js 5.25 kB 0 B
./frontend/.nuxt/dist/client/components/v-audio-track.modern.js 5.21 kB 0 B
./frontend/.nuxt/dist/client/components/v-back-to-search-results-link.js 542 B 0 B
./frontend/.nuxt/dist/client/components/v-back-to-search-results-link.modern.js 548 B 0 B
./frontend/.nuxt/dist/client/components/v-bone.js 689 B 0 B
./frontend/.nuxt/dist/client/components/v-bone.modern.js 693 B 0 B
./frontend/.nuxt/dist/client/components/v-box-layout.js 1.28 kB 0 B
./frontend/.nuxt/dist/client/components/v-box-layout.modern.js 1.28 kB 0 B
./frontend/.nuxt/dist/client/components/v-content-link.js 1.12 kB 0 B
./frontend/.nuxt/dist/client/components/v-content-link.modern.js 1.1 kB 0 B
./frontend/.nuxt/dist/client/components/v-content-page.js 526 B 0 B
./frontend/.nuxt/dist/client/components/v-content-page.modern.js 530 B 0 B
./frontend/.nuxt/dist/client/components/v-content-report-button.js 785 B 0 B
./frontend/.nuxt/dist/client/components/v-content-report-button.modern.js 790 B 0 B
./frontend/.nuxt/dist/client/components/v-content-report-form.js 3.78 kB 0 B
./frontend/.nuxt/dist/client/components/v-content-report-form.modern.js 3.6 kB 0 B
./frontend/.nuxt/dist/client/components/v-content-report-popover.js 4.44 kB 0 B
./frontend/.nuxt/dist/client/components/v-content-report-popover.modern.js 4.25 kB 0 B
./frontend/.nuxt/dist/client/components/v-copy-button.js 4 kB 0 B
./frontend/.nuxt/dist/client/components/v-copy-button.modern.js 4.01 kB 0 B
./frontend/.nuxt/dist/client/components/v-copy-license.js 1 kB 0 B
./frontend/.nuxt/dist/client/components/v-copy-license.modern.js 1 kB 0 B
./frontend/.nuxt/dist/client/components/v-copy-license/components/v-error-image/components/v-media-reuse/components/v-search-grid/d219393b.js 9.96 kB 0 B
./frontend/.nuxt/dist/client/components/v-copy-license/components/v-error-image/components/v-media-reuse/components/v-search-grid/d219393b.modern.js 9.94 kB 0 B
./frontend/.nuxt/dist/client/components/v-dmca-notice.js 754 B 0 B
./frontend/.nuxt/dist/client/components/v-dmca-notice.modern.js 758 B 0 B
./frontend/.nuxt/dist/client/components/v-error-image.js 1.69 kB 0 B
./frontend/.nuxt/dist/client/components/v-error-image.modern.js 1.68 kB 0 B
./frontend/.nuxt/dist/client/components/v-error-section.js 372 B 0 B
./frontend/.nuxt/dist/client/components/v-error-section.modern.js 376 B 0 B
./frontend/.nuxt/dist/client/components/v-external-search-form.js 1.93 kB 0 B
./frontend/.nuxt/dist/client/components/v-external-search-form.modern.js 1.92 kB 0 B
./frontend/.nuxt/dist/client/components/v-external-source-list.js 906 B 0 B
./frontend/.nuxt/dist/client/components/v-external-source-list.modern.js 907 B 0 B
./frontend/.nuxt/dist/client/components/v-full-layout.js 1.52 kB 0 B
./frontend/.nuxt/dist/client/components/v-full-layout.modern.js 1.52 kB 0 B
./frontend/.nuxt/dist/client/components/v-grid-skeleton.js 1.61 kB 0 B
./frontend/.nuxt/dist/client/components/v-grid-skeleton.modern.js 1.62 kB 0 B
./frontend/.nuxt/dist/client/components/v-home-gallery.js 5.18 kB 0 B
./frontend/.nuxt/dist/client/components/v-home-gallery.modern.js 5.17 kB 0 B
./frontend/.nuxt/dist/client/components/v-homepage-content.js 1.76 kB 0 B
./frontend/.nuxt/dist/client/components/v-homepage-content.modern.js 1.72 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-carousel.js 4.74 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-carousel.modern.js 4.72 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-cell.js 1.59 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-cell.modern.js 1.59 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-details.js 1.44 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-details.modern.js 1.43 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-grid.js 2.66 kB 0 B
./frontend/.nuxt/dist/client/components/v-image-grid.modern.js 2.54 kB 0 B
./frontend/.nuxt/dist/client/components/v-license-tab-panel.js 525 B 0 B
./frontend/.nuxt/dist/client/components/v-license-tab-panel.modern.js 528 B 0 B
./frontend/.nuxt/dist/client/components/v-load-more.js 799 B 0 B
./frontend/.nuxt/dist/client/components/v-load-more.modern.js 697 B 0 B
./frontend/.nuxt/dist/client/components/v-media-license.js 829 B 0 B
./frontend/.nuxt/dist/client/components/v-media-license.modern.js 837 B 0 B
./frontend/.nuxt/dist/client/components/v-media-reuse.js 1.63 kB 0 B
./frontend/.nuxt/dist/client/components/v-media-reuse.modern.js 1.62 kB 0 B
./frontend/.nuxt/dist/client/components/v-media-tag.js 434 B 0 B
./frontend/.nuxt/dist/client/components/v-media-tag.modern.js 439 B 0 B
./frontend/.nuxt/dist/client/components/v-modal.js 1.01 kB 0 B
./frontend/.nuxt/dist/client/components/v-modal.modern.js 996 B 0 B
./frontend/.nuxt/dist/client/components/v-no-results.js 757 B 0 B
./frontend/.nuxt/dist/client/components/v-no-results.modern.js 755 B 0 B
./frontend/.nuxt/dist/client/components/v-radio.js 1.52 kB 0 B
./frontend/.nuxt/dist/client/components/v-radio.modern.js 1.48 kB 0 B
./frontend/.nuxt/dist/client/components/v-related-audio.js 1.26 kB 0 B
./frontend/.nuxt/dist/client/components/v-related-audio.modern.js 1.27 kB 0 B
./frontend/.nuxt/dist/client/components/v-related-images.js 3.24 kB 0 B
./frontend/.nuxt/dist/client/components/v-related-images.modern.js 3.12 kB 0 B
./frontend/.nuxt/dist/client/components/v-report-desc-form.js 977 B 0 B
./frontend/.nuxt/dist/client/components/v-report-desc-form.modern.js 980 B 0 B
./frontend/.nuxt/dist/client/components/v-row-layout.js 1.71 kB 0 B
./frontend/.nuxt/dist/client/components/v-row-layout.modern.js 1.71 kB 0 B
./frontend/.nuxt/dist/client/components/v-scroll-button.js 825 B 0 B
./frontend/.nuxt/dist/client/components/v-scroll-button.modern.js 830 B 0 B
./frontend/.nuxt/dist/client/components/v-search-grid.js 5.75 kB 0 B
./frontend/.nuxt/dist/client/components/v-search-grid.modern.js 5.67 kB 0 B
./frontend/.nuxt/dist/client/components/v-search-results-title.js 598 B 0 B
./frontend/.nuxt/dist/client/components/v-search-results-title.modern.js 605 B 0 B
./frontend/.nuxt/dist/client/components/v-search-type-radio.js 804 B 0 B
./frontend/.nuxt/dist/client/components/v-search-type-radio.modern.js 779 B 0 B
./frontend/.nuxt/dist/client/components/v-server-timeout.js 300 B 0 B
./frontend/.nuxt/dist/client/components/v-server-timeout.modern.js 303 B 0 B
./frontend/.nuxt/dist/client/components/v-sketch-fab-viewer.js 1.01 kB 0 B
./frontend/.nuxt/dist/client/components/v-sketch-fab-viewer.modern.js 913 B 0 B
./frontend/.nuxt/dist/client/components/v-snackbar.js 1.16 kB 0 B
./frontend/.nuxt/dist/client/components/v-snackbar.modern.js 1.16 kB 0 B
./frontend/.nuxt/dist/client/components/v-sources-table.js 15 kB 0 B
./frontend/.nuxt/dist/client/components/v-sources-table.modern.js 15 kB 0 B
./frontend/.nuxt/dist/client/components/v-warning-suppressor.js 306 B 0 B
./frontend/.nuxt/dist/client/components/v-warning-suppressor.modern.js 311 B 0 B
./frontend/.nuxt/dist/client/pages/about.js 1.4 kB 0 B
./frontend/.nuxt/dist/client/pages/about.modern.js 1.4 kB 0 B
./frontend/.nuxt/dist/client/pages/audio/_id/index.js 5.02 kB 0 B
./frontend/.nuxt/dist/client/pages/audio/_id/index.modern.js 4.87 kB 0 B
./frontend/.nuxt/dist/client/pages/external-sources.js 1.56 kB 0 B
./frontend/.nuxt/dist/client/pages/external-sources.modern.js 1.57 kB 0 B
./frontend/.nuxt/dist/client/pages/feedback.js 1.34 kB 0 B
./frontend/.nuxt/dist/client/pages/feedback.modern.js 1.35 kB 0 B
./frontend/.nuxt/dist/client/pages/image/_id/index.js 5.41 kB 0 B
./frontend/.nuxt/dist/client/pages/image/_id/index.modern.js 5.17 kB 0 B
./frontend/.nuxt/dist/client/pages/image/_id/report.js 4.55 kB 0 B
./frontend/.nuxt/dist/client/pages/image/_id/report.modern.js 4.27 kB 0 B
./frontend/.nuxt/dist/client/pages/index.js 7.28 kB 0 B
./frontend/.nuxt/dist/client/pages/index.modern.js 7.21 kB 0 B
./frontend/.nuxt/dist/client/pages/preferences.js 1.32 kB 0 B
./frontend/.nuxt/dist/client/pages/preferences.modern.js 1.32 kB 0 B
./frontend/.nuxt/dist/client/pages/privacy.js 1.01 kB 0 B
./frontend/.nuxt/dist/client/pages/privacy.modern.js 1.02 kB 0 B
./frontend/.nuxt/dist/client/pages/search-help.js 1.6 kB 0 B
./frontend/.nuxt/dist/client/pages/search-help.modern.js 1.58 kB 0 B
./frontend/.nuxt/dist/client/pages/search.js 2.2 kB 0 B
./frontend/.nuxt/dist/client/pages/search.modern.js 2.05 kB 0 B
./frontend/.nuxt/dist/client/pages/search/audio.js 3.6 kB 0 B
./frontend/.nuxt/dist/client/pages/search/audio.modern.js 3.51 kB 0 B
./frontend/.nuxt/dist/client/pages/search/image.js 2.84 kB 0 B
./frontend/.nuxt/dist/client/pages/search/image.modern.js 2.73 kB 0 B
./frontend/.nuxt/dist/client/pages/search/index.js 444 B 0 B
./frontend/.nuxt/dist/client/pages/search/index.modern.js 448 B 0 B
./frontend/.nuxt/dist/client/pages/search/model-3d.js 243 B 0 B
./frontend/.nuxt/dist/client/pages/search/model-3d.modern.js 246 B 0 B
./frontend/.nuxt/dist/client/pages/search/search-page.types.js 266 B 0 B
./frontend/.nuxt/dist/client/pages/search/search-page.types.modern.js 271 B 0 B
./frontend/.nuxt/dist/client/pages/search/video.js 240 B 0 B
./frontend/.nuxt/dist/client/pages/search/video.modern.js 244 B 0 B
./frontend/.nuxt/dist/client/pages/sources.js 1.57 kB 0 B
./frontend/.nuxt/dist/client/pages/sources.modern.js 1.57 kB 0 B
./frontend/.nuxt/dist/client/runtime.js 2.72 kB 0 B
./frontend/.nuxt/dist/client/runtime.modern.js 2.73 kB 0 B
./frontend/.nuxt/dist/client/vendors/app.js 64.1 kB 0 B
./frontend/.nuxt/dist/client/vendors/app.modern.js 63.3 kB 0 B

compressed-size-action

@krysal krysal removed the 🧱 stack: frontend Related to the Nuxt frontend label Mar 22, 2023
@github-actions github-actions bot added 🧱 stack: frontend Related to the Nuxt frontend migrations Modifications to Django migrations labels Mar 22, 2023
Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

LGTM! I do think the migration name can be simplified to 0053_remove_tags_list.py but that's not worth blocking the PR over.

Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This change in general is fine (removing the deprecated column, etc), but this PR doesn't work for zero-downtime and would cause the search endpoints to 500 if deployed:

openverse-web-1  | [2023-03-22 21:46:26,906 - django.db.backends - 131][DEBUG] [22c5b7f7a5744e989375e975e2241468] (0.001) SELECT "image"."id", "image"."created_on", "image"."updated_on", "image"."identifier", "image"."foreign_identifier", "image"."title", "image"."foreign_landing_url", "image"."creator", "image"."creator_url", "image"."thumbnail", "image"."provider", "image"."url", "image"."filesize", "image"."filetype", "image"."watermarked", "image"."license", "image"."license_version", "image"."source", "image"."last_synced_with_source", "image"."removed_from_source", "image"."view_count", "image"."tags", "image"."tags_list", "image"."category", "image"."meta_data", "image"."width", "image"."height", "api_matureimage"."created_on", "api_matureimage"."identifier" FROM "image" LEFT OUTER JOIN "api_matureimage" ON ("image"."identifier" = "api_matureimage"."identifier") WHERE "image"."identifier" IN ('2982c0bf-9c26-4543-a712-4d50a117ded8'::uuid, '29d57e46-51f5-43e5-adbb-7841e7e8cc9c'::uuid, '2a48ea01-3ca3-4c5a-a106-a6e10d8938cf'::uuid, '2a7f6797-a1b1-43ac-ac32-e70b76185d9c'::uuid, '2cffa611-44a5-4481-ab19-04ac99420cad'::uuid, '2d04f852-4c9d-4455-895c-2b740e189164'::uuid, '2d1e593a-7214-4e09-a3ac-819cad604150'::uuid, '2dceed3d-78fa-4668-a008-9b53eeb8600e'::uuid, '2f67c4d8-8a25-4590-946b-85e62a99ac91'::uuid, '2f9631a6-41ae-497e-b5dc-a606e0e1d564'::uuid, '2fc59848-7bc6-4ba6-be1c-cb10f47f4a42'::uuid, '2fd6e7be-ea8a-4e2e-b216-21166a45aef9'::uuid, '3067904e-31d4-4252-aff7-c1b126e191fd'::uuid, '33639f6a-c0ae-426e-95f5-44ceeead2661'::uuid, '35ba97dc-0e5e-4eaf-99fe-9a0e0d824940'::uuid, '363f86e5-0c43-4038-bf4d-28fc1aa43175'::uuid, '36675f14-f34f-46d9-9094-fc1d89f762b0'::uuid, '36d19812-53ac-479c-b43b-191e708c5b85'::uuid, '37172cc8-46f4-46a9-82bf-19f88b2c036e'::uuid, '3783c73d-4d48-4199-8d1c-3fa8b0ee1d00'::uuid) ORDER BY "image"."created_on" DESC; args=(UUID('2982c0bf-9c26-4543-a712-4d50a117ded8'), UUID('29d57e46-51f5-43e5-adbb-7841e7e8cc9c'), UUID('2a48ea01-3ca3-4c5a-a106-a6e10d8938cf'), UUID('2a7f6797-a1b1-43ac-ac32-e70b76185d9c'), UUID('2cffa611-44a5-4481-ab19-04ac99420cad'), UUID('2d04f852-4c9d-4455-895c-2b740e189164'), UUID('2d1e593a-7214-4e09-a3ac-819cad604150'), UUID('2dceed3d-78fa-4668-a008-9b53eeb8600e'), UUID('2f67c4d8-8a25-4590-946b-85e62a99ac91'), UUID('2f9631a6-41ae-497e-b5dc-a606e0e1d564'), UUID('2fc59848-7bc6-4ba6-be1c-cb10f47f4a42'), UUID('2fd6e7be-ea8a-4e2e-b216-21166a45aef9'), UUID('3067904e-31d4-4252-aff7-c1b126e191fd'), UUID('33639f6a-c0ae-426e-95f5-44ceeead2661'), UUID('35ba97dc-0e5e-4eaf-99fe-9a0e0d824940'), UUID('363f86e5-0c43-4038-bf4d-28fc1aa43175'), UUID('36675f14-f34f-46d9-9094-fc1d89f762b0'), UUID('36d19812-53ac-479c-b43b-191e708c5b85'), UUID('37172cc8-46f4-46a9-82bf-19f88b2c036e'), UUID('3783c73d-4d48-4199-8d1c-3fa8b0ee1d00')); alias=default
openverse-web-1  | [2023-03-22 21:46:26,906 - django.request - 241][ERROR] [22c5b7f7a5744e989375e975e2241468] Internal Server Error: /v1/images/
openverse-web-1  | Traceback (most recent call last):
openverse-web-1  |   File "/venv/lib/python3.10/site-packages/django/db/backends/utils.py", line 89, in _execute
openverse-web-1  |     return self.cursor.execute(sql, params)
openverse-web-1  | psycopg2.errors.UndefinedColumn: column image.tags_list does not exist
openverse-web-1  | LINE 1: ...om_source", "image"."view_count", "image"."tags", "image"."t...

To reproduce this locally, checkout this branch and run just api/dj migrate. Then checkout main and just up. just logs web to tail the logs and make an images request.

This approximates the situation during a deployment because we'll have applied the migration to remove the tags_list from the model but the previous version of the application will still be running.

We probably need to make a change to the serializer to remove the usage of tags_list first, and then we can deploy a follow-up PR to remove the attribute from the model. For zero-downtime we always need to remove the usages before removing the column. It looks like in this case the usage is hidden away in a non-obvious area 😰

@sarayourfriend
Copy link
Collaborator

After re-reading this guide we found earlier I remembered that it's actually an easy solution for this and that the migration check action might get in the way of safely deploying these changes (:scream:).

We first need to have a PR that only removes the attribute from the model but does not include the migration. Once that is deployed, then we can deploy a follow-up PR that has the migration to remove the column. Basically: we'd split this PR into two, with the second only including the migration and this one having everything else.

@dhruvkb
Copy link
Member

dhruvkb commented Mar 23, 2023

Does a PR deploy automatically run the migrations? Because if not they could be merged in together and then the migrations could be executed later on, separately.

@sarayourfriend
Copy link
Collaborator

Does a PR deploy automatically run the migrations? Because if not they could be merged in together and then the migrations could be executed later on, separately.

They do. Whether to do this or not was a long discussed topic during the ECS migration. Doing as you suggested, running the migration after the deploy, only solves the case when you want to remove a column. If you add a model attribute without having run the migration to add a column, you run into the same issue (trying to select a column that doesn't exist). There are several complexities that such an approach would bring up. For one, we'd have to follow different processes for different types of migrations (either running them before deploying the app or after). Doing so would recreate the core complexity of our old deployment approach. Updating Terraform version numbers was time-consuming but trivial. Running migrations and deciding when to run them? That was a nightmare.

Zero-downtime migrations have many benefits laid out in the zero-downtime migration documentation, not least of which that it promotes a consistent approach to database schema change management. Following this approach, we don't have to think "how/when do I run this migration"? We just have to keep in mind the guidelines for zero-downtime migrations and organise our schema changes to be compatible with zero-downtime migrations. This process is documented already in the Openverse docs, including a link to the above linked guide for how to do different changes with respect to Django specifically.

@obulat
Copy link
Contributor Author

obulat commented Mar 24, 2023

We probably need to make a change to the serializer to remove the usage of tags_list first, and then we can deploy a follow-up PR to remove the attribute from the model. For zero-downtime we always need to remove the usages before removing the column. It looks like in this case the usage is hidden away in a non-obvious area 😰

I am really confused about how to find this usage. I will be investigating it, but any help is very welcome!

@obulat obulat force-pushed the remove_tags_list branch 2 times, most recently from 6d87622 to 5b74aef Compare March 24, 2023 13:40
@AetherUnbound
Copy link
Collaborator

@obulat it seems like the usage of tags_list is coming from deep within the Django ORM code, since it's currently a field and get_queryset() appears to return <model>.objects.all() which explicitly queries for every field. It looks like we could potentially deploy a version of the code where tags_list is deferred: https://stackoverflow.com/a/58445601/3277713

This would prevent tags_list from showing up in any queries made against the database, meaning we could safely deploy a migration immediately after it which would remove that column without breaking the currently deployed version.

One thing to consider in all this, though - I have no idea how long deleting the tags_list column would take in production, or whether that operation would affect production database usage. We'd probably want to test this against staging and see how long it takes before making a decision about deploying it to production.

@AetherUnbound
Copy link
Collaborator

It looks like this will need to be targeted against main and potentially rebased before it gets merged.

@obulat obulat requested a review from a team as a code owner April 24, 2023 15:13
@obulat obulat requested a review from zackkrida April 24, 2023 15:13
@obulat obulat changed the base branch from main_old to main April 24, 2023 15:13
@obulat obulat mentioned this pull request Apr 26, 2023
8 tasks
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

This looks good! I tested that the migrations runs and doesn't cause issues on main afterwards.

@WordPress WordPress deleted a comment from github-actions bot Apr 26, 2023
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@obulat
Copy link
Contributor Author

obulat commented Apr 27, 2023

I removed the tags_list column from both staging and prod databases:

deploy@localhost:openledger> alter table image drop column tags_list;
You're about to run a destructive command.
Do you want to proceed? (y/n): y
Your call!
ALTER TABLE
Time: 0.180s

Merging this PR now

@github-actions
Copy link

This PR has migrations. Please rebase it before merging to ensure that conflicting migrations are not introduced.

@sarayourfriend
Copy link
Collaborator

@obulat Why was it necessary to run the column removal manually in staging and production rather than relying on the migrations during deployment? 🤔

1 similar comment
@sarayourfriend
Copy link
Collaborator

@obulat Why was it necessary to run the column removal manually in staging and production rather than relying on the migrations during deployment? 🤔

@obulat
Copy link
Contributor Author

obulat commented Apr 27, 2023

@obulat Why was it necessary to run the column removal manually in staging and production rather than relying on the migrations during deployment? 🤔

I misunderstood the comment1 about "How long it would take to delete the column" to mean that we would need to do it manually :(

Footnotes

  1. https://github.com/WordPress/openverse/pull/956#issuecomment-1483498388

@obulat obulat merged commit 7141049 into main Apr 27, 2023
@obulat obulat deleted the remove_tags_list branch April 27, 2023 06:08
@AetherUnbound
Copy link
Collaborator

The fact that the column was explicitly deleted by a command that was run outside of Django might mean that the next deployment will fail because Django is expecting the column to be present when that migration is run. It might be necessary to re-add the columns, I'm not sure though. It seems like staging deployments are succeeding 🤷🏼‍♀️

@obulat
Copy link
Contributor Author

obulat commented May 1, 2023

The fact that the column was explicitly deleted by a command that was run outside of Django might mean that the next deployment will fail because Django is expecting the column to be present when that migration is run. It might be necessary to re-add the columns, I'm not sure though. It seems like staging deployments are succeeding 🤷🏼‍♀️

You are right, @AetherUnbound, this did cause problems. We solved it by re-adding the column back, and then deploying the API.
I learned my lesson on migrations the hard way 😀

@AetherUnbound
Copy link
Collaborator

Got it! Was production deployed successfully after reading the column as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users migrations Modifications to Django migrations 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: api Related to the Django API 🧱 stack: ingestion server Related to the ingestion/data refresh server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove legacy tags_list field
6 participants