feat(files): added file manager table, enforce permissions for viewing files (#1766)

* feat(files): added file manager table, enforce permissions for viewing files

* rename types

* cleanup

* cleanup

* confirm local file system works with all contexts

* clean

* remove isAsync

* ignore expiresAt

* add relative imports instead of absolute ones

* absl imports

* remove redundant comments
This commit is contained in:
Waleed
2025-10-29 22:03:27 -07:00
committed by GitHub
parent da30c25efa
commit 48f520b3c7
75 changed files with 10394 additions and 1608 deletions

View File

@@ -0,0 +1,19 @@
CREATE TABLE "workspace_files" (
"id" text PRIMARY KEY NOT NULL,
"key" text NOT NULL,
"user_id" text NOT NULL,
"workspace_id" text,
"context" text NOT NULL,
"original_name" text NOT NULL,
"content_type" text NOT NULL,
"size" integer NOT NULL,
"uploaded_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "workspace_files_key_unique" UNIQUE("key")
);
--> statement-breakpoint
ALTER TABLE "workspace_files" ADD CONSTRAINT "workspace_files_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "workspace_files" ADD CONSTRAINT "workspace_files_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "workspace_files_key_idx" ON "workspace_files" USING btree ("key");--> statement-breakpoint
CREATE INDEX "workspace_files_user_id_idx" ON "workspace_files" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "workspace_files_workspace_id_idx" ON "workspace_files" USING btree ("workspace_id");--> statement-breakpoint
CREATE INDEX "workspace_files_context_idx" ON "workspace_files" USING btree ("context");

File diff suppressed because it is too large Load Diff

View File

@@ -708,6 +708,13 @@
"when": 1761631932261,
"tag": "0101_missing_doc_processing",
"breakpoints": true
},
{
"idx": 102,
"version": "7",
"when": 1761769369858,
"tag": "0102_eminent_amphibian",
"breakpoints": true
}
]
}

View File

@@ -751,6 +751,29 @@ export const workspaceFile = pgTable(
})
)
export const workspaceFiles = pgTable(
'workspace_files',
{
id: text('id').primaryKey(),
key: text('key').notNull().unique(),
userId: text('user_id')
.notNull()
.references(() => user.id, { onDelete: 'cascade' }),
workspaceId: text('workspace_id').references(() => workspace.id, { onDelete: 'cascade' }),
context: text('context').notNull(), // 'workspace', 'copilot', 'chat', 'knowledge-base', 'profile-pictures', 'general', 'execution'
originalName: text('original_name').notNull(),
contentType: text('content_type').notNull(),
size: integer('size').notNull(),
uploadedAt: timestamp('uploaded_at').notNull().defaultNow(),
},
(table) => ({
keyIdx: index('workspace_files_key_idx').on(table.key),
userIdIdx: index('workspace_files_user_id_idx').on(table.userId),
workspaceIdIdx: index('workspace_files_workspace_id_idx').on(table.workspaceId),
contextIdx: index('workspace_files_context_idx').on(table.context),
})
)
export const permissionTypeEnum = pgEnum('permission_type', ['admin', 'write', 'read'])
export const workspaceInvitationStatusEnum = pgEnum('workspace_invitation_status', [