-- Your SQL goes here
CREATE TABLE IF NOT EXISTS public.media_type (
  id serial NOT NULL,
  type_name character varying(255) NOT NULL,
  description text NOT NULL DEFAULT '',
  CONSTRAINT media_type_pkey PRIMARY KEY (id)
);


CREATE TABLE IF NOT EXISTS public.media_format (
  id serial NOT NULL,
  is_physical boolean NOT NULL DEFAULT false,
  format_name character varying(255) NOT NULL,
  description text NOT NULL DEFAULT '',
  CONSTRAINT media_format_pk PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS public.media_type_format_link (
  media_type_id integer NOT NULL,
  media_format_id integer NOT NULL,
  CONSTRAINT media_type_format_link_pk PRIMARY KEY (media_type_id, media_format_id),
  CONSTRAINT media_type_format_link_format_fk FOREIGN KEY (media_format_id)
      REFERENCES public.media_format (id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE,
  CONSTRAINT media_type_format_link_type_fk FOREIGN KEY (media_type_id)
      REFERENCES public.media_type (id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE
);