diff --git a/db/migrate/20150429135339_add_missing_data.rb b/db/migrate/20150429135339_add_missing_data.rb new file mode 100644 index 000000000..c5056745e --- /dev/null +++ b/db/migrate/20150429135339_add_missing_data.rb @@ -0,0 +1,36 @@ +class AddMissingData < ActiveRecord::Migration + def change + return if Rails.env == 'development' + return if Rails.env == 'test' + + Registrar.all.each do |x| + Account.create( + registrar_id: x.id, + account_type: Account::CASH, + balance: 0.0, + currency: 'EUR' + ) + end + + Registrar.all.each do |x| + x.generate_iso_11649_reference_no + x.save + end + + LegalDocument.all.each do |x| + path = nil + loop do + rand = SecureRandom.random_number.to_s.last(4) + next if rand.to_i == 0 || rand.length < 4 + path = "#{ENV['legal_documents_dir']}/#{Time.zone.now.to_formatted_s(:number)}_#{rand}.#{x.document_type}" + break unless File.file?(path) + end + + body = x.read_attribute('body') + File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } + x.update_column('path', path) + end + + remove_column :legal_documents, :body, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 4acc0aea6..491b5d633 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150428075052) do +ActiveRecord::Schema.define(version: 20150429135339) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -297,12 +297,8 @@ ActiveRecord::Schema.define(version: 20150428075052) do t.integer "legacy_id" t.integer "legacy_registrar_id" t.integer "legacy_registrant_id" - t.datetime "outzone_at" - t.datetime "delete_at" end - add_index "domains", ["delete_at"], name: "index_domains_on_delete_at", using: :btree - add_index "domains", ["outzone_at"], name: "index_domains_on_outzone_at", using: :btree add_index "domains", ["registrant_id"], name: "index_domains_on_registrant_id", using: :btree add_index "domains", ["registrar_id"], name: "index_domains_on_registrar_id", using: :btree