0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/migrations/tooling/config/schema/intermediate_db/tables/embed_uploads.rb
Gerhard Schlager 4032dc2b05 MT: Rework the embed linkage tables around an embed owner
The post_* linkage tables from #41177 become embed_* tables keyed by
(owner_type, owner_id), because placeholders will also live in user
bios and group/category/badge descriptions later. On top of the rename:

- quotes carry source coordinates (topic id + post number) and links a
  typed target, so the importer can resolve both once the id maps exist
- new hashtag and emoji linkage tables; mention_type, hashtag_type and
  link_target become integer enums and the string MentionType is gone
- EmbedBuffer records for one owner kind, PlaceholderResolver resolves
  and renders per owner and reports unresolved embeds and orphaned
  placeholders
- the posts and custom_emojis tables stay ignored until their
  conversion steps land in a follow-up PR
- the lazy source-name lookups (users, groups, categories with their
  slug paths, synonym-folded tags) live in their own NameResolver, and
  the resolver spec is split by phase under placeholder_resolver/
2026-07-22 12:56:54 +02:00

29 lines
1.4 KiB
Ruby
Vendored

# frozen_string_literal: true
# Upload embeds. `upload_id` points at a row in the `uploads` table. The importer
# reads that upload's `upload://...` markdown from the uploads store and puts it in
# the owner's markdown. `placeholder` holds the token spliced into the owner's
# markdown (a post body today, a user bio etc. later); see `Migrations::Placeholder`.
# `owner_type`/`owner_id` name that owning record.
#
# `original_markdown` is the verbatim source snippet for an upload referenced by a
# full URL (e.g. `/uploads/.../<sha1>.png`), nil for a short `upload://` reference.
# When the sha1 maps to no Discourse upload, the importer puts this snippet back
# unchanged instead of dropping the embed — a hotlink to another forum's upload then
# survives as-is.
#
# NOTE: `upload_id` is `:text`, not `:numeric`. Upload `original_id`s in the
# IntermediateDB are content hashes (see `uploads.id`, also `:text`). This matches
# the global `.*upload.*_id$ => :text` convention, so the reference must be text too.
# `original_markdown` is not an id, so the convention does not apply to it.
Migrations::Tooling::Schema.table :embed_uploads do
synthetic!
add_column :owner_type, :integer, required: true, enum: :embed_owner
add_column :owner_id, :numeric, required: true
add_column :placeholder, :text, required: true
add_column :upload_id, :text
add_column :original_markdown, :text
index :owner_type, :owner_id
end