-
Notifications
You must be signed in to change notification settings - Fork 8.7k
DEV: Change upload verified column to be integer #10643
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
Changes from all commits
34f272d
900eac2
36f8e0e
9033a5c
a65e535
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
| require "digest/sha1" | ||
|
|
||
| class Upload < ActiveRecord::Base | ||
| self.ignored_columns = [ | ||
| "verified" # TODO(2020-12-10): remove | ||
| ] | ||
|
|
||
| include ActionView::Helpers::NumberHelper | ||
| include HasUrl | ||
|
|
||
|
|
@@ -51,6 +55,14 @@ def access_control_post | |
|
|
||
| scope :by_users, -> { where("uploads.id > ?", SEEDED_ID_THRESHOLD) } | ||
|
|
||
| def self.verification_statuses | ||
| @verification_statuses ||= Enum.new( | ||
| unchecked: 1, | ||
| verified: 2, | ||
| invalid_etag: 3 | ||
| ) | ||
| end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am curious if here wouldn't be beneficial to use rails enums. That would by default define scopes so for example later instead of I grepped and we are not using enums too often so maybe there is a reason for that. I only found one in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure, we have lib/enum.rb so I am just being consistent. IMO we could easily make the API easier so at least we could do |
||
|
|
||
| def to_s | ||
| self.url | ||
| end | ||
|
|
@@ -449,6 +461,7 @@ def short_url_basename | |
| # access_control_post_id :bigint | ||
| # original_sha1 :string | ||
| # verified :boolean | ||
| # verification_status :integer default(1), not null | ||
| # | ||
| # Indexes | ||
| # | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class ChangeUploadsVerifiedToInteger < ActiveRecord::Migration[6.0] | ||
| def up | ||
| add_column :uploads, :verification_status, :integer, null: false, default: 1 | ||
| Migration::ColumnDropper.mark_readonly(:uploads, :verified) | ||
|
|
||
| DB.exec( | ||
| <<~SQL | ||
| UPDATE uploads SET verification_status = CASE WHEN | ||
| verified THEN 2 | ||
| WHEN NOT verified THEN 3 | ||
| END | ||
| SQL | ||
| ) | ||
| end | ||
|
|
||
| def down | ||
| remove_column :uploads, :verification_status | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddIndexToUploadsVerificationStatus < ActiveRecord::Migration[6.0] | ||
| disable_ddl_transaction! | ||
|
|
||
| def up | ||
| execute <<~SQL | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS | ||
| idx_uploads_on_verification_status ON uploads USING btree (verification_status) | ||
| SQL | ||
| end | ||
|
|
||
| def down | ||
| execute "DROP INDEX IF EXISTS idx_uploads_on_verification_status" | ||
| end | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.