diff --git a/db/migrate/20240627142613_create_content_block_documents.rb b/db/migrate/20240627142613_create_content_block_documents.rb new file mode 100644 index 00000000000..c7a06f2905a --- /dev/null +++ b/db/migrate/20240627142613_create_content_block_documents.rb @@ -0,0 +1,11 @@ +class CreateContentBlockDocuments < ActiveRecord::Migration[7.1] + def change + create_table :content_block_documents do |t| + t.string :content_id + t.string :title + t.string :block_type + t.datetime "created_at", precision: nil + t.datetime "updated_at", precision: nil + end + end +end diff --git a/db/migrate/20240628082636_create_content_block_editions.rb b/db/migrate/20240628082636_create_content_block_editions.rb new file mode 100644 index 00000000000..870136a41c2 --- /dev/null +++ b/db/migrate/20240628082636_create_content_block_editions.rb @@ -0,0 +1,10 @@ +class CreateContentBlockEditions < ActiveRecord::Migration[7.1] + def change + create_table :content_block_editions do |t| + t.json :details, null: false + t.references :content_block_document, index: true, foreign_key: true, null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d56457a226e..d2a7f8b41ed 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.1].define(version: 2024_06_18_164903) do +ActiveRecord::Schema[7.1].define(version: 2024_06_28_082636) do create_table "assets", charset: "utf8mb3", force: :cascade do |t| t.string "asset_manager_id", null: false t.string "variant", null: false @@ -191,6 +191,22 @@ t.index ["contactable_id", "contactable_type"], name: "index_contacts_on_contactable_id_and_contactable_type" end + create_table "content_block_documents", charset: "utf8mb3", force: :cascade do |t| + t.string "content_id" + t.string "title" + t.string "block_type" + t.datetime "created_at", precision: nil + t.datetime "updated_at", precision: nil + end + + create_table "content_block_editions", charset: "utf8mb3", force: :cascade do |t| + t.json "details", null: false + t.bigint "content_block_document_id", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false + t.index ["content_block_document_id"], name: "index_content_block_editions_on_content_block_document_id" + end + create_table "data_migration_records", id: :integer, charset: "utf8mb3", force: :cascade do |t| t.string "version" t.index ["version"], name: "index_data_migration_records_on_version", unique: true @@ -1293,6 +1309,7 @@ t.datetime "updated_at", precision: nil end + add_foreign_key "content_block_editions", "content_block_documents" add_foreign_key "documents", "editions", column: "latest_edition_id", on_update: :cascade, on_delete: :nullify add_foreign_key "documents", "editions", column: "live_edition_id", on_update: :cascade, on_delete: :nullify add_foreign_key "link_checker_api_report_links", "link_checker_api_reports" diff --git a/docs/diagrams/object_store_models.png b/docs/diagrams/object_store_models.png new file mode 100644 index 00000000000..ff6361b8084 Binary files /dev/null and b/docs/diagrams/object_store_models.png differ diff --git a/docs/diagrams/object_store_models.puml b/docs/diagrams/object_store_models.puml new file mode 100644 index 00000000000..a2c6603dbe0 --- /dev/null +++ b/docs/diagrams/object_store_models.puml @@ -0,0 +1,25 @@ +@startuml object_store_models +allowmixing +hide empty description + +together { + class ContentBlockDocument { + content_id + block_type + title + } + database content_block_documents + ContentBlockDocument .> content_block_documents +} + +together { + class ContentBlockEdition { + details + } + database content_block_editions + ContentBlockEdition .> content_block_editions +} + +ContentBlockDocument *-r- ContentBlockEdition : "has_many" + +@enduml diff --git a/lib/engines/content_object_store/app/models/content_object_store/content_block_document.rb b/lib/engines/content_object_store/app/models/content_object_store/content_block_document.rb new file mode 100644 index 00000000000..ddf3b949b4c --- /dev/null +++ b/lib/engines/content_object_store/app/models/content_object_store/content_block_document.rb @@ -0,0 +1,5 @@ +class ContentObjectStore::ContentBlockDocument < ApplicationRecord + has_many :content_block_editions, + -> { order(created_at: :asc, id: :asc) }, + inverse_of: :content_block_document +end diff --git a/lib/engines/content_object_store/app/models/content_object_store/content_block_edition.rb b/lib/engines/content_object_store/app/models/content_object_store/content_block_edition.rb new file mode 100644 index 00000000000..edff743b7a7 --- /dev/null +++ b/lib/engines/content_object_store/app/models/content_object_store/content_block_edition.rb @@ -0,0 +1,2 @@ +class ContentObjectStore::ContentBlockEdition < ApplicationRecord +end diff --git a/lib/engines/content_object_store/test/factories/content_block_document.rb b/lib/engines/content_object_store/test/factories/content_block_document.rb new file mode 100644 index 00000000000..428c1be3fe8 --- /dev/null +++ b/lib/engines/content_object_store/test/factories/content_block_document.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :content_block_document, class: "ContentObjectStore::ContentBlockDocument" do + sequence(:content_id) { SecureRandom.uuid } + title { "Title" } + block_type { "Type" } + created_at { Time.zone.now.utc } + updated_at { Time.zone.now.utc } + end +end diff --git a/lib/engines/content_object_store/test/factories/content_block_edition.rb b/lib/engines/content_object_store/test/factories/content_block_edition.rb new file mode 100644 index 00000000000..fbc54a609c3 --- /dev/null +++ b/lib/engines/content_object_store/test/factories/content_block_edition.rb @@ -0,0 +1,7 @@ +FactoryBot.define do + factory :content_block_edition, class: "ContentObjectStore::ContentBlockEdition" do + details { "{}" } + created_at { Time.zone.now.utc } + updated_at { Time.zone.now.utc } + end +end diff --git a/lib/engines/content_object_store/test/unit/app/models/content_block_document_test.rb b/lib/engines/content_object_store/test/unit/app/models/content_block_document_test.rb new file mode 100644 index 00000000000..f43513c504c --- /dev/null +++ b/lib/engines/content_object_store/test/unit/app/models/content_block_document_test.rb @@ -0,0 +1,20 @@ +require "test_helper" + +class ContentObjectStore::ContentBlockDocumentTest < ActiveSupport::TestCase + test "content_block_document exists with required data" do + content_block_document = create( + :content_block_document, + content_id: "52084b2d-4a52-4e69-ba91-3052b07c7eb6", + title: "Title", + block_type: "Type", + created_at: Time.zone.local(2000, 12, 31, 23, 59, 59).utc, + updated_at: Time.zone.local(2000, 12, 31, 23, 59, 59).utc, + ) + + assert_equal "52084b2d-4a52-4e69-ba91-3052b07c7eb6", content_block_document.content_id + assert_equal "Title", content_block_document.title + assert_equal "Type", content_block_document.block_type + assert_equal Time.zone.local(2000, 12, 31, 23, 59, 59).utc, content_block_document.created_at + assert_equal Time.zone.local(2000, 12, 31, 23, 59, 59).utc, content_block_document.updated_at + end +end diff --git a/lib/engines/content_object_store/test/unit/app/models/content_block_edition_test.rb b/lib/engines/content_object_store/test/unit/app/models/content_block_edition_test.rb new file mode 100644 index 00000000000..d093c066704 --- /dev/null +++ b/lib/engines/content_object_store/test/unit/app/models/content_block_edition_test.rb @@ -0,0 +1,18 @@ +require "test_helper" + +class ContentObjectStore::ContentBlockEditionTest < ActiveSupport::TestCase + test "content_block_edition exists with required data" do + content_block_document = create(:content_block_document) + content_block_edition = create( + :content_block_edition, + content_block_document_id: content_block_document.id, + created_at: Time.zone.local(2000, 12, 31, 23, 59, 59).utc, + updated_at: Time.zone.local(2000, 12, 31, 23, 59, 59).utc, + details: '{ "some_field": "some_content" }', + ) + + assert_equal Time.zone.local(2000, 12, 31, 23, 59, 59).utc, content_block_edition.created_at + assert_equal Time.zone.local(2000, 12, 31, 23, 59, 59).utc, content_block_edition.updated_at + assert_equal '{ "some_field": "some_content" }', content_block_edition.details + end +end