From 23f4d20c7bb18de463d897dca36642d8816dbb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com> Date: Mon, 5 Dec 2022 11:07:05 +0100 Subject: [PATCH] rename table, is current permalink, link => path --- app/models/communication/website/permalink.rb | 9 +++--- .../website/with_dependencies.rb | 4 +-- .../concerns/with_permalink_in_website.rb | 10 +++--- .../application/static/_permalink.html.erb | 6 ++-- ...rename_communication_website_permalinks.rb | 5 +++ ...ent_to_communication_website_permalinks.rb | 5 +++ ...ath_in_communication_website_permalinks.rb | 5 +++ db/schema.rb | 31 ++++++++++--------- 8 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 db/migrate/20221205100139_rename_communication_website_permalinks.rb create mode 100644 db/migrate/20221205100241_add_is_current_to_communication_website_permalinks.rb create mode 100644 db/migrate/20221205100440_rename_link_to_path_in_communication_website_permalinks.rb diff --git a/app/models/communication/website/permalink.rb b/app/models/communication/website/permalink.rb index 662016a1a..fdf9c07ee 100644 --- a/app/models/communication/website/permalink.rb +++ b/app/models/communication/website/permalink.rb @@ -1,10 +1,11 @@ # == Schema Information # -# Table name: communication_website_previous_links +# Table name: communication_website_permalinks # # id :uuid not null, primary key # about_type :string not null -# link :string +# is_current :boolean default(TRUE) +# path :string # created_at :datetime not null # updated_at :datetime not null # about_id :uuid not null @@ -13,8 +14,8 @@ # # Indexes # -# index_communication_website_previous_links_on_university_id (university_id) -# index_communication_website_previous_links_on_website_id (website_id) +# index_communication_website_permalinks_on_university_id (university_id) +# index_communication_website_permalinks_on_website_id (website_id) # # Foreign Keys # diff --git a/app/models/communication/website/with_dependencies.rb b/app/models/communication/website/with_dependencies.rb index 255087ad3..749a4c03d 100644 --- a/app/models/communication/website/with_dependencies.rb +++ b/app/models/communication/website/with_dependencies.rb @@ -23,8 +23,8 @@ module Communication::Website::WithDependencies foreign_key: :communication_website_id, dependent: :destroy - has_many :previous_links, - class_name: "Communication::Website::PreviousLink", + has_many :permalinks, + class_name: "Communication::Website::Permalink", dependent: :destroy end diff --git a/app/models/concerns/with_permalink_in_website.rb b/app/models/concerns/with_permalink_in_website.rb index 78e107e43..51f7698db 100644 --- a/app/models/concerns/with_permalink_in_website.rb +++ b/app/models/concerns/with_permalink_in_website.rb @@ -3,12 +3,12 @@ module WithPermalinkInWebsite included do - has_many :previous_links, - class_name: "Communication::Website::PreviousLink", + has_many :permalinks, + class_name: "Communication::Website::Permalink", as: :about, dependent: :destroy - after_validation :manage_previous_links, on: [:create, :update] + after_validation :manage_permalinks, on: [:create, :update] end @@ -30,13 +30,13 @@ module WithPermalinkInWebsite raw_permalink_in_website(website)&.gsub(':slug', self.slug_was) end - def manage_previous_links + def manage_permalinks websites_for_self.each do |website| old_permalink = previous_permalink_in_website(website) new_permalink = permalink_in_website(website) # If the object had a permalink and now is different, we create a previous link - previous_links.create(website: website, link: old_permalink) if old_permalink.present? && new_permalink != old_permalink + permalinks.create(website: website, path: old_permalink) if old_permalink.present? && new_permalink != old_permalink end end diff --git a/app/views/admin/application/static/_permalink.html.erb b/app/views/admin/application/static/_permalink.html.erb index 32b39f787..f215271c8 100644 --- a/app/views/admin/application/static/_permalink.html.erb +++ b/app/views/admin/application/static/_permalink.html.erb @@ -2,9 +2,9 @@ url: "<%= @about.permalink_in_website(@website) %>" <% if @about&.slug %> slug: "<%= @about.slug %>" <% end %> -<% if @about.previous_links.any? %> +<% if @about.permalinks.any? %> aliases: -<% @about.previous_links.each do |previous_link| %> - - <%= previous_link.link %> +<% @about.permalinks.each do |permalink| %> + - <%= permalink.path %> <% end %> <% end %> diff --git a/db/migrate/20221205100139_rename_communication_website_permalinks.rb b/db/migrate/20221205100139_rename_communication_website_permalinks.rb new file mode 100644 index 000000000..4c057f93e --- /dev/null +++ b/db/migrate/20221205100139_rename_communication_website_permalinks.rb @@ -0,0 +1,5 @@ +class RenameCommunicationWebsitePermalinks < ActiveRecord::Migration[7.0] + def change + rename_table :communication_website_previous_links, :communication_website_permalinks + end +end diff --git a/db/migrate/20221205100241_add_is_current_to_communication_website_permalinks.rb b/db/migrate/20221205100241_add_is_current_to_communication_website_permalinks.rb new file mode 100644 index 000000000..6a44f559f --- /dev/null +++ b/db/migrate/20221205100241_add_is_current_to_communication_website_permalinks.rb @@ -0,0 +1,5 @@ +class AddIsCurrentToCommunicationWebsitePermalinks < ActiveRecord::Migration[7.0] + def change + add_column :communication_website_permalinks, :is_current, :boolean, default: true + end +end diff --git a/db/migrate/20221205100440_rename_link_to_path_in_communication_website_permalinks.rb b/db/migrate/20221205100440_rename_link_to_path_in_communication_website_permalinks.rb new file mode 100644 index 000000000..6cb1fd9f0 --- /dev/null +++ b/db/migrate/20221205100440_rename_link_to_path_in_communication_website_permalinks.rb @@ -0,0 +1,5 @@ +class RenameLinkToPathInCommunicationWebsitePermalinks < ActiveRecord::Migration[7.0] + def change + rename_column :communication_website_permalinks, :link, :path + end +end diff --git a/db/schema.rb b/db/schema.rb index 616cbe6f3..325431fae 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_02_132447) do +ActiveRecord::Schema[7.0].define(version: 2022_12_05_100440) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -328,6 +328,19 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_02_132447) do t.index ["university_id"], name: "index_communication_website_pages_on_university_id" end + create_table "communication_website_permalinks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.string "about_type", null: false + t.uuid "about_id", null: false + t.string "path" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "is_current", default: true + t.index ["university_id"], name: "index_communication_website_permalinks_on_university_id" + t.index ["website_id"], name: "index_communication_website_permalinks_on_website_id" + end + create_table "communication_website_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false @@ -352,18 +365,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_02_132447) do t.index ["university_id"], name: "index_communication_website_posts_on_university_id" end - create_table "communication_website_previous_links", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "university_id", null: false - t.uuid "website_id", null: false - t.string "about_type", null: false - t.uuid "about_id", null: false - t.string "link" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["university_id"], name: "index_communication_website_previous_links_on_university_id" - t.index ["website_id"], name: "index_communication_website_previous_links_on_website_id" - end - create_table "communication_websites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.string "name" @@ -869,11 +870,11 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_02_132447) do add_foreign_key "communication_website_pages", "communication_website_pages", column: "parent_id" add_foreign_key "communication_website_pages", "communication_websites" add_foreign_key "communication_website_pages", "universities" + add_foreign_key "communication_website_permalinks", "communication_websites", column: "website_id" + add_foreign_key "communication_website_permalinks", "universities" add_foreign_key "communication_website_posts", "communication_websites" add_foreign_key "communication_website_posts", "universities" add_foreign_key "communication_website_posts", "university_people", column: "author_id" - add_foreign_key "communication_website_previous_links", "communication_websites", column: "website_id" - add_foreign_key "communication_website_previous_links", "universities" add_foreign_key "communication_websites", "universities" add_foreign_key "education_academic_years", "universities" add_foreign_key "education_cohorts", "education_academic_years", column: "academic_year_id" -- GitLab