0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/migrations/core
Gerhard Schlager 552868bc37 MT: Add files_db schema configuration and generated models
This is part of the uploads rework series. `disco upload` currently writes its
results into `uploads.db`, a hand-written schema where each upload is stashed as
a JSON blob (`uploads.upload`, `optimized_images.optimized_images`). That's hard
to query and doesn't line up with the schema DSL the other databases use.

The replacement is `files.db`, and I want it to store the real Discourse upload
columns instead of a blob, so an ad-hoc `SELECT` actually tells you something. So
I added a `files_db` schema config under the schema DSL and generated its SQL and
models from it.

A few things are deliberately different from `intermediate_db`:

- The conventions are minimal: no `id -> original_id` rename and no
  `*upload*_id -> text` rule. In `files.db` the ids are the real staging
  `Upload#id`/`optimized_images.id` and stay integers, and `upload_id` is a real
  integer foreign key, not a content hash. I only ignore `updated_at` globally and
  make `created_at` not required.
- `uploads` and `optimized_images` mirror the live Discourse tables. On `uploads`
  I ignore `user_id` (always the system user on the staging site; the import step
  assigns the real owner), `access_control_post_id` (staging post id, not
  portable) and `retain_hours` (not meaningful for imported files).
- `upload_results` is synthetic: one row per IntermediateDB `upload_sources` row,
  keyed by the same XXH3 hash. It carries the precomputed per-source markdown,
  the `upload_id` (nullable, since several results dedup onto one upload via sha1,
  and it's NULL when a source was skipped or failed), plus `status` and
  `skip_reason`. Those two are string enums on purpose so `skip_reason =
  'download_error'` stays readable in plain SQL.
- `downloads` is the synthetic download-cache index.

Nothing consumes `files.db` yet. A later PR switches `disco upload` over and
removes the old `uploads_db` schema; here I only add the new schema alongside it.

The generated SQL, models and enums come straight from
`migrations/bin/disco schema generate --db files_db`.
2026-07-10 21:03:14 +02:00
..
bin
config MT: Run conversion steps concurrently and split the heavy ones across cores 2026-07-03 11:48:25 +02:00
db MT: Add files_db schema configuration and generated models 2026-07-10 21:03:14 +02:00
lib MT: Add files_db schema configuration and generated models 2026-07-10 21:03:14 +02:00
spec MT: Rename IntermediateDB uploads table to upload_sources 2026-07-10 20:50:03 +02:00
.rspec
Gemfile
migrations-core.gemspec MT: Run conversion steps concurrently and split the heavy ones across cores 2026-07-03 11:48:25 +02:00