Merge pull request #6035 from betagouv/last-part-of-active-storage-migration

Base de donnée : ajout d'une contrainte 'not null' sur la colonne `service_name` de la table `active_storage_blobs` (#6035)
This commit is contained in:
Pierre de La Morinerie 2021-03-30 13:02:39 +02:00 committed by GitHub
commit 5bc40595c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,21 @@
class AddNotNullServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.1]
def up
unless column_exists?(:active_storage_blobs, :service_name, null: false)
if (configured_service = ActiveStorage::Blob.service.name)
# First backfill the remaining data.
# (It should be fast, because the previous migration already backfilled almost all of it.)
say_with_time('fill missings ActiveStorage::Blob.service_name. This could take a while…') do
# rubocop:disable DS/Unscoped
ActiveStorage::Blob.unscoped.where(service_name: nil).update_all service_name: configured_service
# rubocop:enable DS/Unscoped
end
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
def down
change_column :active_storage_blobs, :service_name, :string, null: true
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_03_18_090001) do ActiveRecord::Schema.define(version: 2021_03_30_112235) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -44,7 +44,7 @@ ActiveRecord::Schema.define(version: 2021_03_18_090001) do
t.bigint "byte_size", null: false t.bigint "byte_size", null: false
t.string "checksum", null: false t.string "checksum", null: false
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.string "service_name" t.string "service_name", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end end