trading-app/drizzle/0000_init.sql
David 27a358038a
Some checks failed
Tick / tick (push) Failing after 1s
Cagnotte V1: IA news-driven trading sim, sandbox, PEA tracking, PWA
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 19:06:17 +01:00

147 lines
4.4 KiB
SQL

CREATE TABLE "actions" (
"id" serial PRIMARY KEY NOT NULL,
"rendezvous_id" integer NOT NULL,
"kind" text NOT NULL,
"training" boolean NOT NULL,
"symbol" text,
"payload" jsonb NOT NULL,
"status" text DEFAULT 'pending' NOT NULL,
"responded_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "ai_usage" (
"id" serial PRIMARY KEY NOT NULL,
"at" timestamp with time zone DEFAULT now() NOT NULL,
"model" text NOT NULL,
"purpose" text NOT NULL,
"input_tokens" integer NOT NULL,
"output_tokens" integer NOT NULL,
"cost_usd" double precision NOT NULL
);
--> statement-breakpoint
CREATE TABLE "cash_flows" (
"id" serial PRIMARY KEY NOT NULL,
"portfolio_id" text NOT NULL,
"amount" double precision NOT NULL,
"kind" text NOT NULL,
"date" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "equity_snapshots" (
"id" serial PRIMARY KEY NOT NULL,
"portfolio_id" text NOT NULL,
"date" text NOT NULL,
"equity" double precision NOT NULL
);
--> statement-breakpoint
CREATE TABLE "kv" (
"key" text PRIMARY KEY NOT NULL,
"value" jsonb NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "news" (
"id" text PRIMARY KEY NOT NULL,
"symbol" text NOT NULL,
"title" text NOT NULL,
"publisher" text,
"url" text,
"published_at" timestamp with time zone NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"triage" jsonb,
"triaged_at" timestamp with time zone,
"alerted_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "orders" (
"id" serial PRIMARY KEY NOT NULL,
"portfolio_id" text NOT NULL,
"symbol" text NOT NULL,
"name" text NOT NULL,
"currency" text NOT NULL,
"side" text NOT NULL,
"type" text NOT NULL,
"limit_price" double precision,
"shares" integer NOT NULL,
"stop_price" double precision,
"target_price" double precision,
"max_exit_date" text,
"position_id" integer,
"signal_id" integer,
"status" text DEFAULT 'pending' NOT NULL,
"valid_until" text,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"filled_at" timestamp with time zone,
"fill_price" double precision,
"note" text
);
--> statement-breakpoint
CREATE TABLE "portfolios" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"initial_cash" double precision NOT NULL,
"cash" double precision NOT NULL,
"high_water_mark" double precision DEFAULT 0 NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "positions" (
"id" serial PRIMARY KEY NOT NULL,
"portfolio_id" text NOT NULL,
"symbol" text NOT NULL,
"name" text NOT NULL,
"currency" text NOT NULL,
"shares" integer NOT NULL,
"entry_price" double precision NOT NULL,
"entry_fx" double precision NOT NULL,
"opened_at" timestamp with time zone NOT NULL,
"stop_price" double precision,
"target_price" double precision,
"max_exit_date" text,
"status" text DEFAULT 'open' NOT NULL,
"closed_at" timestamp with time zone,
"exit_price" double precision,
"exit_fx" double precision,
"exit_reason" text,
"fees_eur" double precision DEFAULT 0 NOT NULL,
"pnl_eur" double precision,
"signal_id" integer
);
--> statement-breakpoint
CREATE TABLE "push_subscriptions" (
"endpoint" text PRIMARY KEY NOT NULL,
"keys" jsonb NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "rendezvous" (
"id" serial PRIMARY KEY NOT NULL,
"date" text NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"summary" text NOT NULL,
"notified_at" timestamp with time zone
);
--> statement-breakpoint
CREATE TABLE "signals" (
"id" serial PRIMARY KEY NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"date" text NOT NULL,
"symbol" text NOT NULL,
"name" text NOT NULL,
"decision" text NOT NULL,
"confidence" integer NOT NULL,
"thesis" text NOT NULL,
"risks" text NOT NULL,
"expected_move_pct" double precision NOT NULL,
"stop_pct" double precision NOT NULL,
"target_pct" double precision NOT NULL,
"horizon_days" integer NOT NULL,
"price_at_signal" double precision NOT NULL,
"currency" text NOT NULL,
"news_ids" jsonb NOT NULL,
"risk_verdict" text
);
--> statement-breakpoint
CREATE UNIQUE INDEX "equity_portfolio_date_idx" ON "equity_snapshots" USING btree ("portfolio_id","date");--> statement-breakpoint
CREATE UNIQUE INDEX "rendezvous_date_idx" ON "rendezvous" USING btree ("date");