Merge pull request #1059 from sgmap/add-timestamps-to-entreprise

Add timestamps on Entreprises
This commit is contained in:
Mathieu Magnin 2017-12-08 10:41:00 +01:00 committed by GitHub
commit 9e1ca5258a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 2 deletions

View file

@ -0,0 +1,6 @@
class AddTimestampsToEntreprise < ActiveRecord::Migration[5.0]
def change
add_column :entreprises, :created_at, :datetime
add_column :entreprises, :updated_at, :datetime
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171123125346) do
ActiveRecord::Schema.define(version: 20171205151128) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -224,6 +224,8 @@ ActiveRecord::Schema.define(version: 20171123125346) do
t.string "nom"
t.string "prenom"
t.integer "dossier_id"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["dossier_id"], name: "index_entreprises_on_dossier_id", using: :btree
end
@ -419,8 +421,8 @@ ActiveRecord::Schema.define(version: 20171123125346) do
t.boolean "for_individual", default: false
t.boolean "individual_with_siret", default: false
t.date "auto_archive_on"
t.datetime "hidden_at"
t.datetime "published_at"
t.datetime "hidden_at"
t.datetime "archived_at"
t.index ["hidden_at"], name: "index_procedures_on_hidden_at", using: :btree
end

View file

@ -0,0 +1,19 @@
namespace :'2017_12_05_initialize_timestamps_for_entreprises' do
task set: :environment do
entreprises = Entreprise.where(created_at: nil).includes(:dossier)
puts "#{entreprises.count} to initialize..."
entreprises.each { |e| initialize_entreprise(e) }
end
def initialize_entreprise(entreprise)
puts "initializing entreprise #{entreprise.id}"
if entreprise.dossier.present?
entreprise.update_columns(created_at: entreprise.dossier.created_at, updated_at: entreprise.dossier.created_at)
else
puts "dossier #{entreprise.dossier_id} is missing for entreprise #{entreprise.id}"
entreprise.update_columns(created_at: DateTime.now, updated_at: DateTime.now)
end
end
end