From f50904c95811d2d4315cc6155f2c24ba030f51e0 Mon Sep 17 00:00:00 2001 From: Cesium-Ice Date: Wed, 25 Dec 2024 19:10:53 -0800 Subject: [PATCH] fix migration and create rake task --- .../20241224082840_create_locale_languages.rb | 11 ----------- lib/tasks/after_tasks.rake | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/db/migrate/20241224082840_create_locale_languages.rb b/db/migrate/20241224082840_create_locale_languages.rb index 1ffb9aaa0a..e0770da7ff 100644 --- a/db/migrate/20241224082840_create_locale_languages.rb +++ b/db/migrate/20241224082840_create_locale_languages.rb @@ -1,16 +1,5 @@ class CreateLocaleLanguages < ActiveRecord::Migration[7.0] def change ActiveRecord::Base.connection.execute("CREATE TABLE locale_languages LIKE languages;") - - ActiveRecord::Base.connection.execute("INSERT INTO locale_languages SELECT * FROM languages;") - - # Only if you care about the name of the index being consistent - # remove_index :locale_languages, column: [:short], name: "index_languages_on_short" - # remove_index :locale_languages, column: [:sortable_name], name: "index_languages_on_sortable_name" - - # change_table :locale_languages do |t| - # t.index :short - # t.index :sortable_name - # end end end diff --git a/lib/tasks/after_tasks.rake b/lib/tasks/after_tasks.rake index 97340982c2..8da70c43c9 100644 --- a/lib/tasks/after_tasks.rake +++ b/lib/tasks/after_tasks.rake @@ -358,5 +358,19 @@ namespace :After do puts("Admin not found.") end end + + desc "Populate locale_languages table from languages table" + task(populate_locale_languages_table: :environment) do + Language.find_each do |lang| + LocaleLanguage.new do |ll| + ll.name = lang.name + ll.short = lang.short + ll.support_available = lang.support_available + ll.abuse_support_available = lang.abuse_support_available + ll.sortable_name = lang.sortable_name + ll.save + end + end + end # This is the end that you have to put new tasks above. end