🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
-- Structured user memory columns on the existing user_memories* tables (lifecycle, context
-- synthesis, dossier and entity links); subscription-account logins per device, per-device account
-- bindings for agents, and workspace visibility for subscription accounts. The new memory tables
-- themselves landed in 0193.
-- Only fast, metadata-level changes on the existing large memory tables: nullable columns (or a
-- constant default) and NOT VALID foreign keys. drizzle runs every pending migration in one
-- transaction, so a plain CREATE INDEX here would hold the ADD COLUMN locks on those tables for the
-- whole index build. Their indexes come in the next migration, created CONCURRENTLY by hand first.
CREATE TABLE IF NOT EXISTS "agent_device_account_bindings" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"agent_id" text NOT NULL,
"user_id" text NOT NULL,
"workspace_id" text,
"device_id" uuid NOT NULL,
"account_id" uuid NOT NULL,
"accessed_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "agent_provider_account_logins" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"account_id" uuid NOT NULL,
"device_id" uuid NOT NULL,
"user_id" text NOT NULL,
"workspace_id" text,
"first_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
"last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,
"accessed_at" timestamp with time zone DEFAULT now() NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
CONSTRAINT "agent_provider_account_logins_account_device_unique" UNIQUE("account_id","device_id")
);--> statement-breakpoint
ALTER TABLE "agent_provider_accounts" ADD COLUMN IF NOT EXISTS "visibility" text DEFAULT 'public' NOT NULL;--> statement-breakpoint
ALTER TABLE "user_memories" ADD COLUMN IF NOT EXISTS "state" text;--> statement-breakpoint
ALTER TABLE "user_memories" ADD COLUMN IF NOT EXISTS "user_locked" boolean DEFAULT false;--> statement-breakpoint
ALTER TABLE "user_memories_activities" ADD COLUMN IF NOT EXISTS "dossier_id" varchar(255);--> statement-breakpoint
ALTER TABLE "user_memories_activities" ADD COLUMN IF NOT EXISTS "injectable" boolean DEFAULT true NOT NULL;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "user_memory_id" varchar(255);--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "now" text;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "next_steps" jsonb;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "open_questions" jsonb;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "first_seen_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "last_evidence_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD COLUMN IF NOT EXISTS "synthesized_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "user_memories_identities" ADD COLUMN IF NOT EXISTS "entity_id" varchar(255);--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD COLUMN IF NOT EXISTS "holder_entity_id" varchar(255);--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD COLUMN IF NOT EXISTS "applies_to_entity_id" varchar(255);--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD COLUMN IF NOT EXISTS "scope" text;--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD COLUMN IF NOT EXISTS "evidence_source" text;--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD COLUMN IF NOT EXISTS "evidence_count" integer DEFAULT 1 NOT NULL;--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD COLUMN IF NOT EXISTS "last_evidence_at" timestamp with time zone;--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" DROP CONSTRAINT IF EXISTS "agent_device_account_bindings_agent_id_agents_id_fk";--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" ADD CONSTRAINT "agent_device_account_bindings_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" DROP CONSTRAINT IF EXISTS "agent_device_account_bindings_user_id_users_id_fk";--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" ADD CONSTRAINT "agent_device_account_bindings_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" DROP CONSTRAINT IF EXISTS "agent_device_account_bindings_workspace_id_workspaces_id_fk";--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" ADD CONSTRAINT "agent_device_account_bindings_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" DROP CONSTRAINT IF EXISTS "agent_device_account_bindings_device_id_devices_id_fk";--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" ADD CONSTRAINT "agent_device_account_bindings_device_id_devices_id_fk" FOREIGN KEY ("device_id") REFERENCES "public"."devices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" DROP CONSTRAINT IF EXISTS "agent_device_account_bindings_account_id_agent_provider_accounts_id_fk";--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" ADD CONSTRAINT "agent_device_account_bindings_account_id_agent_provider_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."agent_provider_accounts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" DROP CONSTRAINT IF EXISTS "agent_device_account_bindings_login_fk";--> statement-breakpoint
ALTER TABLE "agent_device_account_bindings" ADD CONSTRAINT "agent_device_account_bindings_login_fk" FOREIGN KEY ("account_id","device_id") REFERENCES "public"."agent_provider_account_logins"("account_id","device_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" DROP CONSTRAINT IF EXISTS "agent_provider_account_logins_account_id_agent_provider_accounts_id_fk";--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" ADD CONSTRAINT "agent_provider_account_logins_account_id_agent_provider_accounts_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."agent_provider_accounts"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" DROP CONSTRAINT IF EXISTS "agent_provider_account_logins_device_id_devices_id_fk";--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" ADD CONSTRAINT "agent_provider_account_logins_device_id_devices_id_fk" FOREIGN KEY ("device_id") REFERENCES "public"."devices"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" DROP CONSTRAINT IF EXISTS "agent_provider_account_logins_user_id_users_id_fk";--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" ADD CONSTRAINT "agent_provider_account_logins_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" DROP CONSTRAINT IF EXISTS "agent_provider_account_logins_workspace_id_workspaces_id_fk";--> statement-breakpoint
ALTER TABLE "agent_provider_account_logins" ADD CONSTRAINT "agent_provider_account_logins_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "agent_device_account_bindings_agent_device_unique" ON "agent_device_account_bindings" USING btree ("agent_id","device_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_device_account_bindings_device_id_idx" ON "agent_device_account_bindings" USING btree ("device_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_device_account_bindings_account_device_idx" ON "agent_device_account_bindings" USING btree ("account_id","device_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_device_account_bindings_user_id_idx" ON "agent_device_account_bindings" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_device_account_bindings_workspace_id_idx" ON "agent_device_account_bindings" USING btree ("workspace_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_provider_account_logins_device_id_idx" ON "agent_provider_account_logins" USING btree ("device_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_provider_account_logins_user_id_idx" ON "agent_provider_account_logins" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_provider_account_logins_workspace_id_idx" ON "agent_provider_account_logins" USING btree ("workspace_id");--> statement-breakpoint
ALTER TABLE "user_memories_activities" DROP CONSTRAINT IF EXISTS "user_memories_activities_dossier_id_user_memories_dossiers_id_fk";--> statement-breakpoint
ALTER TABLE "user_memories_activities" ADD CONSTRAINT "user_memories_activities_dossier_id_user_memories_dossiers_id_fk" FOREIGN KEY ("dossier_id") REFERENCES "public"."user_memories_dossiers"("id") ON DELETE set null ON UPDATE no action NOT VALID;--> statement-breakpoint
ALTER TABLE "user_memories_contexts" DROP CONSTRAINT IF EXISTS "user_memories_contexts_user_memory_id_user_memories_id_fk";--> statement-breakpoint
ALTER TABLE "user_memories_contexts" ADD CONSTRAINT "user_memories_contexts_user_memory_id_user_memories_id_fk" FOREIGN KEY ("user_memory_id") REFERENCES "public"."user_memories"("id") ON DELETE cascade ON UPDATE no action NOT VALID;--> statement-breakpoint
ALTER TABLE "user_memories_identities" DROP CONSTRAINT IF EXISTS "user_memories_identities_entity_id_user_memories_entities_id_fk";--> statement-breakpoint
ALTER TABLE "user_memories_identities" ADD CONSTRAINT "user_memories_identities_entity_id_user_memories_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."user_memories_entities"("id") ON DELETE set null ON UPDATE no action NOT VALID;--> statement-breakpoint
ALTER TABLE "user_memories_preferences" DROP CONSTRAINT IF EXISTS "user_memories_preferences_holder_entity_id_user_memories_entities_id_fk";--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD CONSTRAINT "user_memories_preferences_holder_entity_id_user_memories_entities_id_fk" FOREIGN KEY ("holder_entity_id") REFERENCES "public"."user_memories_entities"("id") ON DELETE set null ON UPDATE no action NOT VALID;--> statement-breakpoint
ALTER TABLE "user_memories_preferences" DROP CONSTRAINT IF EXISTS "user_memories_preferences_applies_to_entity_id_user_memories_entities_id_fk";--> statement-breakpoint
ALTER TABLE "user_memories_preferences" ADD CONSTRAINT "user_memories_preferences_applies_to_entity_id_user_memories_entities_id_fk" FOREIGN KEY ("applies_to_entity_id") REFERENCES "public"."user_memories_entities"("id") ON DELETE set null ON UPDATE no action NOT VALID;--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "agent_provider_accounts_workspace_visibility_idx" ON "agent_provider_accounts" USING btree ("workspace_id","visibility","user_id");