diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 1c88b3614b2a140cd5ebe87d360b0d94f8d0fa73..430a7ca6312e781d6a12179fdfe048acd71d27b9 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -26,6 +26,9 @@ class Communication::Website < ApplicationRecord belongs_to :university belongs_to :about, polymorphic: true, optional: true has_many :pages, foreign_key: :communication_website_id + has_one :imported_website, + class_name: 'Communication::Website::Imported::Website', + dependent: :destroy def self.about_types [nil, Research::Journal.name] diff --git a/app/models/communication/website/imported.rb b/app/models/communication/website/imported.rb new file mode 100644 index 0000000000000000000000000000000000000000..1f0a38d5cba2ba932dea24a6facc59dcddd68a81 --- /dev/null +++ b/app/models/communication/website/imported.rb @@ -0,0 +1,5 @@ +module Communication::Website::Imported + def self.table_name_prefix + 'communication_website_imported_' + end +end diff --git a/app/models/communication/website/imported/page.rb b/app/models/communication/website/imported/page.rb new file mode 100644 index 0000000000000000000000000000000000000000..9a9c3f2bc993160eb2b1deabcc3f5dc79cc52f36 --- /dev/null +++ b/app/models/communication/website/imported/page.rb @@ -0,0 +1,29 @@ +# == Schema Information +# +# Table name: communication_website_imported_pages +# +# id :uuid not null, primary key +# status :integer default(0) +# created_at :datetime not null +# updated_at :datetime not null +# page_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_pages_on_page_id (page_id) +# index_communication_website_imported_pages_on_university_id (university_id) +# index_communication_website_imported_pages_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => communication_website_pages.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# +class Communication::Website::Imported::Page < ApplicationRecord + belongs_to :university + belongs_to :website, class_name: 'Communication::Website::Imported::Website' + belongs_to :page, class_name: 'Communication::Website::Page' +end diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb new file mode 100644 index 0000000000000000000000000000000000000000..8b5a8b941dc615e1f5566fde8e1ad80940b085fb --- /dev/null +++ b/app/models/communication/website/imported/website.rb @@ -0,0 +1,26 @@ +# == Schema Information +# +# Table name: communication_website_imported_websites +# +# id :uuid not null, primary key +# status :integer default(0) +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_websites_on_university_id (university_id) +# index_communication_website_imported_websites_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_websites.id) +# +class Communication::Website::Imported::Website < ApplicationRecord + belongs_to :university + belongs_to :website, class_name: 'Communication::Website' + has_many :pages, class_name: 'Communication::Website::Imported::Page' +end diff --git a/db/migrate/20211007144642_create_communication_website_imported_websites.rb b/db/migrate/20211007144642_create_communication_website_imported_websites.rb new file mode 100644 index 0000000000000000000000000000000000000000..6970212b25c39385b2fe2c2ad604ba59df8891c4 --- /dev/null +++ b/db/migrate/20211007144642_create_communication_website_imported_websites.rb @@ -0,0 +1,11 @@ +class CreateCommunicationWebsiteImportedWebsites < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_imported_websites, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :website, null: false, foreign_key: {to_table: :communication_websites}, type: :uuid + t.integer :status, default: 0 + + t.timestamps + end + end +end diff --git a/db/migrate/20211007144729_create_communication_website_imported_pages.rb b/db/migrate/20211007144729_create_communication_website_imported_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..76cc159d7591f4dbe84f6fcd038c02dbba918321 --- /dev/null +++ b/db/migrate/20211007144729_create_communication_website_imported_pages.rb @@ -0,0 +1,12 @@ +class CreateCommunicationWebsiteImportedPages < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_imported_pages, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :website, null: false, foreign_key: {to_table: :communication_website_imported_websites}, type: :uuid + t.references :page, null: false, foreign_key: {to_table: :communication_website_pages}, type: :uuid + t.integer :status, default: 0 + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f755ca6a69a15c898dd54f5f90e7a22cc15ada9b..285d783a704bf1ea6b263f1fbffdc33566bdc1cc 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.define(version: 2021_09_22_095252) do +ActiveRecord::Schema.define(version: 2021_10_07_144729) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -66,6 +66,28 @@ ActiveRecord::Schema.define(version: 2021_09_22_095252) do t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" end + create_table "communication_website_imported_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.uuid "page_id", null: false + t.integer "status", default: 0 + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["page_id"], name: "index_communication_website_imported_pages_on_page_id" + t.index ["university_id"], name: "index_communication_website_imported_pages_on_university_id" + t.index ["website_id"], name: "index_communication_website_imported_pages_on_website_id" + end + + create_table "communication_website_imported_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.integer "status", default: 0 + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["university_id"], name: "index_communication_website_imported_websites_on_university_id" + t.index ["website_id"], name: "index_communication_website_imported_websites_on_website_id" + end + create_table "communication_website_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "communication_website_id", null: false @@ -254,6 +276,11 @@ ActiveRecord::Schema.define(version: 2021_09_22_095252) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "administration_qualiopi_indicators", "administration_qualiopi_criterions", column: "criterion_id" + add_foreign_key "communication_website_imported_pages", "communication_website_imported_websites", column: "website_id" + add_foreign_key "communication_website_imported_pages", "communication_website_pages", column: "page_id" + add_foreign_key "communication_website_imported_pages", "universities" + add_foreign_key "communication_website_imported_websites", "communication_websites", column: "website_id" + add_foreign_key "communication_website_imported_websites", "universities" 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" diff --git a/test/fixtures/communication/website/imported/pages.yml b/test/fixtures/communication/website/imported/pages.yml new file mode 100644 index 0000000000000000000000000000000000000000..2a4031ac1ecadf74cdfe87aa419972832dc88d7c --- /dev/null +++ b/test/fixtures/communication/website/imported/pages.yml @@ -0,0 +1,37 @@ +# == Schema Information +# +# Table name: communication_website_imported_pages +# +# id :uuid not null, primary key +# status :integer default(0) +# created_at :datetime not null +# updated_at :datetime not null +# page_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_pages_on_page_id (page_id) +# index_communication_website_imported_pages_on_university_id (university_id) +# index_communication_website_imported_pages_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => communication_website_pages.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + university: one + website: one + page: one + status: 1 + +two: + university: two + website: two + page: two + status: 1 diff --git a/test/fixtures/communication/website/imported/websites.yml b/test/fixtures/communication/website/imported/websites.yml new file mode 100644 index 0000000000000000000000000000000000000000..2d60279b34f9e325e495cee9232a85b7ca48d695 --- /dev/null +++ b/test/fixtures/communication/website/imported/websites.yml @@ -0,0 +1,32 @@ +# == Schema Information +# +# Table name: communication_website_imported_websites +# +# id :uuid not null, primary key +# status :integer default(0) +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_websites_on_university_id (university_id) +# index_communication_website_imported_websites_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_websites.id) +# +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + university: one + website: one + status: 1 + +two: + university: two + website: two + status: 1 diff --git a/test/models/communication/website/imported/page_test.rb b/test/models/communication/website/imported/page_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..ee56cdab46a9825a18bc6659a4c442838a43f253 --- /dev/null +++ b/test/models/communication/website/imported/page_test.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: communication_website_imported_pages +# +# id :uuid not null, primary key +# status :integer default(0) +# created_at :datetime not null +# updated_at :datetime not null +# page_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_pages_on_page_id (page_id) +# index_communication_website_imported_pages_on_university_id (university_id) +# index_communication_website_imported_pages_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (page_id => communication_website_pages.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# +require "test_helper" + +class Communication::Website::Imported::PageTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/communication/website/imported/website_test.rb b/test/models/communication/website/imported/website_test.rb new file mode 100644 index 0000000000000000000000000000000000000000..437dd642b891db9095d2cac3d00a7bf18aa10731 --- /dev/null +++ b/test/models/communication/website/imported/website_test.rb @@ -0,0 +1,28 @@ +# == Schema Information +# +# Table name: communication_website_imported_websites +# +# id :uuid not null, primary key +# status :integer default(0) +# created_at :datetime not null +# updated_at :datetime not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# index_communication_website_imported_websites_on_university_id (university_id) +# index_communication_website_imported_websites_on_website_id (website_id) +# +# Foreign Keys +# +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_websites.id) +# +require "test_helper" + +class Communication::Website::Imported::WebsiteTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end