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

Move DataExport CSV data into Active Storage #9409

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

Nitemaeric
Copy link
Contributor

@Nitemaeric Nitemaeric commented May 29, 2024

Context

We want to reduce the size of the data_exports table rows. They are currently storing the CSV contents in the database itself in binary form.

Changes proposed in this pull request

  • Migrate existing DataExport csv data in the data attribute into the file attachment.
  • Update the data_exports#download controller action to download from Azure.

Guidance to review

Locally

  • You'll need a storage account with a container in Azure Storage.
  • Update the AZURE_STORAGE_ACCOUNT_NAME, AZURE_STORAGE_ACCESS_KEY, and AZURE_STORAGE_CONTAINER_NAME environment variables accordingly.

Documentation

Link to Trello card

https://trello.com/c/AS6YvTve/1342-bug-apply-db-backups-intermittently-failing

Things to check

  • If the code removes any existing feature flags, a data migration has also been added to delete the entry from the database
  • This code does not rely on migrations in the same Pull Request
  • If this code includes a migration adding or changing columns, it also backfills existing records for consistency
  • If this code adds a column to the DB, decide whether it needs to be in analytics yml file or analytics blocklist
  • API release notes have been updated if necessary
  • If it adds a significant user-facing change, is it documented in the CHANGELOG?
  • Required environment variables have been updated added to the Azure KeyVault

@Nitemaeric Nitemaeric self-assigned this May 29, 2024
@Nitemaeric Nitemaeric force-pushed the dd/move-data-export-files-into-active-storage branch from fab851c to 0c1c121 Compare May 30, 2024 09:57
@Nitemaeric Nitemaeric requested review from a team, aje54 and saliceti and removed request for a team and aje54 May 30, 2024 10:46
@Nitemaeric Nitemaeric marked this pull request as ready for review May 30, 2024 10:47
Copy link
Collaborator

@tomas-stefano tomas-stefano left a comment

Choose a reason for hiding this comment

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

I don't wanna to be picky but:

Is it possible to separate into multiples PRs? (DB migration/ERD, data migrations/code?)
Can we add documentation to the AKS cheatsheet about how to access the azure storage/buckets file, troubleshooting, etc?

@Nitemaeric Nitemaeric changed the base branch from main to dd/add-active-storage May 31, 2024 13:34
@Nitemaeric Nitemaeric force-pushed the dd/move-data-export-files-into-active-storage branch from 0c1c121 to daa2870 Compare June 3, 2024 09:54
Copy link
Contributor

@dcyoung-dev dcyoung-dev left a comment

Choose a reason for hiding this comment

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

😍 makes life much easier 🚀

@@ -48,7 +48,8 @@ def create
def download
data_export = DataExport.find(params[:id])
data_export.update!(audit_comment: 'File downloaded')
send_data data_export.data, filename: data_export.filename, disposition: :attachment

redirect_to rails_blob_path(data_export.file, disposition: 'attachment')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check if data_export.file.attached? here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took a slightly separate approach here. If the file doesn't exist, the .find call will fail.

@Nitemaeric Nitemaeric force-pushed the dd/add-active-storage branch 2 times, most recently from 35c4782 to f92e524 Compare June 6, 2024 11:25
@Nitemaeric Nitemaeric force-pushed the dd/move-data-export-files-into-active-storage branch from daa2870 to e0478de Compare June 6, 2024 11:45
Base automatically changed from dd/add-active-storage to main June 7, 2024 15:15
Migrate previous `DataExport#data` values into `DataExport#file`.

Start populating the CSV content into the `DataExport#file` field via the `DataExporter` class calls.
@Nitemaeric Nitemaeric force-pushed the dd/move-data-export-files-into-active-storage branch from e0478de to 4b0a386 Compare June 11, 2024 10:54
Copy link
Collaborator

@tomas-stefano tomas-stefano left a comment

Choose a reason for hiding this comment

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

Looks great 🚀

@Nitemaeric Nitemaeric merged commit d04ca5d into main Jun 11, 2024
24 checks passed
@Nitemaeric Nitemaeric deleted the dd/move-data-export-files-into-active-storage branch June 11, 2024 12:18
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.

3 participants