Skip to content

Commit

Permalink
Add migrations introduced by rails update task
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Apr 6, 2024
1 parent 2988751 commit 8d5486d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
return unless table_exists?(:active_storage_blobs)

unless column_exists?(:active_storage_blobs, :service_name)

Check failure on line 6 in db/migrate/20240406222249_add_service_name_to_active_storage_blobs.active_storage.rb

View workflow job for this annotation

GitHub Actions / RuboCop (Ruby)

Style/GuardClause: Use a guard clause (`return if column_exists?(:active_storage_blobs, :service_name)`) instead of wrapping the code inside a conditional expression.
add_column :active_storage_blobs, :service_name, :string

if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end

change_column :active_storage_blobs, :service_name, :string, null: false
end
end

def down
return unless table_exists?(:active_storage_blobs)

remove_column :active_storage_blobs, :service_name
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
return unless table_exists?(:active_storage_blobs)

# Use Active Record's configured type for primary key
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
t.string :variation_digest, null: false

t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

private
def primary_key_type
config = Rails.configuration.generators
config.options[config.orm][:primary_key_type] || :primary_key
end

def blobs_primary_key_type
pkey_name = connection.primary_key(:active_storage_blobs)
pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
pkey_column.bigint? ? :bigint : pkey_column.type
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This migration comes from active_storage (originally 20211119233751)
class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0]
def change
return unless table_exists?(:active_storage_blobs)

change_column_null(:active_storage_blobs, :checksum, true)
end
end

0 comments on commit 8d5486d

Please sign in to comment.