Login
You're viewing the m.mtlynch.io public feed.
  • Apr 30, 2022, 2:01 PM

    The last tricky part was writing a SQL migration to populate the sizes of files that were uploaded and stored in the DB before this change. I've never written an update that derives from other data in the DB before, but it wasn't too hard.

    ALTER TABLE entries ADD COLUMN file_size INTEGER;

-- Populate file sizes for legacy entries
UPDATE entries
SET file_size = (
    SELECT SUM(LENGTH(entries_data.chunk)) AS file_size
    FROM
        entries_data
    WHERE
        entries.id = entries_data.id
);
    💬 1🔄 0⭐ 0

Replies