mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem
We solved manually some `troubleshooting_entries` table missing data and
mismatches.
- **Rows without slugs.** Some `troubleshooting_entries` rows had no
slug, so no guide could match them and the guides looked "new".
- **Duplicate discussions.** A guide that didn't match its row got a
fresh GitHub discussion, leaving the original behind (sometimes with
extras).
- **Slug mismatch.** The fetch stripped the hash suffix from file names
while the table keeps it, so those guides never matched their rows.
- **Overlapping runs.** The workflow had no concurrency control, so two
runs could both create a discussion for the same guide, and `upsert`
silently overwrote the first run's row.
- **Missing checksums.** Rows without a checksum counted as "changed"
and were re-pushed to GitHub on every run.
- **Weak dry run.** `--dry-run` only printed slugs, so it was hard to
see what a run would actually do.
- **Fragile lookup and duplicated code.** Rows were fetched with every
slug in the URL (`.in('slug', …)`), and both scripts carried their own
copy of the guide reader and checksum.
## Solution
After those steps we applied successfully to the database, we revamp our
existing sync scripts to allow dry runs to make sure the changes we
apply are going to generate the correct impact.
A new improvement to prevent bulk discussion errors on GitHub API.
<!--
## Preview links
If relevant, include links to changed pages for easy review access.
Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.
| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->
<!-- ## Additional context
Optionally add any other context or screenshots.
-->
## Review instructions
_Sadly, we need to merge, and pray..._
## Checklist
Check all before review:
- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [x] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
99 lines
3.0 KiB
TypeScript
99 lines
3.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
computeChecksum,
|
|
describeConflict,
|
|
findTitleConflicts,
|
|
isBlocking,
|
|
type CategoryDiscussion,
|
|
type EntryRow,
|
|
} from './troubleshooting-sync-shared.ts'
|
|
|
|
const discussion = (id: string, title: string): CategoryDiscussion => ({
|
|
id,
|
|
title,
|
|
url: `https://github.com/orgs/supabase/discussions/${id}`,
|
|
})
|
|
|
|
const entry = (id: string, slug: string | null, github_id: string): EntryRow => ({
|
|
id,
|
|
slug,
|
|
github_id,
|
|
github_url: `https://github.com/orgs/supabase/discussions/${github_id}`,
|
|
checksum: null,
|
|
})
|
|
|
|
describe('computeChecksum', () => {
|
|
it('is the sha256 of JSON.stringify({ title, body }), hex encoded', () => {
|
|
// Pinned: sync-troubleshooting-updates.ts compares this against stored
|
|
// values, so changing the formula would mark every guide as changed.
|
|
expect(computeChecksum('Title', 'Body')).toBe(
|
|
'01e5f0f389e0155e1ecc739dbc285466e73240ec3a9a6bc062caec4dd18d536f'
|
|
)
|
|
})
|
|
|
|
it('changes when either the title or the body changes', () => {
|
|
const base = computeChecksum('Title', 'Body')
|
|
expect(computeChecksum('Title!', 'Body')).not.toBe(base)
|
|
expect(computeChecksum('Title', 'Body!')).not.toBe(base)
|
|
})
|
|
|
|
it('does not confuse a title/body boundary shift', () => {
|
|
expect(computeChecksum('ab', 'c')).not.toBe(computeChecksum('a', 'bc'))
|
|
})
|
|
})
|
|
|
|
describe('findTitleConflicts', () => {
|
|
it('finds nothing when no discussion has the title', () => {
|
|
expect(
|
|
findTitleConflicts('New guide', [discussion('1', 'Other guide')], [entry('r1', 'other', '1')])
|
|
).toEqual([])
|
|
})
|
|
|
|
it('flags a discussion no row references as an orphan, and blocks on it', () => {
|
|
const [conflict] = findTitleConflicts('New guide', [discussion('1', 'New guide')], [])
|
|
|
|
expect(conflict.kind).toBe('orphan')
|
|
expect(isBlocking(conflict)).toBe(true)
|
|
})
|
|
|
|
it('flags a discussion owned by a slug-less row, and blocks on it', () => {
|
|
const [conflict] = findTitleConflicts(
|
|
'New guide',
|
|
[discussion('1', 'New guide')],
|
|
[entry('r1', null, '1')]
|
|
)
|
|
|
|
expect(conflict.kind).toBe('slugless-row')
|
|
expect(isBlocking(conflict)).toBe(true)
|
|
expect(describeConflict(conflict)).toContain('backfill')
|
|
})
|
|
|
|
it('only warns when the discussion belongs to a row with a different slug', () => {
|
|
const [conflict] = findTitleConflicts(
|
|
'New guide',
|
|
[discussion('1', 'New guide')],
|
|
[entry('r1', 'some-other-slug', '1')]
|
|
)
|
|
|
|
expect(conflict.kind).toBe('other-slug')
|
|
expect(isBlocking(conflict)).toBe(false)
|
|
})
|
|
|
|
it('compares titles ignoring case and surrounding whitespace', () => {
|
|
const conflicts = findTitleConflicts(' New Guide ', [discussion('1', 'new guide')], [])
|
|
|
|
expect(conflicts).toHaveLength(1)
|
|
})
|
|
|
|
it('reports every discussion that carries the title', () => {
|
|
const conflicts = findTitleConflicts(
|
|
'Dup',
|
|
[discussion('1', 'Dup'), discussion('2', 'Dup'), discussion('3', 'Else')],
|
|
[entry('r1', 'dup', '1')]
|
|
)
|
|
|
|
expect(conflicts.map((c) => c.kind)).toEqual(['other-slug', 'orphan'])
|
|
})
|
|
})
|