mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 08:43:37 +02:00
Save documents on disk
This commit is contained in:
parent
a99d36f683
commit
79f76b2ccf
6 changed files with 41 additions and 6 deletions
19
db/migrate/20150422132631_save_legal_docs_to_disk.rb
Normal file
19
db/migrate/20150422132631_save_legal_docs_to_disk.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
class SaveLegalDocsToDisk < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :legal_documents, :path, :string
|
||||
LegalDocument.all.each do |x|
|
||||
path = nil
|
||||
loop do
|
||||
rand = SecureRandom.random_number.to_s.last(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
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150417082723) do
|
||||
ActiveRecord::Schema.define(version: 20150422132631) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -396,13 +396,13 @@ ActiveRecord::Schema.define(version: 20150417082723) do
|
|||
|
||||
create_table "legal_documents", force: :cascade do |t|
|
||||
t.string "document_type"
|
||||
t.text "body"
|
||||
t.integer "documentable_id"
|
||||
t.string "documentable_type"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "creator_str"
|
||||
t.string "updator_str"
|
||||
t.string "path"
|
||||
end
|
||||
|
||||
add_index "legal_documents", ["documentable_type", "documentable_id"], name: "index_legal_documents_on_documentable_type_and_documentable_id", using: :btree
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue