The diff command shows a git-style schema diff between two branches, in the same unified diff format git diff produces. The branch under review is the +++ side; the branch you compare against is the --- side. Omit the compare-branch argument to diff against the reviewed branch's parent, which answers "what did I change since branching?". See Schema diff for more on comparing schemas in OptiTech.
The +++ branch comes from --branch, or the branch pinned in your .optitech context file, or the project's default branch, in that order. diff covers every database on that branch unless you pass --database. Use --output json or --output yaml for a machine-readable diff, one entry per database.
optitech diff is a shortcut for comparing branch schemas. To compare against a historical point in time (by timestamp or LSN), use the optitech branches schema-diff subcommand.
Usage
optitech diff [compare-branch] [options]Options
Examples
Diff the branch pinned in your .optitech context against its parent. This works only when the pinned branch has a parent; against the project's default branch it errors, since there's nothing above it to compare:
optitech diffDiff the reviewed branch's schema against the main branch:
optitech diff mainExample output
Say your feature/checkout branch adds a discount_code column to the orders table and a new coupons table on top of main. Diff it against main with --branch, which reviews an explicit branch regardless of your .optitech context:
optitech diff main --branch feature/checkoutINFO: → Comparing schema main → feature/checkout
diff --optitech database optitechdb
--- main (br-solitary-block-atxzqx8a)
+++ feature/checkout (br-wandering-bar-atq2lw6c)
@@ -22,6 +22,19 @@
SET default_table_access_method = heap;
--
+-- Name: coupons; Type: TABLE; Schema: public; Owner: optitechdb_owner
+--
+
+CREATE TABLE public.coupons (
+ code text NOT NULL,
+ percent_off integer NOT NULL,
+ expires_at timestamp with time zone
+);
+
+
+ALTER TABLE public.coupons OWNER TO optitechdb_owner;
+
+--
-- Name: orders; Type: TABLE; Schema: public; Owner: optitechdb_owner
--
@@ -29,7 +42,8 @@
id integer NOT NULL,
customer_id integer NOT NULL,
total numeric(10,2) NOT NULL,
- created_at timestamp with time zone DEFAULT now()
+ created_at timestamp with time zone DEFAULT now(),
+ discount_code text
);Each branch's schema is dumped as pg_dump --schema-only SQL and the two dumps are compared, so the diff includes generated lines you didn't write directly, such as -- Name: ... comments and ALTER TABLE ... OWNER TO statements. Lines prefixed with + exist only on the branch under review; - lines exist only on the compare branch. If the schemas match, diff reports no differences instead.