···1-CREATE TABLE `recipes` (
2- `uri` text GENERATED ALWAYS AS ("author_did" || '/' || "rkey") VIRTUAL,
3- `author_did` text NOT NULL,
4- `rkey` text NOT NULL,
5- `image_ref` text,
6- `title` text NOT NULL,
7- `time` integer DEFAULT 0 NOT NULL,
8- `serves` integer,
9- `description` text,
10- `ingredients` text NOT NULL,
11- `ingredients_count` integer GENERATED ALWAYS AS (json_array_length("ingredients")) VIRTUAL,
12- `steps` text NOT NULL,
13- `steps_count` integer GENERATED ALWAYS AS (json_array_length("steps")) VIRTUAL,
14- `created_at` text NOT NULL,
15- PRIMARY KEY(`author_did`, `rkey`)
16-);
···0000000000000000
+46
libs/database/migrations/0000_young_hellcat.sql
···0000000000000000000000000000000000000000000000
···1+CREATE TABLE IF NOT EXISTS "profiles" (
2+ "uri" text GENERATED ALWAYS AS ('at://' || "profiles"."did" || '/blue.recipes.actor.profile/self') STORED,
3+ "cid" text NOT NULL,
4+ "did" text PRIMARY KEY NOT NULL,
5+ "ingested_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL,
6+ "display_name" varchar(640) NOT NULL,
7+ "description" varchar(2500),
8+ "pronouns" varchar(200),
9+ "website" text,
10+ "avatar" text,
11+ "banner" text,
12+ "created_at" text NOT NULL
13+);
14+--> statement-breakpoint
15+CREATE TABLE IF NOT EXISTS "recipes" (
16+ "uri" text GENERATED ALWAYS AS ('at://' || "recipes"."author_did" || '/blue.recipes.feed.recipe/' || "recipes"."rkey") STORED,
17+ "cid" text NOT NULL,
18+ "author_did" text NOT NULL,
19+ "rkey" text NOT NULL,
20+ "image" text,
21+ "title" text NOT NULL,
22+ "time" integer DEFAULT 0 NOT NULL,
23+ "serves" integer,
24+ "description" text,
25+ "ingredients" jsonb NOT NULL,
26+ "ingredients_count" integer GENERATED ALWAYS AS (jsonb_array_length("recipes"."ingredients")) STORED,
27+ "steps" jsonb NOT NULL,
28+ "steps_count" integer GENERATED ALWAYS AS (jsonb_array_length("recipes"."steps")) STORED,
29+ "created_at" text NOT NULL,
30+ "ingested_at" text DEFAULT CURRENT_TIMESTAMP NOT NULL,
31+ CONSTRAINT "recipes_author_did_rkey_pk" PRIMARY KEY("author_did","rkey")
32+);
33+--> statement-breakpoint
34+DO $$ BEGIN
35+ ALTER TABLE "recipes" ADD CONSTRAINT "recipes_author_did_profiles_did_fk" FOREIGN KEY ("author_did") REFERENCES "public"."profiles"("did") ON DELETE cascade ON UPDATE no action;
36+EXCEPTION
37+ WHEN duplicate_object THEN null;
38+END $$;
39+--> statement-breakpoint
40+CREATE INDEX IF NOT EXISTS "profiles_cid_idx" ON "profiles" USING btree ("cid");--> statement-breakpoint
41+CREATE INDEX IF NOT EXISTS "profiles_cat_idx" ON "profiles" USING btree ("created_at");--> statement-breakpoint
42+CREATE INDEX IF NOT EXISTS "profiles_iat_idx" ON "profiles" USING btree ("ingested_at");--> statement-breakpoint
43+CREATE INDEX IF NOT EXISTS "recipes_title_idx" ON "recipes" USING btree ("title");--> statement-breakpoint
44+CREATE INDEX IF NOT EXISTS "recipes_cid_idx" ON "recipes" USING btree ("cid");--> statement-breakpoint
45+CREATE INDEX IF NOT EXISTS "recipes_cat_idx" ON "recipes" USING btree ("created_at");--> statement-breakpoint
46+CREATE INDEX IF NOT EXISTS "recipes_iat_idx" ON "recipes" USING btree ("ingested_at");
-23
libs/database/migrations/0001_past_umar.sql
···1-ALTER TABLE `recipes` RENAME COLUMN "image_ref" TO "image";--> statement-breakpoint
2-CREATE TABLE `profiles` (
3- `uri` text GENERATED ALWAYS AS ('at://' || "did" || '/?/self') VIRTUAL,
4- `did` text PRIMARY KEY NOT NULL,
5- `ingested_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
6- `display_name` text(640) NOT NULL,
7- `description` text(2500),
8- `pronouns` text(200),
9- `website` text,
10- `avatar` text,
11- `banner` text,
12- `created_at` text NOT NULL
13-);
14---> statement-breakpoint
15-CREATE INDEX `profiles_cat_idx` ON `profiles` (`created_at`);--> statement-breakpoint
16-CREATE INDEX `profiles_iat_idx` ON `profiles` (`ingested_at`);--> statement-breakpoint
17-ALTER TABLE `recipes` DROP COLUMN `uri`;--> statement-breakpoint
18-ALTER TABLE `recipes` ADD `uri` text GENERATED ALWAYS AS ('at://' || "author_did" || '/?/' || "rkey") VIRTUAL;--> statement-breakpoint
19-ALTER TABLE `recipes` ADD `ingested_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL;--> statement-breakpoint
20-CREATE INDEX `recipes_title_idx` ON `recipes` (`title`);--> statement-breakpoint
21-CREATE INDEX `recipes_cat_idx` ON `recipes` (`created_at`);--> statement-breakpoint
22-CREATE INDEX `recipes_iat_idx` ON `recipes` (`ingested_at`);--> statement-breakpoint
23-ALTER TABLE `recipes` ALTER COLUMN "author_did" TO "author_did" text NOT NULL REFERENCES profiles(did) ON DELETE cascade ON UPDATE no action;
···00000000000000000000000
-4
libs/database/migrations/0002_cheerful_venom.sql
···1-ALTER TABLE `profiles` DROP COLUMN `uri`;--> statement-breakpoint
2-ALTER TABLE `profiles` ADD `uri` text GENERATED ALWAYS AS ('at://' || "did" || '/blue.recipes.actor.profile/self') VIRTUAL;--> statement-breakpoint
3-ALTER TABLE `recipes` DROP COLUMN `uri`;--> statement-breakpoint
4-ALTER TABLE `recipes` ADD `uri` text GENERATED ALWAYS AS ('at://' || "author_did" || '/blue.recipes.feed.recipe/' || "rkey") VIRTUAL;
···1-ALTER TABLE `profiles` ADD `cid` text NOT NULL;--> statement-breakpoint
2-CREATE INDEX `profiles_cid_idx` ON `profiles` (`cid`);--> statement-breakpoint
3-ALTER TABLE `recipes` ADD `cid` text NOT NULL;--> statement-breakpoint
4-CREATE INDEX `recipes_cid_idx` ON `recipes` (`cid`);