-- Star gift (payments.sendStarsForm + inputInvoiceStarGift): a user spends Stars -- to send another user a gift (a sticker-style collectible). Previously -- getStarGifts/getSavedStarGifts returned empty stubs and -- getPaymentForm/sendStarsForm were unregistered. The catalog is a static -- in-memory table synthesized from the seeded animated_emoji (not stored in the -- DB); this table stores "received gift instances". It works with the Stars ledger -- (migration 0009): Debit on send, Credit on conversion back to Stars. -- msg_id is the gift's service-message id in the owner's private chat -- (messageActionStarGift), and is the identity key for save/convert -- (corresponding to inputSavedStarGiftUser.msg_id). CREATE TABLE public.user_star_gifts ( id bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, owner_user_id bigint NOT NULL, from_user_id bigint DEFAULT 0 NOT NULL, gift_id bigint NOT NULL, msg_id integer NOT NULL, gift_date integer DEFAULT 0 NOT NULL, name_hidden boolean DEFAULT false NOT NULL, unsaved boolean DEFAULT false NOT NULL, converted boolean DEFAULT false NOT NULL, convert_stars bigint DEFAULT 0 NOT NULL, message text DEFAULT '' NOT NULL, CONSTRAINT user_star_gifts_pkey PRIMARY KEY (id), CONSTRAINT user_star_gifts_owner_msg_uniq UNIQUE (owner_user_id, msg_id) ); -- getSavedStarGifts keyset pagination by (owner, gift_date DESC, id DESC). CREATE INDEX user_star_gifts_owner_idx ON public.user_star_gifts USING btree (owner_user_id, gift_date DESC, id DESC);