mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-08 22:48:14 -05:00
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:
19
packages/db/migrations/0102_eminent_amphibian.sql
Normal file
19
packages/db/migrations/0102_eminent_amphibian.sql
Normal 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");
|
||||
7250
packages/db/migrations/meta/0102_snapshot.json
Normal file
7250
packages/db/migrations/meta/0102_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -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', [
|
||||
|
||||
Reference in New Issue
Block a user