22 lines
960 B
SQL
22 lines
960 B
SQL
-- Homepage banners are independent editorial content. A banner can either
|
|
-- reference a course (and always use its current cover) or use an uploaded
|
|
-- image stored in Bunny Storage.
|
|
create table home_banners (
|
|
id uuid primary key default gen_random_uuid(),
|
|
kind text not null check (kind in ('course', 'custom')),
|
|
course_id uuid references courses(id) on delete cascade,
|
|
image_url text,
|
|
title text not null default '',
|
|
description text not null default '',
|
|
position integer not null check (position > 0),
|
|
created_at timestamptz not null default now(),
|
|
updated_at timestamptz not null default now(),
|
|
constraint home_banners_source_check check (
|
|
(kind = 'course' and course_id is not null and image_url is null) or
|
|
(kind = 'custom' and course_id is null and image_url is not null)
|
|
),
|
|
unique (position)
|
|
);
|
|
|
|
create trigger home_banners_set_updated_at before update on home_banners for each row execute function set_updated_at();
|