@@ -109,7 +109,7 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
109109 entity_id text NOT NULL, permission_type text NOT NULL);
110110 CREATE TABLE permission_group (id text PRIMARY KEY, organization_id text,
111111 config jsonb, updated_at timestamp);
112- CREATE TABLE workspace_files (id text PRIMARY KEY, entity_type text, entity_id text,
112+ CREATE TABLE workspace_files (id text PRIMARY KEY, project_id text,
113113 workspace_id text, context text NOT NULL, size_bytes bigint, deleted_at timestamp);
114114 CREATE TABLE workspace_file_version (id text PRIMARY KEY,
115115 file_id text REFERENCES workspace_files(id) ON DELETE CASCADE, size_bytes bigint NOT NULL);
@@ -195,9 +195,9 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
195195 await sql `UPDATE workspace SET organization_id = NULL, billed_account_user_id = 'user-b',
196196 storage_used_bytes = 100 WHERE id = 'workspace-a'`
197197 await sql `UPDATE user_stats SET storage_used_bytes = 50 WHERE user_id = 'user-b'`
198- await sql `INSERT INTO workspace_files (id, entity_type, entity_id , workspace_id, context, size_bytes)
199- VALUES ('project-file', 'project', 'project -a', NULL, 'project', 40),
200- ('workspace-file', 'workspace', 'workspace-a' , 'workspace-a', 'workspace', 100)`
198+ await sql `INSERT INTO workspace_files (id, project_id , workspace_id, context, size_bytes)
199+ VALUES ('project-file', 'project-a', NULL, 'project', 40),
200+ ('workspace-file', NULL , 'workspace-a', 'workspace', 100)`
201201 await database . transaction ( ( tx ) =>
202202 changeProjectAndWorkspaceStoragePayersInTx ( tx , {
203203 projectChanges : [
@@ -242,9 +242,9 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
242242 storage_used_bytes = 20 WHERE id = 'workspace-a'`
243243 await sql `INSERT INTO project_workspace (project_id, workspace_id) VALUES ('project-a', 'workspace-a')`
244244 await sql `UPDATE user_stats SET storage_used_bytes = CASE user_id WHEN 'user-a' THEN 40 ELSE 20 END`
245- await sql `INSERT INTO workspace_files (id, entity_type, entity_id , workspace_id, context, size_bytes)
246- VALUES ('project-file', 'project', 'project -a', NULL, 'project', 40),
247- ('workspace-file', 'workspace', 'workspace-a' , 'workspace-a', 'workspace', 20)`
245+ await sql `INSERT INTO workspace_files (id, project_id , workspace_id, context, size_bytes)
246+ VALUES ('project-file', 'project-a', NULL, 'project', 40),
247+ ('workspace-file', NULL , 'workspace-a', 'workspace', 20)`
248248 await database . transaction ( ( tx ) =>
249249 transferWorkspaceProjects ( tx , [ 'workspace-a' ] , 'organization-a' , undefined , [
250250 {
@@ -283,8 +283,8 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
283283 await sql `INSERT INTO permissions (id, user_id, entity_type, entity_id, permission_type)
284284 VALUES ('admin', 'user-b', 'workspace', 'workspace-a', 'admin')`
285285 await sql `UPDATE user_stats SET storage_used_bytes = 20 WHERE user_id = 'user-a'`
286- await sql `INSERT INTO workspace_files (id, entity_type, entity_id , workspace_id, context, size_bytes)
287- VALUES ('workspace-file', 'workspace', 'workspace-a' , 'workspace-a', 'workspace', 20)`
286+ await sql `INSERT INTO workspace_files (id, project_id , workspace_id, context, size_bytes)
287+ VALUES ('workspace-file', NULL , 'workspace-a', 'workspace', 20)`
288288 const written = createDeferred < void > ( )
289289 const releaseWrite = createDeferred < void > ( )
290290 const teardownPid = createDeferred < number > ( )
@@ -294,8 +294,8 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
294294 organizationId : null ,
295295 billingEntity : { type : 'user' , id : 'user-a' } ,
296296 } )
297- await tx . execute ( query `INSERT INTO workspace_files (id, entity_type, entity_id , context, size_bytes)
298- VALUES ('project-file', 'project', 'project -a', 'project', 40)` )
297+ await tx . execute ( query `INSERT INTO workspace_files (id, project_id , context, size_bytes)
298+ VALUES ('project-file', 'project-a', 'project', 40)` )
299299 await prepared . applyDelta ( 40 )
300300 written . resolve ( )
301301 await releaseWrite . promise
@@ -341,8 +341,8 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
341341 ...[ 'project-a' , 'project-b' ] . map ( ( projectId ) =>
342342 database . transaction ( async ( tx ) => {
343343 const prepared = await prepareProjectStorageMutationInTx ( tx , context ( projectId , 60 ) )
344- await tx . execute ( query `INSERT INTO workspace_files (id, entity_type, entity_id , context, size_bytes)
345- VALUES (${ projectId } , 'project', ${ projectId } , 'project', 40)` )
344+ await tx . execute ( query `INSERT INTO workspace_files (id, project_id , context, size_bytes)
345+ VALUES (${ projectId } , ${ projectId } , 'project', 40)` )
346346 await prepared . applyDelta ( 40 )
347347 } )
348348 ) ,
@@ -404,7 +404,7 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
404404 await database . transaction ( async ( tx ) => {
405405 const prepared = await prepareProjectStorageMutationInTx ( tx , context ( ) )
406406 await tx . execute (
407- query `INSERT INTO workspace_files VALUES ('file', 'project', 'project -a', NULL, 'project', 100, NULL)`
407+ query `INSERT INTO workspace_files VALUES ('file', 'project-a', NULL, 'project', 100, NULL)`
408408 )
409409 await tx . execute ( query `INSERT INTO workspace_file_version VALUES ('version', 'file', 500)` )
410410 await prepared . applyDelta ( 100 )
@@ -442,9 +442,9 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
442442 'moves exact Project heads once across payers, including archived heads but excluding versions' ,
443443 async ( ) => {
444444 await sql `INSERT INTO workspace_files VALUES
445- ('active', 'project', 'project -a', NULL, 'project', 40, NULL),
446- ('archived', 'project', 'project -a', NULL, 'project', 60, now()),
447- ('other', 'project', 'project -b', NULL, 'project', 25, NULL)`
445+ ('active', 'project-a', NULL, 'project', 40, NULL),
446+ ('archived', 'project-a', NULL, 'project', 60, now()),
447+ ('other', 'project-b', NULL, 'project', 25, NULL)`
448448 await sql `INSERT INTO workspace_file_version VALUES ('version', 'active', 900)`
449449 await sql `UPDATE organization SET storage_used_bytes = 125 WHERE id = 'organization-a'`
450450 await database . transaction ( ( tx ) =>
@@ -485,10 +485,10 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
485485 'reconciliation adds Project heads once and refuses incomplete canonical size metadata' ,
486486 async ( ) => {
487487 await sql `INSERT INTO workspace_files VALUES
488- ('workspace-file', 'workspace', 'workspace-a' , 'workspace-a', 'workspace', 20, NULL),
489- ('project-file', 'project', 'project -a', NULL, 'project', 40, NULL),
490- ('archived', 'project', 'project -a', NULL, 'project', 60, now()),
491- ('chat', NULL, NULL, 'workspace-a', 'mothership', 999, NULL)`
488+ ('workspace-file', NULL , 'workspace-a', 'workspace', 20, NULL),
489+ ('project-file', 'project-a', NULL, 'project', 40, NULL),
490+ ('archived', 'project-a', NULL, 'project', 60, now()),
491+ ('chat', NULL, 'workspace-a', 'mothership', 999, NULL)`
492492 await sql `INSERT INTO workspace_file_version VALUES ('version', 'project-file', 900)`
493493 const store = createPostgresStorageReconciliationStore ( sql )
494494 await store . reconcileWorkspaces ( [ 'workspace-a' ] )
@@ -512,7 +512,7 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
512512 const write = database . transaction ( async ( tx ) => {
513513 const prepared = await prepareProjectStorageMutationInTx ( tx , context ( ) )
514514 await tx . execute (
515- query `INSERT INTO workspace_files VALUES ('file', 'project', 'project -a', NULL, 'project', 40, NULL)`
515+ query `INSERT INTO workspace_files VALUES ('file', 'project-a', NULL, 'project', 40, NULL)`
516516 )
517517 await prepared . applyDelta ( 40 )
518518 changed . resolve ( )
@@ -549,7 +549,7 @@ describe('Project storage admission, transfer, and reconciliation in PostgreSQL'
549549 const write = database . transaction ( async ( tx ) => {
550550 const prepared = await prepareProjectStorageMutationInTx ( tx , context ( ) )
551551 await tx . execute (
552- query `INSERT INTO workspace_files VALUES ('file', 'project', 'project -a', NULL, 'project', 40, NULL)`
552+ query `INSERT INTO workspace_files VALUES ('file', 'project-a', NULL, 'project', 40, NULL)`
553553 )
554554 await prepared . applyDelta ( 40 )
555555 changed . resolve ( )
0 commit comments