diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a0d5a1b7..adbf1e554 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,7 +104,7 @@ jobs: system_tests: name: System tests - runs-on: self-hosted + runs-on: ubuntu-latest env: RUBY_YJIT_ENABLE: "1" services: diff --git a/app/models/champ.rb b/app/models/champ.rb index ebf3fec90..f9a28afe9 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -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] : [] diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index fd5bb3db6..e97357272 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -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 diff --git a/app/tasks/maintenance/fill_champs_stable_id_task.rb b/app/tasks/maintenance/fill_champs_stable_id_task.rb new file mode 100644 index 000000000..e332389be --- /dev/null +++ b/app/tasks/maintenance/fill_champs_stable_id_task.rb @@ -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 diff --git a/db/migrate/20240316065520_champs_add_stable_id.rb b/db/migrate/20240316065520_champs_add_stable_id.rb new file mode 100644 index 000000000..e04f23bb6 --- /dev/null +++ b/db/migrate/20240316065520_champs_add_stable_id.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index a0c5b6233..67699f3f4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/spec/factories/champ.rb b/spec/factories/champ.rb index 57c190de4..6660c730b 100644 --- a/spec/factories/champ.rb +++ b/spec/factories/champ.rb @@ -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 @@ -239,11 +244,12 @@ FactoryBot.define do end factory :champ_engagement_juridique, class: 'Champs::EngagementJuridiqueChamp' do - type_de_champ { association :type_de_champ_engagement_juridique, procedure: dossier.procedure } -end + type_de_champ { association :type_de_champ_engagement_juridique, procedure: dossier.procedure } + end + factory :champ_cojo, class: 'Champs::COJOChamp' do - type_de_champ { association :type_de_champ_cojo, procedure: dossier.procedure } - end + type_de_champ { association :type_de_champ_cojo, procedure: dossier.procedure } + end factory :champ_rnf, class: 'Champs::RNFChamp' do type_de_champ { association :type_de_champ_rnf, procedure: dossier.procedure }