Renumber article slugs to sequential article-N

One-time PocketBase migration that replaces every article's slug with
article-1, article-2, ... ordered by publishedAt (oldest first),
requested explicitly by the site owner in place of the existing
descriptive slugs.
This commit is contained in:
2026-09-14 14:44:07 +02:00
parent 728e931421
commit bd26cc8ea6
2 changed files with 42 additions and 0 deletions
+7
View File
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.1.1] - 2026-09-14
### Changed
- Renumbered every article's slug to sequential `article-N`, ordered by `publishedAt` (oldest
first), via a one-time PocketBase migration — replaces the previous descriptive slugs at the
owner's explicit request. Not reversible; existing links/indexed URLs using the old slugs now
404.
### Fixed
- Language switch no longer overlaps the header logo on narrow viewports (~390px, e.g. iPhone 14
@@ -0,0 +1,35 @@
/// <reference path="../pb_data/types.d.ts" />
// One-time cleanup: replace every article's slug with a sequential
// "article-N", ordered by publishedAt (oldest first; drafts, which have no
// publishedAt, sort after published articles by creation order). Requested
// explicitly by the site owner, aware this drops the existing descriptive
// slugs and breaks any already-indexed/shared URLs using them.
//
// Two passes with a temporary unique slug in between: assigning final slugs
// in a single pass can collide with another record's current slug that
// hasn't been renamed yet (slug has a unique index).
migrate((app) => {
const articles = app.findAllRecords('articles')
articles.sort((a, b) => {
const publishedA = a.getString('publishedAt')
const publishedB = b.getString('publishedAt')
if (publishedA && publishedB) return publishedA < publishedB ? -1 : publishedA > publishedB ? 1 : 0
if (publishedA) return -1
if (publishedB) return 1
return a.getString('created') < b.getString('created') ? -1 : 1
})
articles.forEach((record) => {
record.set('slug', `migrating-${record.id}`)
app.save(record)
})
articles.forEach((record, index) => {
record.set('slug', `article-${index + 1}`)
app.save(record)
})
}, (_app) => {
// Not reversible: the original slugs aren't recorded anywhere.
})