aboutsummaryrefslogtreecommitdiffstats
path: root/internal/db/migrations/blog/00010_font_kind.sql
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/migrations/blog/00010_font_kind.sql')
-rw-r--r--internal/db/migrations/blog/00010_font_kind.sql21
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/db/migrations/blog/00010_font_kind.sql b/internal/db/migrations/blog/00010_font_kind.sql
new file mode 100644
index 0000000..cf741e4
--- /dev/null
+++ b/internal/db/migrations/blog/00010_font_kind.sql
@@ -0,0 +1,21 @@
+-- +goose Up
+-- Fonts become a file kind of their own so the design page can offer them.
+ALTER TABLE files DROP CONSTRAINT files_kind_check;
+ALTER TABLE files ADD CONSTRAINT files_kind_check
+ CHECK (kind IN ('image', 'document', 'audio', 'video', 'font', 'archive', 'other'));
+-- Fonts uploaded before this were stored as "other"; the magic bytes tell them
+-- apart (the same signatures the Go sniffer trusts), and substring() reads
+-- only that slice.
+UPDATE files SET kind = 'font', content_type = CASE substring(data from 1 for 4)
+ WHEN '\x774f4632'::bytea THEN 'font/woff2'
+ WHEN '\x774f4646'::bytea THEN 'font/woff'
+ WHEN '\x4f54544f'::bytea THEN 'font/otf'
+ ELSE 'font/ttf' END
+WHERE kind = 'other'
+ AND substring(data from 1 for 4) IN ('\x774f4632'::bytea, '\x774f4646'::bytea, '\x4f54544f'::bytea, '\x00010000'::bytea);
+
+-- +goose Down
+UPDATE files SET kind = 'other', content_type = 'application/octet-stream' WHERE kind = 'font';
+ALTER TABLE files DROP CONSTRAINT files_kind_check;
+ALTER TABLE files ADD CONSTRAINT files_kind_check
+ CHECK (kind IN ('image', 'document', 'audio', 'video', 'archive', 'other'));