2016-10-05 17:12:45 +02:00
|
|
|
class PurgeDraftDossier < ActiveRecord::Migration
|
2018-03-06 13:44:29 +01:00
|
|
|
class Dossier < ApplicationRecord
|
2016-10-05 17:12:45 +02:00
|
|
|
BROUILLON = %w(draft)
|
|
|
|
|
|
|
|
def brouillon?
|
|
|
|
BROUILLON.include?(state)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class Commentaire < ApplicationRecord
|
2016-10-05 17:12:45 +02:00
|
|
|
belongs_to :dossier
|
|
|
|
end
|
|
|
|
|
2018-03-06 13:44:29 +01:00
|
|
|
class Cerfa < ApplicationRecord
|
2016-10-05 17:12:45 +02:00
|
|
|
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
|