From 1f8427c9264b68374a1abcd1a2639117c807e1f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 19 Dec 2022 18:12:09 +0100
Subject: [PATCH] set default language to websites without language

---
 ..._set_default_language_to_communication_websites.rb | 11 +++++++++++
 db/schema.rb                                          |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 db/migrate/20221219170849_set_default_language_to_communication_websites.rb

diff --git a/db/migrate/20221219170849_set_default_language_to_communication_websites.rb b/db/migrate/20221219170849_set_default_language_to_communication_websites.rb
new file mode 100644
index 000000000..cae1de149
--- /dev/null
+++ b/db/migrate/20221219170849_set_default_language_to_communication_websites.rb
@@ -0,0 +1,11 @@
+class SetDefaultLanguageToCommunicationWebsites < ActiveRecord::Migration[7.0]
+  def change
+    # From now on, all websites require at least one language.
+    default_language = Language.find_by(iso_code: "fr")
+    default_language ||= Language.first
+
+    Communication::Website.where.missing(:languages).each do |website|
+      website.update(languages: [default_language], default_language: default_language)
+    end
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 13d83e590..dea20520f 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: 2022_12_16_152525) do
+ActiveRecord::Schema[7.0].define(version: 2022_12_19_170849) do
   # These are extensions that must be enabled in order to support this database
   enable_extension "pgcrypto"
   enable_extension "plpgsql"
-- 
GitLab