Migrate stack to SQLite and set Coolify defaults
This commit is contained in:
190
drizzle/0000_cold_silver_centurion.sql
Normal file
190
drizzle/0000_cold_silver_centurion.sql
Normal file
@@ -0,0 +1,190 @@
|
||||
CREATE TABLE `account` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`accountId` text NOT NULL,
|
||||
`providerId` text NOT NULL,
|
||||
`userId` text NOT NULL,
|
||||
`accessToken` text,
|
||||
`refreshToken` text,
|
||||
`idToken` text,
|
||||
`accessTokenExpiresAt` integer,
|
||||
`refreshTokenExpiresAt` integer,
|
||||
`scope` text,
|
||||
`password` text,
|
||||
`createdAt` integer NOT NULL,
|
||||
`updatedAt` integer NOT NULL,
|
||||
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `account_userId_idx` ON `account` (`userId`);--> statement-breakpoint
|
||||
CREATE TABLE `filing` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`ticker` text NOT NULL,
|
||||
`filing_type` text NOT NULL,
|
||||
`filing_date` text NOT NULL,
|
||||
`accession_number` text NOT NULL,
|
||||
`cik` text NOT NULL,
|
||||
`company_name` text NOT NULL,
|
||||
`filing_url` text,
|
||||
`submission_url` text,
|
||||
`primary_document` text,
|
||||
`metrics` text,
|
||||
`analysis` text,
|
||||
`created_at` text NOT NULL,
|
||||
`updated_at` text NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `filing_accession_uidx` ON `filing` (`accession_number`);--> statement-breakpoint
|
||||
CREATE INDEX `filing_ticker_date_idx` ON `filing` (`ticker`,`filing_date`);--> statement-breakpoint
|
||||
CREATE INDEX `filing_date_idx` ON `filing` (`filing_date`);--> statement-breakpoint
|
||||
CREATE TABLE `filing_link` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`filing_id` integer NOT NULL,
|
||||
`link_type` text NOT NULL,
|
||||
`url` text NOT NULL,
|
||||
`source` text DEFAULT 'sec' NOT NULL,
|
||||
`created_at` text NOT NULL,
|
||||
FOREIGN KEY (`filing_id`) REFERENCES `filing`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `filing_link_unique_uidx` ON `filing_link` (`filing_id`,`url`);--> statement-breakpoint
|
||||
CREATE INDEX `filing_link_filing_idx` ON `filing_link` (`filing_id`);--> statement-breakpoint
|
||||
CREATE TABLE `holding` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
`ticker` text NOT NULL,
|
||||
`shares` numeric NOT NULL,
|
||||
`avg_cost` numeric NOT NULL,
|
||||
`current_price` numeric,
|
||||
`market_value` numeric NOT NULL,
|
||||
`gain_loss` numeric NOT NULL,
|
||||
`gain_loss_pct` numeric NOT NULL,
|
||||
`last_price_at` text,
|
||||
`created_at` text NOT NULL,
|
||||
`updated_at` text NOT NULL,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `holding_user_ticker_uidx` ON `holding` (`user_id`,`ticker`);--> statement-breakpoint
|
||||
CREATE INDEX `holding_user_idx` ON `holding` (`user_id`);--> statement-breakpoint
|
||||
CREATE TABLE `invitation` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`organizationId` text NOT NULL,
|
||||
`email` text NOT NULL,
|
||||
`role` text,
|
||||
`status` text DEFAULT 'pending' NOT NULL,
|
||||
`expiresAt` integer NOT NULL,
|
||||
`createdAt` integer NOT NULL,
|
||||
`inviterId` text NOT NULL,
|
||||
FOREIGN KEY (`organizationId`) REFERENCES `organization`(`id`) ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY (`inviterId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `invitation_organizationId_idx` ON `invitation` (`organizationId`);--> statement-breakpoint
|
||||
CREATE INDEX `invitation_email_idx` ON `invitation` (`email`);--> statement-breakpoint
|
||||
CREATE TABLE `member` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`organizationId` text NOT NULL,
|
||||
`userId` text NOT NULL,
|
||||
`role` text DEFAULT 'member' NOT NULL,
|
||||
`createdAt` integer NOT NULL,
|
||||
FOREIGN KEY (`organizationId`) REFERENCES `organization`(`id`) ON UPDATE no action ON DELETE cascade,
|
||||
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `member_organizationId_idx` ON `member` (`organizationId`);--> statement-breakpoint
|
||||
CREATE INDEX `member_userId_idx` ON `member` (`userId`);--> statement-breakpoint
|
||||
CREATE TABLE `organization` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`slug` text NOT NULL,
|
||||
`logo` text,
|
||||
`createdAt` integer NOT NULL,
|
||||
`metadata` text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `organization_slug_uidx` ON `organization` (`slug`);--> statement-breakpoint
|
||||
CREATE TABLE `portfolio_insight` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
`provider` text NOT NULL,
|
||||
`model` text NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`created_at` text NOT NULL,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `insight_user_created_idx` ON `portfolio_insight` (`user_id`,`created_at`);--> statement-breakpoint
|
||||
CREATE TABLE `session` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`expiresAt` integer NOT NULL,
|
||||
`token` text NOT NULL,
|
||||
`createdAt` integer NOT NULL,
|
||||
`updatedAt` integer NOT NULL,
|
||||
`ipAddress` text,
|
||||
`userAgent` text,
|
||||
`userId` text NOT NULL,
|
||||
`impersonatedBy` text,
|
||||
`activeOrganizationId` text,
|
||||
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `session_token_uidx` ON `session` (`token`);--> statement-breakpoint
|
||||
CREATE INDEX `session_userId_idx` ON `session` (`userId`);--> statement-breakpoint
|
||||
CREATE TABLE `task_run` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
`task_type` text NOT NULL,
|
||||
`status` text NOT NULL,
|
||||
`priority` integer NOT NULL,
|
||||
`payload` text NOT NULL,
|
||||
`result` text,
|
||||
`error` text,
|
||||
`attempts` integer NOT NULL,
|
||||
`max_attempts` integer NOT NULL,
|
||||
`workflow_run_id` text,
|
||||
`created_at` text NOT NULL,
|
||||
`updated_at` text NOT NULL,
|
||||
`finished_at` text,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `task_user_created_idx` ON `task_run` (`user_id`,`created_at`);--> statement-breakpoint
|
||||
CREATE INDEX `task_status_idx` ON `task_run` (`status`);--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `task_workflow_run_uidx` ON `task_run` (`workflow_run_id`);--> statement-breakpoint
|
||||
CREATE TABLE `user` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
`email` text NOT NULL,
|
||||
`emailVerified` integer DEFAULT false NOT NULL,
|
||||
`image` text,
|
||||
`createdAt` integer NOT NULL,
|
||||
`updatedAt` integer NOT NULL,
|
||||
`role` text,
|
||||
`banned` integer DEFAULT false,
|
||||
`banReason` text,
|
||||
`banExpires` integer
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `user_email_uidx` ON `user` (`email`);--> statement-breakpoint
|
||||
CREATE TABLE `verification` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`identifier` text NOT NULL,
|
||||
`value` text NOT NULL,
|
||||
`expiresAt` integer NOT NULL,
|
||||
`createdAt` integer NOT NULL,
|
||||
`updatedAt` integer NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE INDEX `verification_identifier_idx` ON `verification` (`identifier`);--> statement-breakpoint
|
||||
CREATE TABLE `watchlist_item` (
|
||||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`user_id` text NOT NULL,
|
||||
`ticker` text NOT NULL,
|
||||
`company_name` text NOT NULL,
|
||||
`sector` text,
|
||||
`created_at` text NOT NULL,
|
||||
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `watchlist_user_ticker_uidx` ON `watchlist_item` (`user_id`,`ticker`);--> statement-breakpoint
|
||||
CREATE INDEX `watchlist_user_created_idx` ON `watchlist_item` (`user_id`,`created_at`);
|
||||
@@ -1,199 +0,0 @@
|
||||
CREATE TABLE IF NOT EXISTS "account" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"accountId" text NOT NULL,
|
||||
"providerId" text NOT NULL,
|
||||
"userId" text NOT NULL,
|
||||
"accessToken" text,
|
||||
"refreshToken" text,
|
||||
"idToken" text,
|
||||
"accessTokenExpiresAt" timestamp with time zone,
|
||||
"refreshTokenExpiresAt" timestamp with time zone,
|
||||
"scope" text,
|
||||
"password" text,
|
||||
"createdAt" timestamp with time zone NOT NULL,
|
||||
"updatedAt" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "invitation" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organizationId" text NOT NULL,
|
||||
"email" text NOT NULL,
|
||||
"role" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"expiresAt" timestamp with time zone NOT NULL,
|
||||
"createdAt" timestamp with time zone NOT NULL,
|
||||
"inviterId" text NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "member" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"organizationId" text NOT NULL,
|
||||
"userId" text NOT NULL,
|
||||
"role" text DEFAULT 'member' NOT NULL,
|
||||
"createdAt" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "organization" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"slug" text NOT NULL,
|
||||
"logo" text,
|
||||
"createdAt" timestamp with time zone NOT NULL,
|
||||
"metadata" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "session" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"expiresAt" timestamp with time zone NOT NULL,
|
||||
"token" text NOT NULL,
|
||||
"createdAt" timestamp with time zone NOT NULL,
|
||||
"updatedAt" timestamp with time zone NOT NULL,
|
||||
"ipAddress" text,
|
||||
"userAgent" text,
|
||||
"userId" text NOT NULL,
|
||||
"impersonatedBy" text,
|
||||
"activeOrganizationId" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"email" text NOT NULL,
|
||||
"emailVerified" boolean DEFAULT false NOT NULL,
|
||||
"image" text,
|
||||
"createdAt" timestamp with time zone NOT NULL,
|
||||
"updatedAt" timestamp with time zone NOT NULL,
|
||||
"role" text,
|
||||
"banned" boolean DEFAULT false,
|
||||
"banReason" text,
|
||||
"banExpires" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "verification" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"identifier" text NOT NULL,
|
||||
"value" text NOT NULL,
|
||||
"expiresAt" timestamp with time zone NOT NULL,
|
||||
"createdAt" timestamp with time zone NOT NULL,
|
||||
"updatedAt" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DO $$
|
||||
DECLARE
|
||||
m record;
|
||||
BEGIN
|
||||
FOR m IN (
|
||||
SELECT * FROM (
|
||||
VALUES
|
||||
('user', 'email_verified', 'emailVerified'),
|
||||
('user', 'emailverified', 'emailVerified'),
|
||||
('user', 'created_at', 'createdAt'),
|
||||
('user', 'createdat', 'createdAt'),
|
||||
('user', 'updated_at', 'updatedAt'),
|
||||
('user', 'updatedat', 'updatedAt'),
|
||||
('user', 'ban_reason', 'banReason'),
|
||||
('user', 'banreason', 'banReason'),
|
||||
('user', 'ban_expires', 'banExpires'),
|
||||
('user', 'banexpires', 'banExpires'),
|
||||
('organization', 'created_at', 'createdAt'),
|
||||
('organization', 'createdat', 'createdAt'),
|
||||
('session', 'expires_at', 'expiresAt'),
|
||||
('session', 'expiresat', 'expiresAt'),
|
||||
('session', 'created_at', 'createdAt'),
|
||||
('session', 'createdat', 'createdAt'),
|
||||
('session', 'updated_at', 'updatedAt'),
|
||||
('session', 'updatedat', 'updatedAt'),
|
||||
('session', 'ip_address', 'ipAddress'),
|
||||
('session', 'ipaddress', 'ipAddress'),
|
||||
('session', 'user_agent', 'userAgent'),
|
||||
('session', 'useragent', 'userAgent'),
|
||||
('session', 'user_id', 'userId'),
|
||||
('session', 'userid', 'userId'),
|
||||
('session', 'impersonated_by', 'impersonatedBy'),
|
||||
('session', 'impersonatedby', 'impersonatedBy'),
|
||||
('session', 'active_organization_id', 'activeOrganizationId'),
|
||||
('session', 'activeorganizationid', 'activeOrganizationId'),
|
||||
('account', 'account_id', 'accountId'),
|
||||
('account', 'accountid', 'accountId'),
|
||||
('account', 'provider_id', 'providerId'),
|
||||
('account', 'providerid', 'providerId'),
|
||||
('account', 'user_id', 'userId'),
|
||||
('account', 'userid', 'userId'),
|
||||
('account', 'access_token', 'accessToken'),
|
||||
('account', 'accesstoken', 'accessToken'),
|
||||
('account', 'refresh_token', 'refreshToken'),
|
||||
('account', 'refreshtoken', 'refreshToken'),
|
||||
('account', 'id_token', 'idToken'),
|
||||
('account', 'idtoken', 'idToken'),
|
||||
('account', 'access_token_expires_at', 'accessTokenExpiresAt'),
|
||||
('account', 'accesstokenexpiresat', 'accessTokenExpiresAt'),
|
||||
('account', 'refresh_token_expires_at', 'refreshTokenExpiresAt'),
|
||||
('account', 'refreshtokenexpiresat', 'refreshTokenExpiresAt'),
|
||||
('account', 'created_at', 'createdAt'),
|
||||
('account', 'createdat', 'createdAt'),
|
||||
('account', 'updated_at', 'updatedAt'),
|
||||
('account', 'updatedat', 'updatedAt'),
|
||||
('verification', 'expires_at', 'expiresAt'),
|
||||
('verification', 'expiresat', 'expiresAt'),
|
||||
('verification', 'created_at', 'createdAt'),
|
||||
('verification', 'createdat', 'createdAt'),
|
||||
('verification', 'updated_at', 'updatedAt'),
|
||||
('verification', 'updatedat', 'updatedAt'),
|
||||
('member', 'organization_id', 'organizationId'),
|
||||
('member', 'organizationid', 'organizationId'),
|
||||
('member', 'user_id', 'userId'),
|
||||
('member', 'userid', 'userId'),
|
||||
('member', 'created_at', 'createdAt'),
|
||||
('member', 'createdat', 'createdAt'),
|
||||
('invitation', 'organization_id', 'organizationId'),
|
||||
('invitation', 'organizationid', 'organizationId'),
|
||||
('invitation', 'expires_at', 'expiresAt'),
|
||||
('invitation', 'expiresat', 'expiresAt'),
|
||||
('invitation', 'created_at', 'createdAt'),
|
||||
('invitation', 'createdat', 'createdAt'),
|
||||
('invitation', 'inviter_id', 'inviterId'),
|
||||
('invitation', 'inviterid', 'inviterId')
|
||||
) AS rename_map(table_name, old_column, new_column)
|
||||
)
|
||||
LOOP
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = m.table_name
|
||||
AND column_name = m.old_column
|
||||
)
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'public'
|
||||
AND table_name = m.table_name
|
||||
AND column_name = m.new_column
|
||||
) THEN
|
||||
EXECUTE format(
|
||||
'ALTER TABLE %I.%I RENAME COLUMN %I TO %I',
|
||||
'public',
|
||||
m.table_name,
|
||||
m.old_column,
|
||||
m.new_column
|
||||
);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'account_userId_user_id_fk') THEN ALTER TABLE "account" ADD CONSTRAINT "account_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; END IF; END $$;--> statement-breakpoint
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'invitation_organizationId_organization_id_fk') THEN ALTER TABLE "invitation" ADD CONSTRAINT "invitation_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action; END IF; END $$;--> statement-breakpoint
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'invitation_inviterId_user_id_fk') THEN ALTER TABLE "invitation" ADD CONSTRAINT "invitation_inviterId_user_id_fk" FOREIGN KEY ("inviterId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; END IF; END $$;--> statement-breakpoint
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'member_organizationId_organization_id_fk') THEN ALTER TABLE "member" ADD CONSTRAINT "member_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action; END IF; END $$;--> statement-breakpoint
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'member_userId_user_id_fk') THEN ALTER TABLE "member" ADD CONSTRAINT "member_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; END IF; END $$;--> statement-breakpoint
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'session_userId_user_id_fk') THEN ALTER TABLE "session" ADD CONSTRAINT "session_userId_user_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; END IF; END $$;--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "account_userId_idx" ON "account" USING btree ("userId");--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "invitation_organizationId_idx" ON "invitation" USING btree ("organizationId");--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "invitation_email_idx" ON "invitation" USING btree ("email");--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "member_organizationId_idx" ON "member" USING btree ("organizationId");--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "member_userId_idx" ON "member" USING btree ("userId");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "organization_slug_uidx" ON "organization" USING btree ("slug");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "session_token_uidx" ON "session" USING btree ("token");--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "session_userId_idx" ON "session" USING btree ("userId");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "user_email_uidx" ON "user" USING btree ("email");--> statement-breakpoint
|
||||
CREATE INDEX IF NOT EXISTS "verification_identifier_idx" ON "verification" USING btree ("identifier");
|
||||
@@ -1,94 +0,0 @@
|
||||
CREATE TABLE "filing" (
|
||||
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "filing_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"ticker" text NOT NULL,
|
||||
"filing_type" text NOT NULL,
|
||||
"filing_date" text NOT NULL,
|
||||
"accession_number" text NOT NULL,
|
||||
"cik" text NOT NULL,
|
||||
"company_name" text NOT NULL,
|
||||
"filing_url" text,
|
||||
"submission_url" text,
|
||||
"primary_document" text,
|
||||
"metrics" jsonb,
|
||||
"analysis" jsonb,
|
||||
"created_at" timestamp with time zone NOT NULL,
|
||||
"updated_at" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "filing_link" (
|
||||
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "filing_link_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"filing_id" integer NOT NULL,
|
||||
"link_type" text NOT NULL,
|
||||
"url" text NOT NULL,
|
||||
"source" text DEFAULT 'sec' NOT NULL,
|
||||
"created_at" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "holding" (
|
||||
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "holding_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"user_id" text NOT NULL,
|
||||
"ticker" text NOT NULL,
|
||||
"shares" numeric(30, 6) NOT NULL,
|
||||
"avg_cost" numeric(30, 6) NOT NULL,
|
||||
"current_price" numeric(30, 6),
|
||||
"market_value" numeric(30, 2) NOT NULL,
|
||||
"gain_loss" numeric(30, 2) NOT NULL,
|
||||
"gain_loss_pct" numeric(30, 2) NOT NULL,
|
||||
"last_price_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone NOT NULL,
|
||||
"updated_at" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "portfolio_insight" (
|
||||
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "portfolio_insight_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"user_id" text NOT NULL,
|
||||
"provider" text NOT NULL,
|
||||
"model" text NOT NULL,
|
||||
"content" text NOT NULL,
|
||||
"created_at" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "task_run" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"task_type" text NOT NULL,
|
||||
"status" text NOT NULL,
|
||||
"priority" integer NOT NULL,
|
||||
"payload" jsonb NOT NULL,
|
||||
"result" jsonb,
|
||||
"error" text,
|
||||
"attempts" integer NOT NULL,
|
||||
"max_attempts" integer NOT NULL,
|
||||
"workflow_run_id" text,
|
||||
"created_at" timestamp with time zone NOT NULL,
|
||||
"updated_at" timestamp with time zone NOT NULL,
|
||||
"finished_at" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "watchlist_item" (
|
||||
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "watchlist_item_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
||||
"user_id" text NOT NULL,
|
||||
"ticker" text NOT NULL,
|
||||
"company_name" text NOT NULL,
|
||||
"sector" text,
|
||||
"created_at" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "filing_link" ADD CONSTRAINT "filing_link_filing_id_filing_id_fk" FOREIGN KEY ("filing_id") REFERENCES "public"."filing"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "holding" ADD CONSTRAINT "holding_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "portfolio_insight" ADD CONSTRAINT "portfolio_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 "task_run" ADD CONSTRAINT "task_run_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "watchlist_item" ADD CONSTRAINT "watchlist_item_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "filing_accession_uidx" ON "filing" USING btree ("accession_number");--> statement-breakpoint
|
||||
CREATE INDEX "filing_ticker_date_idx" ON "filing" USING btree ("ticker","filing_date");--> statement-breakpoint
|
||||
CREATE INDEX "filing_date_idx" ON "filing" USING btree ("filing_date");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "filing_link_unique_uidx" ON "filing_link" USING btree ("filing_id","url");--> statement-breakpoint
|
||||
CREATE INDEX "filing_link_filing_idx" ON "filing_link" USING btree ("filing_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "holding_user_ticker_uidx" ON "holding" USING btree ("user_id","ticker");--> statement-breakpoint
|
||||
CREATE INDEX "holding_user_idx" ON "holding" USING btree ("user_id");--> statement-breakpoint
|
||||
CREATE INDEX "insight_user_created_idx" ON "portfolio_insight" USING btree ("user_id","created_at");--> statement-breakpoint
|
||||
CREATE INDEX "task_user_created_idx" ON "task_run" USING btree ("user_id","created_at");--> statement-breakpoint
|
||||
CREATE INDEX "task_status_idx" ON "task_run" USING btree ("status");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "task_workflow_run_uidx" ON "task_run" USING btree ("workflow_run_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "watchlist_user_ticker_uidx" ON "watchlist_item" USING btree ("user_id","ticker");--> statement-breakpoint
|
||||
CREATE INDEX "watchlist_user_created_idx" ON "watchlist_item" USING btree ("user_id","created_at");
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,12 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"dialect": "sqlite",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1771967961625,
|
||||
"tag": "0000_tense_centennial",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1772076911227,
|
||||
"tag": "0001_boring_toad",
|
||||
"version": "6",
|
||||
"when": 1772137733427,
|
||||
"tag": "0000_cold_silver_centurion",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user