Merge pull request #10109 from tchak/refactor-champs-add-stable_id

add stable_id and stream
This commit is contained in:
Paul Chavard 2024-03-18 11:00:16 +00:00 committed by GitHub
commit 003e73e853
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 37 additions and 8 deletions

View file

@ -104,7 +104,7 @@ jobs:
system_tests:
name: System tests
runs-on: self-hosted
runs-on: ubuntu-latest
env:
RUBY_YJIT_ENABLE: "1"
services:

View file

@ -221,7 +221,7 @@ class Champ < ApplicationRecord
end
def clone(fork = false)
champ_attributes = [:parent_id, :private, :row_id, :type, :type_de_champ_id]
champ_attributes = [:parent_id, :private, :row_id, :type, :type_de_champ_id, :stable_id, :stream]
value_attributes = fork || !private? ? [:value, :value_json, :data, :external_id] : []
relationships = fork || !private? ? [:etablissement, :geo_areas] : []

View file

@ -250,7 +250,9 @@ class TypeDeChamp < ApplicationRecord
def params_for_champ
{
private: private?,
type: "Champs::#{type_champ.classify}Champ"
type: "Champs::#{type_champ.classify}Champ",
stable_id:,
stream: 'main'
}
end

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
module Maintenance
class FillChampsStableIdTask < MaintenanceTasks::Task
def collection
Champ.includes(:type_de_champ)
end
def process(champ)
champ.update_columns(stable_id: champ.stable_id, stream: 'main')
end
end
end

View file

@ -0,0 +1,6 @@
class ChampsAddStableId < ActiveRecord::Migration[7.0]
def change
add_column :champs, :stable_id, :bigint
add_column :champs, :stream, :string
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2024_02_27_163855) do
ActiveRecord::Schema[7.0].define(version: 2024_03_16_065520) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@ -263,6 +263,8 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_27_163855) do
t.boolean "private", default: false, null: false
t.datetime "rebased_at", precision: nil
t.string "row_id"
t.bigint "stable_id"
t.string "stream"
t.string "type"
t.integer "type_de_champ_id"
t.datetime "updated_at", precision: nil

View file

@ -1,10 +1,15 @@
FactoryBot.define do
factory :champ do
stream { 'main' }
add_attribute(:private) { false }
dossier { association :dossier }
type_de_champ { association :type_de_champ, procedure: dossier.procedure }
after(:build) do |champ, _evaluator|
champ.stable_id = champ.type_de_champ.stable_id
end
trait :private do
add_attribute(:private) { true }
end
@ -240,7 +245,8 @@ FactoryBot.define do
factory :champ_engagement_juridique, class: 'Champs::EngagementJuridiqueChamp' do
type_de_champ { association :type_de_champ_engagement_juridique, procedure: dossier.procedure }
end
end
factory :champ_cojo, class: 'Champs::COJOChamp' do
type_de_champ { association :type_de_champ_cojo, procedure: dossier.procedure }
end