CREATE TABLE public.users (
    id         bigint      NOT NULL,
    email      text        NOT NULL,
    created_at timestamptz
);

CREATE TABLE public.orders (
    id      bigint NOT NULL,
    user_id bigint NOT NULL,
    total   numeric(10,2)
);

CREATE TYPE public.order_status AS ENUM ('pending', 'shipped', 'delivered');

CREATE VIEW public.active_users AS
    SELECT id, email FROM public.users WHERE created_at IS NOT NULL;

CREATE FUNCTION public.get_user(p_id bigint) RETURNS public.users
    LANGUAGE sql AS $$ SELECT * FROM public.users WHERE id = p_id $$;

COMMENT ON TABLE public.users IS 'registered application users';
COMMENT ON COLUMN public.users.email IS 'unique login email';
COMMENT ON FUNCTION public.get_user(bigint) IS 'fetch a single user by id';
