Merge pull request #5525 from tchak/add-revisions-step-3

Révisions : suppression de la relation procédure <-> type de champ
This commit is contained in:
Pierre de La Morinerie 2020-09-03 17:15:03 +02:00 committed by GitHub
commit 72afb01cbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 25 deletions

View file

@ -44,7 +44,6 @@ module NewAdministrateur
{
type_de_champ: type_de_champ.as_json(
except: [
:id,
:created_at,
:options,
:order_place,
@ -64,7 +63,7 @@ module NewAdministrateur
:piece_justificative_template_url,
:quartiers_prioritaires
]
).merge(id: TypeDeChamp.format_stable_id(type_de_champ.stable_id))
)
}
end

View file

@ -2,20 +2,19 @@
#
# Table name: types_de_champ
#
# id :integer not null, primary key
# description :text
# libelle :string
# mandatory :boolean default(FALSE)
# options :jsonb
# order_place :integer
# private :boolean default(FALSE), not null
# type_champ :string
# created_at :datetime
# updated_at :datetime
# parent_id :bigint
# procedure_id :integer
# revision_id :bigint
# stable_id :bigint
# id :integer not null, primary key
# description :text
# libelle :string
# mandatory :boolean default(FALSE)
# options :jsonb
# order_place :integer
# private :boolean default(FALSE), not null
# type_champ :string
# created_at :datetime
# updated_at :datetime
# parent_id :bigint
# revision_id :bigint
# stable_id :bigint
#
class TypeDeChamp < ApplicationRecord
self.ignored_columns = ['procedure_id']
@ -304,7 +303,7 @@ class TypeDeChamp < ApplicationRecord
def read_attribute_for_serialization(name)
if name == 'id'
self.class.format_stable_id(stable_id)
stable_id
else
super
end
@ -317,15 +316,11 @@ class TypeDeChamp < ApplicationRecord
# This is only needed for a clean migration without downtime. We want to ensure
# that if editor send a simple id because it was loaded before deployment
# we would still do the right thing.
def self.format_stable_id(stable_id)
"stable:#{stable_id}"
end
def self.to_stable_id(id_or_stable_id)
if id_or_stable_id.to_s =~ /^stable:/
id_or_stable_id.to_s.gsub(/^stable:/, '')
else
find(id_or_stable_id).stable_id
id_or_stable_id
end
end

View file

@ -0,0 +1,5 @@
class RemoveTypeDeChampProcedureId < ActiveRecord::Migration[6.0]
def change
remove_column :types_de_champ, :procedure_id
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: 2020_08_19_153016) do
ActiveRecord::Schema.define(version: 2020_09_02_103047) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -611,7 +611,6 @@ ActiveRecord::Schema.define(version: 2020_08_19_153016) do
t.string "libelle"
t.string "type_champ"
t.integer "order_place"
t.integer "procedure_id"
t.text "description"
t.boolean "mandatory", default: false
t.boolean "private", default: false, null: false
@ -623,7 +622,6 @@ ActiveRecord::Schema.define(version: 2020_08_19_153016) do
t.bigint "revision_id"
t.index ["parent_id"], name: "index_types_de_champ_on_parent_id"
t.index ["private"], name: "index_types_de_champ_on_private"
t.index ["procedure_id"], name: "index_types_de_champ_on_procedure_id"
t.index ["revision_id"], name: "index_types_de_champ_on_revision_id"
t.index ["stable_id"], name: "index_types_de_champ_on_stable_id"
end