Skip to content

docs: add database schema design post - #638

Open
faisalahammad wants to merge 3 commits into
WordPress:developfrom
faisalahammad:docs/391-database-schema-post
Open

faisalahammad wants to merge 3 commits into
WordPress:developfrom
faisalahammad:docs/391-database-schema-post

Conversation

@faisalahammad

Copy link
Copy Markdown

What?

Adds a "Database Schema Design" page to Storybook. It explains how notifications are stored in the v2 tables and why the tables look the way they do. The text is meant as a draft for the Make Core post asked for in #391.

It also updates the "Database Schema" and "Translations" pages so they match the v2 schema.

Refs #391

Depends on #637. This branch is built on top of fix/615-database-schema-v2, so the diff also shows the 2 commits from #637 until that one is merged. Only the last commit (docs: add database schema design post) belongs to this PR.

Why?

#391 asks to review the schema doc, make sure it is up to date, and prepare a post that explains the design. The old docs had a few things that did not match the code anymore, for example a channel role property, a channels table and the title_key / message_key translation idea.

How?

  • New storybook/stories/docs/database-schema-design.md with the post, and databaseSchemaDesign.stories.mdx to show it under Documentation. It covers the flow from emit to the queue, why messages and the queue are split, one message row per locale, why there is no channels table, keys and indexes, dates in UTC, meta as JSON text, text sizes, expiry and cleanup, upgrades, and open questions for feedback.
  • database-schema.md: links to the new page, removes the channel role text and the channels table, fixes the nested meta list and a few wording issues.
  • translations.md: now says the translated text is stored with one message row per locale, and the channel title comes from the registry.

The post says clearly that emitting, snoozing, the repositories and the REST endpoints are still being built, and that v1 installs are not upgraded until #616.

I kept it as "Refs" and not "Fixes", because the post still needs to be published on Make Core.

Testing Instructions

  1. Run npm install and npm run start --workspace=storybook.
  2. Open http://localhost:6006.
  3. Open Documentation > Database Schema Design. The page renders and the links to Database schema v2 #615, Removing the channel title in the messages table #372, Fix the database migration gate and add a v1 → v2 upgrade routine #616 and Prepare a post about the database schema #391 work.
  4. Open Documentation > Database Schema. The intro links to the design page, the meta list is nested, and there is no channel role text.
  5. Open Documentation > Translations. It no longer talks about title_key / message_key.
  6. Compare the columns with the *_v2() methods in includes/database/class-schema.php.

npx wp-scripts lint-md-docs passes on the three markdown files.

Screenshots or screencast

Docs only, no UI changes in the plugin.

- Add v2 table definitions for messages, queue and subscriptions
- messages.id is now auto_increment, channel_title is removed and
  message is text
- queue gets context and created_at, primary key (user_id, message_id)
- subscriptions gets created_at, primary key (user_id, channel_name)
- channel_name is varchar(64) everywhere
- Fresh installs create v2 tables, DB version is now 2
- Add schema tests and update the database schema docs

The v1 schema had no auto_increment on messages.id, so the second
message insert failed with a duplicate key error. The queue and
subscriptions tables also had no primary key, so the same row could
be stored many times. v1 methods are kept for the upgrade in WordPress#616.

Fixes WordPress#615
Drop channel_title, keep expires_at and severity out of meta,
and raise the message limit to TEXT size (65,535 bytes).
Add a Storybook page that explains the v2 schema and the reasons
behind it, as a draft for the Make Core post. Also update the
schema and translations pages so they match the v2 tables.

Refs WordPress#391

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant