CREATE TABLE "budget" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "amount" numeric(15, 2) NOT NULL, "period" text NOT NULL, "category_id" text, "user_id" text NOT NULL, "is_active" boolean DEFAULT true NOT NULL, "alert_threshold" numeric(5, 2) DEFAULT '80.00', "rollover_unused" boolean DEFAULT false NOT NULL, "start_date" timestamp NOT NULL, "end_date" timestamp, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "category" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "type" text NOT NULL, "color" text DEFAULT '#3B82F6' NOT NULL, "icon" text, "parent_id" text, "user_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "financial_account" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "type" text NOT NULL, "balance" numeric(15, 2) DEFAULT '0.00' NOT NULL, "currency" text DEFAULT 'EUR' NOT NULL, "is_active" boolean DEFAULT true NOT NULL, "account_number" text, "bank_name" text, "user_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "financial_insight" ( "id" text PRIMARY KEY NOT NULL, "type" text NOT NULL, "title" text NOT NULL, "message" text NOT NULL, "severity" text DEFAULT 'info' NOT NULL, "data" jsonb, "is_read" boolean DEFAULT false NOT NULL, "user_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "goal" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "description" text, "target_amount" numeric(15, 2) NOT NULL, "current_amount" numeric(15, 2) DEFAULT '0.00' NOT NULL, "target_date" timestamp, "type" text NOT NULL, "priority" text DEFAULT 'medium' NOT NULL, "status" text DEFAULT 'active' NOT NULL, "user_id" text NOT NULL, "account_id" text, "is_recurring" boolean DEFAULT false NOT NULL, "recurring_amount" numeric(15, 2), "recurring_interval" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "report" ( "id" text PRIMARY KEY NOT NULL, "name" text NOT NULL, "type" text NOT NULL, "period" text NOT NULL, "start_date" timestamp NOT NULL, "end_date" timestamp NOT NULL, "data" jsonb NOT NULL, "user_id" text NOT NULL, "created_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "transaction" ( "id" text PRIMARY KEY NOT NULL, "description" text NOT NULL, "amount" numeric(15, 2) NOT NULL, "type" text NOT NULL, "date" timestamp NOT NULL, "category_id" text, "account_id" text NOT NULL, "user_id" text NOT NULL, "is_recurring" boolean DEFAULT false NOT NULL, "recurring_interval" text, "tags" text[], "notes" text, "merchant" text, "location" text, "is_imported" boolean DEFAULT false NOT NULL, "imported_source" text, "created_at" timestamp DEFAULT now() NOT NULL, "updated_at" timestamp DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "budget" ADD CONSTRAINT "budget_category_id_category_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."category"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "budget" ADD CONSTRAINT "budget_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "category" ADD CONSTRAINT "category_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "financial_account" ADD CONSTRAINT "financial_account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "financial_insight" ADD CONSTRAINT "financial_insight_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "goal" ADD CONSTRAINT "goal_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "goal" ADD CONSTRAINT "goal_account_id_financial_account_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."financial_account"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "report" ADD CONSTRAINT "report_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "transaction" ADD CONSTRAINT "transaction_category_id_category_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."category"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "transaction" ADD CONSTRAINT "transaction_account_id_financial_account_id_fk" FOREIGN KEY ("account_id") REFERENCES "public"."financial_account"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "transaction" ADD CONSTRAINT "transaction_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;