Skip to content

Commit 02d4a79

Browse files
committed
Rails app:update: missing migrations
We don't use ActiveStorage in this app, but app:update detected these migrations were missing so I feel it's better to add them for now. We can more fully remove ActiveStorage from this app in the future, but I was not prepared to address that during this maintenance cycle.
1 parent 630b9a2 commit 02d4a79

4 files changed

+58
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This migration comes from active_storage (originally 20190112182829)
2+
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
3+
def up
4+
return unless table_exists?(:active_storage_blobs)
5+
6+
unless column_exists?(:active_storage_blobs, :service_name)
7+
add_column :active_storage_blobs, :service_name, :string
8+
9+
if configured_service = ActiveStorage::Blob.service.name
10+
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
11+
end
12+
13+
change_column :active_storage_blobs, :service_name, :string, null: false
14+
end
15+
end
16+
17+
def down
18+
return unless table_exists?(:active_storage_blobs)
19+
20+
remove_column :active_storage_blobs, :service_name
21+
end
22+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This migration comes from active_storage (originally 20191206030411)
2+
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
3+
def change
4+
return unless table_exists?(:active_storage_blobs)
5+
6+
# Use Active Record's configured type for primary key
7+
create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
8+
t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
9+
t.string :variation_digest, null: false
10+
11+
t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
12+
t.foreign_key :active_storage_blobs, column: :blob_id
13+
end
14+
end
15+
16+
private
17+
def primary_key_type
18+
config = Rails.configuration.generators
19+
config.options[config.orm][:primary_key_type] || :primary_key
20+
end
21+
22+
def blobs_primary_key_type
23+
pkey_name = connection.primary_key(:active_storage_blobs)
24+
pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
25+
pkey_column.bigint? ? :bigint : pkey_column.type
26+
end
27+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This migration comes from active_storage (originally 20211119233751)
2+
class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0]
3+
def change
4+
return unless table_exists?(:active_storage_blobs)
5+
6+
change_column_null(:active_storage_blobs, :checksum, true)
7+
end
8+
end

db/schema.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)