Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

script(rdvsp): add an export script for checking data coherence with rdvsp #2217

Draft
wants to merge 2 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/export_organisations_rdvsp_ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env ruby

require "json"
require_relative "../config/environment"

organisations_data = Organisation.all.map do |organisation|
{
rdv_solidarites_organisation_id: organisation.rdv_solidarites_organisation_id
}
end

json_data = JSON.pretty_generate(organisations_data)
file_path = Rails.root.join("rdvsp_organisations_ids.json")
File.write(file_path, json_data)

puts "Le fichier JSON a été généré et sauvegardé à l'emplacement suivant : #{file_path}"
25 changes: 25 additions & 0 deletions scripts/export_users_rdvsp_ids.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env ruby

require "json"
require_relative "../config/environment"

# .active n'est pas suffisant car vérifie uniquement le champ deleted_at
# Or on a des usagers qui n'ont pas de deleted_at et qui n'ont pas de rdv_solidarites_user_id Pourquoi ?
# Il faudrait ajouter d'autres scopes si nécessaire
# On a aussi 30 users avec un rdv_solidarites_user_id mais qui n'ont pas d'organisation en prod ? (on les skip ligne 13)

users_data = User.active.where.not(rdv_solidarites_user_id: nil).includes(:organisations).map do |user|
rdv_solidarites_organisation_ids = user.organisations.pluck(:rdv_solidarites_organisation_id)
next if rdv_solidarites_organisation_ids.empty?

{
rdv_solidarites_user_id: user.rdv_solidarites_user_id,
rdv_solidarites_organisation_ids: rdv_solidarites_organisation_ids
}
end.compact

json_data = JSON.pretty_generate(users_data)
file_path = Rails.root.join("rdvsp_users_ids.json")
File.write(file_path, json_data)

puts "Le fichier JSON a été généré et sauvegardé à l'emplacement suivant : #{file_path}"
Loading