demarches-normaliennes/db/migrate/20161005144657_purge_draft_dossier.rb
2018-03-06 17:18:44 +01:00

25 lines
549 B
Ruby

class PurgeDraftDossier < ActiveRecord::Migration
class Dossier < ApplicationRecord
BROUILLON = %w(draft)
def brouillon?
BROUILLON.include?(state)
end
end
class Commentaire < ApplicationRecord
belongs_to :dossier
end
class Cerfa < ApplicationRecord
belongs_to :dossier
belongs_to :user
end
def change
Cerfa.all.each { |cerfa| cerfa.delete if cerfa.dossier.brouillon? }
Commentaire.all.each { |com| com.delete if com.dossier.brouillon? }
Dossier.where(state: :draft).destroy_all
end
end