- golem15_journal_image_variants (migration 202610280002): a thumbnail
per width of golem15.journal.image_widths (480, 800, 1200 by default,
never wider than the original) and its WebP copy, with the original's
size
- conga job golem15.journal.image_variants (three attempts), queued after
a featured image upload and after an admin save of a post whose images
lack a width; the upload request never encodes
- journal:image-variants [--all] backfills
- featured_images[].variants {width, height, url, webp_url, source_width,
source_height} on the post answers (additive key)
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package updates
|
|
|
|
import (
|
|
"github.com/go-gormigrate/gormigrate/v2"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// createImageVariants creates golem15_journal_image_variants (P33-43): one
|
|
// row per featured image and width with the thumbnail's key, its WebP
|
|
// copy's key and the original's size. file_id names a system_files row
|
|
// without a foreign key (the plugin's migrations run without the framework
|
|
// tables in its tests); the API deletes the rows with the file, and rows
|
|
// of a file removed elsewhere are never listed.
|
|
var createImageVariants = []*gormigrate.Migration{
|
|
{
|
|
ID: "202610280002_create_golem15_journal_image_variants",
|
|
Migrate: func(tx *gorm.DB) error {
|
|
if err := tx.Exec(`CREATE TABLE golem15_journal_image_variants (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
file_id BIGINT NOT NULL,
|
|
width INTEGER NOT NULL,
|
|
height INTEGER NOT NULL,
|
|
key TEXT NOT NULL,
|
|
webp_key TEXT NOT NULL,
|
|
source_width INTEGER NOT NULL,
|
|
source_height INTEGER NOT NULL,
|
|
created_at TIMESTAMP(0) NULL
|
|
)`).Error; err != nil {
|
|
return err
|
|
}
|
|
return tx.Exec(`CREATE UNIQUE INDEX golem15_journal_image_variants_file_width ON golem15_journal_image_variants (file_id, width)`).Error
|
|
},
|
|
Rollback: func(tx *gorm.DB) error {
|
|
return tx.Exec(`DROP TABLE IF EXISTS golem15_journal_image_variants`).Error
|
|
},
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
Register(createImageVariants...)
|
|
}
|