CREATE TABLE "release_size_rules" (
	"quality" "quality" PRIMARY KEY NOT NULL,
	"min_mb_per_minute" numeric(6, 1) NOT NULL,
	"max_mb_per_minute" numeric(6, 1) NOT NULL,
	"atmos_max_mb_per_minute" numeric(6, 1),
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
-- Seeded from percentiles over every probed file in this library that has a
-- real duration, so the table starts out describing the collection it governs:
--
--    quality      n     p05     p50     p90     p95     p99      max
--    sd        3604     6.1    15.2    16.0    17.0    18.5     45.7
--    720p      9958     3.4     7.7    18.0    19.1    25.5     55.3
--    1080p     9184     8.3    19.6    48.7    61.9   104.8    237.9
--    4k         449    30.3    92.2   154.4   184.1   233.4    264.5
--
-- 1080p is capped at 60 rather than the 40 the film numbers alone suggest:
-- television runs hotter than film at 1080p (median 24.1 against 15.9), and 40
-- would have refused 1,602 files already held, 1,569 of them television.
INSERT INTO "release_size_rules"
  ("quality", "min_mb_per_minute", "max_mb_per_minute", "atmos_max_mb_per_minute")
VALUES
  ('sd',     2,  20, NULL),
  ('720p',   2,  20, NULL),
  ('1080p',  4,  60, NULL),
  ('4k',    16, 160, 240)
ON CONFLICT ("quality") DO NOTHING;
