-- Code generated by stitchql schema generate. DO NOT EDIT. CREATE TABLE authors ( id bigint PRIMARY KEY, name text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now(), CHECK (updated_at >= created_at) ); CREATE TYPE book_status AS ENUM ('draft', 'published', 'out_of_print'); CREATE TABLE books ( id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, title text NOT NULL, author_id bigint NOT NULL REFERENCES authors(id), status book_status NOT NULL DEFAULT 'draft', created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now(), CHECK (updated_at >= created_at) ); CREATE MATERIALIZED VIEW author_book_counts AS SELECT author_id, count(*) AS book_count FROM books GROUP BY author_id WITH NO DATA; CREATE UNIQUE INDEX author_book_counts_author_idx ON author_book_counts(author_id);