refactor(workspace, users, billing): remove default workspace + rename (#9360)

Replaced user-based parameterization with workspace-focused logic across
seed scripts, mocks, and billing services. Removed redundant `user`
references and standardized to `workspace` to align with updated
business rules. Adjusted mock data and tests to reflect these changes.

Fix https://github.com/twentyhq/twenty/issues/9295
This commit is contained in:
Antoine Moreaux
2025-01-06 12:33:57 +01:00
committed by GitHub
parent 25083e5405
commit 3eb7ec909e
12 changed files with 35 additions and 51 deletions

View File

@ -21,7 +21,7 @@ export const seedCoreSchema = async (
const schemaName = 'core';
await seedWorkspaces(workspaceDataSource, schemaName, workspaceId);
await seedUsers(workspaceDataSource, schemaName, workspaceId);
await seedUsers(workspaceDataSource, schemaName);
await seedUserWorkspaces(workspaceDataSource, schemaName, workspaceId);
};

View File

@ -13,7 +13,6 @@ export const DEMO_SEED_USER_IDS = {
export const seedUsers = async (
workspaceDataSource: DataSource,
schemaName: string,
workspaceId: string,
) => {
await workspaceDataSource
.createQueryBuilder()
@ -56,16 +55,22 @@ export const seedUsers = async (
};
export const deleteUsersByWorkspace = async (
workspaceDataSource: DataSource,
dataSource: DataSource,
schemaName: string,
workspaceId: string,
) => {
await workspaceDataSource
const user = await dataSource
.createQueryBuilder(`${schemaName}.${tableName}`, 'user')
.leftJoinAndSelect('user.workspaces', 'userWorkspace')
.where(`userWorkspace."workspaceId" = :workspaceId`, {
workspaceId,
})
.getMany();
await dataSource
.createQueryBuilder()
.delete()
.from(`${schemaName}.${tableName}`)
.where(`"${tableName}"."defaultWorkspaceId" = :workspaceId`, {
workspaceId,
})
.where(`"${tableName}"."id" IN (:...ids)`, { ids: user.map((u) => u.id) })
.execute();
};

View File

@ -12,7 +12,7 @@ export const seedCoreSchema = async (
const schemaName = 'core';
await seedWorkspaces(workspaceDataSource, schemaName, workspaceId);
await seedUsers(workspaceDataSource, schemaName, workspaceId);
await seedUsers(workspaceDataSource, schemaName);
await seedUserWorkspaces(workspaceDataSource, schemaName, workspaceId);
await seedFeatureFlags(workspaceDataSource, schemaName, workspaceId);
};

View File

@ -1,7 +1,5 @@
import { DataSource } from 'typeorm';
// import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces';
const tableName = 'user';
export const DEV_SEED_USER_IDS = {
@ -13,7 +11,6 @@ export const DEV_SEED_USER_IDS = {
export const seedUsers = async (
workspaceDataSource: DataSource,
schemaName: string,
workspaceId: string,
) => {
await workspaceDataSource
.createQueryBuilder()
@ -54,18 +51,3 @@ export const seedUsers = async (
])
.execute();
};
export const deleteUsersByWorkspace = async (
workspaceDataSource: DataSource,
schemaName: string,
workspaceId: string,
) => {
await workspaceDataSource
.createQueryBuilder()
.delete()
.from(`${schemaName}.${tableName}`)
.where(`"${tableName}"."defaultWorkspaceId" = :workspaceId`, {
workspaceId,
})
.execute();
};