@@ -23,9 +23,9 @@ export const upsertAdminUser = async (): Promise<void> => {
2323 const { workspaceId, databaseId } =
2424 await ensureOpenOpsTablesWorkspaceAndDatabaseExist ( ) ;
2525
26- await ensureOrganizationExists ( user , workspaceId ) ;
26+ await ensureOrganizationExists ( user ) ;
2727
28- await ensureProjectExists ( user , databaseId ) ;
28+ await ensureProjectExists ( user , databaseId , workspaceId ) ;
2929 }
3030} ;
3131
@@ -97,10 +97,7 @@ async function ensureOpenOpsTablesWorkspaceAndDatabaseExist(): Promise<{
9797 return { workspaceId, databaseId } ;
9898}
9999
100- async function ensureOrganizationExists (
101- user : User ,
102- tablesWorkspaceId : number ,
103- ) : Promise < void > {
100+ async function ensureOrganizationExists ( user : User ) : Promise < void > {
104101 if ( user . organizationId ) {
105102 const existingOrganization = await organizationService . getOne (
106103 user . organizationId ,
@@ -112,19 +109,12 @@ async function ensureOrganizationExists(
112109 ) ;
113110 }
114111
115- if ( existingOrganization . tablesWorkspaceId !== tablesWorkspaceId ) {
116- throw new Error (
117- 'User organization exists but with different tablesWorkspaceId' ,
118- ) ;
119- }
120-
121112 return ;
122113 }
123114
124115 const organization = await organizationService . create ( {
125116 ownerId : user . id ,
126117 name : DEFAULT_ORGANIZATION_NAME ,
127- tablesWorkspaceId,
128118 } ) ;
129119
130120 user . organizationId = organization . id ;
@@ -133,6 +123,7 @@ async function ensureOrganizationExists(
133123async function ensureProjectExists (
134124 user : User ,
135125 databaseId : number ,
126+ workspaceId : number ,
136127) : Promise < void > {
137128 const project = await projectService . getOneForUser ( user ) ;
138129 if ( project ) {
@@ -142,6 +133,12 @@ async function ensureProjectExists(
142133 ) ;
143134 }
144135
136+ if ( project . tablesWorkspaceId !== workspaceId ) {
137+ throw new Error (
138+ 'User project exists but with different tablesWorkspaceId' ,
139+ ) ;
140+ }
141+
145142 return ;
146143 }
147144
@@ -150,6 +147,7 @@ async function ensureProjectExists(
150147 ownerId : user . id ,
151148 organizationId : user . organizationId ! ,
152149 tablesDatabaseId : databaseId ,
150+ tablesWorkspaceId : workspaceId ,
153151 } ) ;
154152}
155153
0 commit comments