* feat: seed companies and people data * init DataSeedDemoWorkspaceCommand to handle: - seedCoreSchema() - seedMetadataSchema() * feature: Seed workspace with demo data - delete workspace - initDemo() with prefillWorkspaceWithDemoObjects() * added companies-demo.ts with data * added people-demo.ts with data * added workspaceId to seedFeatureFlags() * delete previous CoreSchema before seedCoreSchema * added workspaceMemberPrefillData * getDemoWorkspaces() to get DEMO_WORKSPACES from config * defined DemoSeedUserIds - created core/demo/ to keep modified seedCoreSchema() there - DemoSeedUserIds with new set of users and Ids * generateOpportunities() to seed demo opportunities (limit = 50) * Code review and fixes * Fix --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -142,6 +142,23 @@ export const useFindManyRecords = <
|
||||
...fetchMoreResult?.[objectMetadataItem.namePlural]?.edges,
|
||||
]);
|
||||
}
|
||||
onCompleted?.({
|
||||
__typename: `${capitalize(
|
||||
objectMetadataItem.nameSingular,
|
||||
)}Connection`,
|
||||
edges: newEdges,
|
||||
pageInfo:
|
||||
fetchMoreResult?.[objectMetadataItem.namePlural].pageInfo,
|
||||
});
|
||||
|
||||
if (data?.[objectMetadataItem.namePlural]) {
|
||||
setLastCursor(
|
||||
data?.[objectMetadataItem.namePlural]?.pageInfo.endCursor,
|
||||
);
|
||||
setHasNextPage(
|
||||
data?.[objectMetadataItem.namePlural]?.pageInfo.hasNextPage,
|
||||
);
|
||||
}
|
||||
|
||||
return Object.assign({}, prev, {
|
||||
[objectMetadataItem.namePlural]: {
|
||||
@ -171,13 +188,18 @@ export const useFindManyRecords = <
|
||||
}
|
||||
}
|
||||
}, [
|
||||
lastCursor,
|
||||
hasNextPage,
|
||||
setIsFetchingMoreObjects,
|
||||
fetchMore,
|
||||
filter,
|
||||
orderBy,
|
||||
objectMetadataItem,
|
||||
hasNextPage,
|
||||
setIsFetchingMoreObjects,
|
||||
lastCursor,
|
||||
objectMetadataItem.namePlural,
|
||||
objectMetadataItem.nameSingular,
|
||||
onCompleted,
|
||||
data,
|
||||
setLastCursor,
|
||||
setHasNextPage,
|
||||
enqueueSnackBar,
|
||||
]);
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ const StyledPageContainer = styled.div`
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: row;
|
||||
height: 100vh;
|
||||
`;
|
||||
|
||||
const StyledMainContainer = styled.div`
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { ReactNode } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
import { PAGE_BAR_MIN_HEIGHT } from '@/ui/layout/page/PageHeader';
|
||||
import { RightDrawer } from '@/ui/layout/right-drawer/components/RightDrawer';
|
||||
import { MOBILE_VIEWPORT } from '@/ui/theme/constants/theme';
|
||||
|
||||
@ -16,7 +17,9 @@ const StyledMainContainer = styled.div`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: ${({ theme }) => theme.spacing(2)};
|
||||
height: 100%;
|
||||
height: calc(
|
||||
100% - ${({ theme }) => theme.spacing(5)} - ${PAGE_BAR_MIN_HEIGHT}px
|
||||
);
|
||||
padding-bottom: ${({ theme }) => theme.spacing(3)};
|
||||
padding-right: ${({ theme }) => theme.spacing(3)};
|
||||
width: 100%;
|
||||
|
||||
@ -2,6 +2,7 @@ import { useRef } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { RecordTableBodyEffect } from '@/ui/object/record-table/components/RecordTableBodyEffect';
|
||||
import { RecordTableHeader } from '@/ui/object/record-table/components/RecordTableHeader';
|
||||
import { RecordTableInternalEffect } from '@/ui/object/record-table/components/RecordTableInternalEffect';
|
||||
import { useRecordTable } from '@/ui/object/record-table/hooks/useRecordTable';
|
||||
@ -108,6 +109,7 @@ export const RecordTable = ({
|
||||
<div ref={tableBodyRef}>
|
||||
<StyledTable className="entity-table-cell">
|
||||
<RecordTableHeader createRecord={createRecord} />
|
||||
<RecordTableBodyEffect />
|
||||
<RecordTableBody />
|
||||
</StyledTable>
|
||||
<DragSelect
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useInView } from 'react-intersection-observer';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
|
||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
|
||||
import { useObjectRecordTable } from '@/object-record/hooks/useObjectRecordTable';
|
||||
import { isFetchingMoreRecordsFamilyState } from '@/object-record/states/isFetchingMoreRecordsFamilyState';
|
||||
import {
|
||||
RecordTableRow,
|
||||
@ -12,8 +11,8 @@ import {
|
||||
} from '@/ui/object/record-table/components/RecordTableRow';
|
||||
import { RowIdContext } from '@/ui/object/record-table/contexts/RowIdContext';
|
||||
import { RowIndexContext } from '@/ui/object/record-table/contexts/RowIndexContext';
|
||||
import { useRecordTableScopedStates } from '@/ui/object/record-table/hooks/internal/useRecordTableScopedStates';
|
||||
import { isFetchingRecordTableDataState } from '@/ui/object/record-table/states/isFetchingRecordTableDataState';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
import { useRecordTable } from '../hooks/useRecordTable';
|
||||
import { tableRowIdsState } from '../states/tableRowIdsState';
|
||||
@ -24,6 +23,8 @@ export const RecordTableBody = () => {
|
||||
const tableRowIds = useRecoilValue(tableRowIdsState);
|
||||
|
||||
const { scopeId: objectNamePlural } = useRecordTable();
|
||||
const { tableLastRowVisibleState } = useRecordTableScopedStates();
|
||||
const setTableLastRowVisible = useSetRecoilState(tableLastRowVisibleState);
|
||||
|
||||
const { objectNameSingular } = useObjectNameSingularFromPlural({
|
||||
objectNamePlural,
|
||||
@ -42,17 +43,11 @@ export const RecordTableBody = () => {
|
||||
const isFetchingRecordTableData = useRecoilValue(
|
||||
isFetchingRecordTableDataState,
|
||||
);
|
||||
|
||||
// Todo, move this to an effect to not trigger many re-renders
|
||||
const { fetchMoreRecords: fetchMoreObjects } = useObjectRecordTable();
|
||||
const lastRowId = tableRowIds[tableRowIds.length - 1];
|
||||
|
||||
useEffect(() => {
|
||||
if (lastTableRowIsVisible && isDefined(fetchMoreObjects)) {
|
||||
fetchMoreObjects();
|
||||
}
|
||||
}, [lastTableRowIsVisible, fetchMoreObjects]);
|
||||
|
||||
const lastRowId = tableRowIds[tableRowIds.length - 1];
|
||||
setTableLastRowVisible(lastTableRowIsVisible);
|
||||
}, [lastTableRowIsVisible, setTableLastRowVisible]);
|
||||
|
||||
if (isFetchingRecordTableData) {
|
||||
return <></>;
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { useObjectRecordTable } from '@/object-record/hooks/useObjectRecordTable';
|
||||
import { useRecordTableScopedStates } from '@/ui/object/record-table/hooks/internal/useRecordTableScopedStates';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
export const RecordTableBodyEffect = () => {
|
||||
const { fetchMoreRecords: fetchMoreObjects } = useObjectRecordTable();
|
||||
const { tableLastRowVisibleState } = useRecordTableScopedStates();
|
||||
const tableLastRowVisible = useRecoilValue(tableLastRowVisibleState);
|
||||
|
||||
useEffect(() => {
|
||||
if (tableLastRowVisible && isDefined(fetchMoreObjects)) {
|
||||
fetchMoreObjects();
|
||||
}
|
||||
}, [fetchMoreObjects, tableLastRowVisible]);
|
||||
|
||||
return <></>;
|
||||
};
|
||||
@ -24,6 +24,7 @@ export const useRecordTableScopedStates = (args?: {
|
||||
visibleTableColumnsSelector,
|
||||
onEntityCountChangeState,
|
||||
onColumnsChangeState,
|
||||
tableLastRowVisibleState,
|
||||
} = getRecordTableScopedStates({
|
||||
recordTableScopeId: scopeId,
|
||||
});
|
||||
@ -40,5 +41,6 @@ export const useRecordTableScopedStates = (args?: {
|
||||
visibleTableColumnsSelector,
|
||||
onEntityCountChangeState,
|
||||
onColumnsChangeState,
|
||||
tableLastRowVisibleState,
|
||||
};
|
||||
};
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
import { createScopedState } from '@/ui/utilities/recoil-scope/utils/createScopedState';
|
||||
|
||||
export const tableLastRowVisibleScopedState = createScopedState<boolean>({
|
||||
key: 'tableLastRowVisibleScopedState',
|
||||
defaultValue: false,
|
||||
});
|
||||
@ -1,4 +1,5 @@
|
||||
import { objectMetadataConfigScopedState } from '@/ui/object/record-table/states/objectMetadataConfigScopedState';
|
||||
import { tableLastRowVisibleScopedState } from '@/ui/object/record-table/states/tableLastRowVisibleScopedState';
|
||||
import { getScopedState } from '@/ui/utilities/recoil-scope/utils/getScopedState';
|
||||
|
||||
import { availableTableColumnsScopedState } from '../states/availableTableColumnsScopedState';
|
||||
@ -61,6 +62,11 @@ export const getRecordTableScopedStates = ({
|
||||
recordTableScopeId,
|
||||
);
|
||||
|
||||
const tableLastRowVisibleState = getScopedState(
|
||||
tableLastRowVisibleScopedState,
|
||||
recordTableScopeId,
|
||||
);
|
||||
|
||||
return {
|
||||
availableTableColumnsState,
|
||||
tableFiltersState,
|
||||
@ -72,5 +78,6 @@ export const getRecordTableScopedStates = ({
|
||||
visibleTableColumnsSelector,
|
||||
onColumnsChangeState,
|
||||
onEntityCountChangeState,
|
||||
tableLastRowVisibleState,
|
||||
};
|
||||
};
|
||||
|
||||
@ -30,3 +30,4 @@ SIGN_IN_PREFILLED=true
|
||||
# MESSAGE_QUEUE_TYPE=pg-boss
|
||||
# REDIS_HOST=127.0.0.1
|
||||
# REDIS_PORT=6379
|
||||
# DEMO_WORKSPACE_IDS=REPLACE_ME_WITH_A_RANDOM_UUID
|
||||
|
||||
@ -22,11 +22,12 @@
|
||||
"test:e2e": "./scripts/run-integration.sh",
|
||||
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
|
||||
"typeorm:migrate": "yarn typeorm migration:run -d ./src/database/typeorm/metadata/metadata.datasource.ts && yarn typeorm migration:run -d ./src/database/typeorm/core/core.datasource.ts",
|
||||
"database:init": "yarn database:setup && yarn database:seed",
|
||||
"database:init": "yarn database:setup && yarn database:seed:dev",
|
||||
"database:setup": "npx ts-node ./scripts/setup-db.ts && yarn database:migrate",
|
||||
"database:truncate": "npx ts-node ./scripts/truncate-db.ts",
|
||||
"database:migrate": "yarn build && yarn typeorm:migrate",
|
||||
"database:seed": "yarn build && yarn command workspace:seed",
|
||||
"database:seed:dev": "yarn build && yarn command workspace:seed:dev",
|
||||
"database:seed:demo": "yarn build && yarn command workspace:seed:demo",
|
||||
"database:reset": "yarn database:truncate && yarn database:init",
|
||||
"command": "node dist/src/command"
|
||||
},
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
import { Command, CommandRunner } from 'nest-commander';
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import {
|
||||
deleteCoreSchema,
|
||||
seedCoreSchema,
|
||||
} from 'src/database/typeorm-seeds/core/demo';
|
||||
import { EnvironmentService } from 'src/integrations/environment/environment.service';
|
||||
import { WorkspaceManagerService } from 'src/workspace/workspace-manager/workspace-manager.service';
|
||||
|
||||
@Command({
|
||||
name: 'workspace:seed:demo',
|
||||
description:
|
||||
'Seed workspace with demo data. This command is intended for development only.',
|
||||
})
|
||||
export class DataSeedDemoWorkspaceCommand extends CommandRunner {
|
||||
constructor(
|
||||
private readonly environmentService: EnvironmentService,
|
||||
private readonly workspaceManagerService: WorkspaceManagerService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
try {
|
||||
const dataSource = new DataSource({
|
||||
url: this.environmentService.getPGDatabaseUrl(),
|
||||
type: 'postgres',
|
||||
logging: true,
|
||||
schema: 'public',
|
||||
});
|
||||
await dataSource.initialize();
|
||||
const demoWorkspaceIds = this.environmentService.getDemoWorkspaceIds();
|
||||
|
||||
if (demoWorkspaceIds.length === 0) {
|
||||
throw new Error(
|
||||
'Could not get DEMO_WORKSPACE_IDS. Please specify in .env',
|
||||
);
|
||||
}
|
||||
for (const workspaceId of demoWorkspaceIds) {
|
||||
await deleteCoreSchema(dataSource, workspaceId);
|
||||
await this.workspaceManagerService.delete(workspaceId);
|
||||
|
||||
await seedCoreSchema(dataSource, workspaceId);
|
||||
await this.workspaceManagerService.initDemo(workspaceId);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ import { EnvironmentService } from 'src/integrations/environment/environment.ser
|
||||
|
||||
// TODO: implement dry-run
|
||||
@Command({
|
||||
name: 'workspace:seed',
|
||||
name: 'workspace:seed:dev',
|
||||
description:
|
||||
'Seed workspace with initial data. This command is intended for development only.',
|
||||
})
|
||||
@ -45,7 +45,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
});
|
||||
await dataSource.initialize();
|
||||
|
||||
await seedCoreSchema(dataSource);
|
||||
await seedCoreSchema(dataSource, this.workspaceId);
|
||||
await seedMetadataSchema(dataSource);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -7,7 +7,8 @@ import { WorkspaceMigrationModule } from 'src/metadata/workspace-migration/works
|
||||
import { WorkspaceMigrationRunnerModule } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.module';
|
||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||
import { WorkspaceModule } from 'src/core/workspace/workspace.module';
|
||||
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-workspace.command';
|
||||
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-workspace.command';
|
||||
import { DataSeedDemoWorkspaceCommand } from 'src/database/commands/data-seed-demo-workspace.command';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -18,6 +19,10 @@ import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-worksp
|
||||
WorkspaceMigrationRunnerModule,
|
||||
WorkspaceModule,
|
||||
],
|
||||
providers: [DataSeedWorkspaceCommand, ConfirmationQuestion],
|
||||
providers: [
|
||||
DataSeedWorkspaceCommand,
|
||||
DataSeedDemoWorkspaceCommand,
|
||||
ConfirmationQuestion,
|
||||
],
|
||||
})
|
||||
export class DatabaseCommandModule {}
|
||||
|
||||
36
server/src/database/typeorm-seeds/core/demo/feature-flags.ts
Normal file
36
server/src/database/typeorm-seeds/core/demo/feature-flags.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
const tableName = 'featureFlag';
|
||||
|
||||
export const seedFeatureFlags = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, ['key', 'workspaceId', 'value'])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
key: 'IS_RELATION_FIELD_TYPE_ENABLED',
|
||||
workspaceId: workspaceId,
|
||||
value: true,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
|
||||
export const deleteFeatureFlags = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(`${schemaName}.${tableName}`)
|
||||
.where(`"${tableName}"."workspaceId" = :workspaceId`, { workspaceId })
|
||||
.execute();
|
||||
};
|
||||
35
server/src/database/typeorm-seeds/core/demo/index.ts
Normal file
35
server/src/database/typeorm-seeds/core/demo/index.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import {
|
||||
seedUsers,
|
||||
deleteUsersByWorkspace,
|
||||
} from 'src/database/typeorm-seeds/core/demo/users';
|
||||
import {
|
||||
seedWorkspaces,
|
||||
deleteWorkspaces,
|
||||
} from 'src/database/typeorm-seeds/core/demo/workspaces';
|
||||
import {
|
||||
seedFeatureFlags,
|
||||
deleteFeatureFlags,
|
||||
} from 'src/database/typeorm-seeds/core/demo/feature-flags';
|
||||
|
||||
export const seedCoreSchema = async (
|
||||
workspaceDataSource: DataSource,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
const schemaName = 'core';
|
||||
await seedWorkspaces(workspaceDataSource, schemaName, workspaceId);
|
||||
await seedUsers(workspaceDataSource, schemaName, workspaceId);
|
||||
await seedFeatureFlags(workspaceDataSource, schemaName, workspaceId);
|
||||
};
|
||||
|
||||
export const deleteCoreSchema = async (
|
||||
workspaceDataSource: DataSource,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
const schemaName = 'core';
|
||||
await deleteUsersByWorkspace(workspaceDataSource, schemaName, workspaceId);
|
||||
await deleteFeatureFlags(workspaceDataSource, schemaName, workspaceId);
|
||||
// deleteWorkspaces should be last
|
||||
await deleteWorkspaces(workspaceDataSource, schemaName, workspaceId);
|
||||
};
|
||||
76
server/src/database/typeorm-seeds/core/demo/users.ts
Normal file
76
server/src/database/typeorm-seeds/core/demo/users.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
// import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces';
|
||||
|
||||
const tableName = 'user';
|
||||
|
||||
export enum DemoSeedUserIds {
|
||||
Noah = '20202020-9e3b-46d4-a556-88b9ddc2b035',
|
||||
Hugo = '20202020-3957-4908-9c36-2929a23f8358',
|
||||
Julia = '20202020-7169-42cf-bc47-1cfef15264b9',
|
||||
}
|
||||
|
||||
export const seedUsers = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
'id',
|
||||
'firstName',
|
||||
'lastName',
|
||||
'email',
|
||||
'passwordHash',
|
||||
'defaultWorkspaceId',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
id: DemoSeedUserIds.Noah,
|
||||
firstName: 'Noah',
|
||||
lastName: 'A',
|
||||
email: 'noah@demo.dev',
|
||||
passwordHash:
|
||||
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
|
||||
defaultWorkspaceId: workspaceId,
|
||||
},
|
||||
{
|
||||
id: DemoSeedUserIds.Hugo,
|
||||
firstName: 'Hugo',
|
||||
lastName: 'I',
|
||||
email: 'hugo@demo.dev',
|
||||
passwordHash:
|
||||
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
|
||||
defaultWorkspaceId: workspaceId,
|
||||
},
|
||||
,
|
||||
{
|
||||
id: DemoSeedUserIds.Julia,
|
||||
firstName: 'Julia',
|
||||
lastName: 'S',
|
||||
email: 'julia.s@demo.dev',
|
||||
passwordHash:
|
||||
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
|
||||
defaultWorkspaceId: workspaceId,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
|
||||
export const deleteUsersByWorkspace = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(`${schemaName}.${tableName}`)
|
||||
.where(`"${tableName}"."defaultWorkspaceId" = :workspaceId`, {
|
||||
workspaceId,
|
||||
})
|
||||
.execute();
|
||||
};
|
||||
44
server/src/database/typeorm-seeds/core/demo/workspaces.ts
Normal file
44
server/src/database/typeorm-seeds/core/demo/workspaces.ts
Normal file
File diff suppressed because one or more lines are too long
@ -2,11 +2,12 @@ import { DataSource } from 'typeorm';
|
||||
|
||||
const tableName = 'featureFlag';
|
||||
|
||||
import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces';
|
||||
// import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces';
|
||||
|
||||
export const seedFeatureFlags = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
@ -16,9 +17,22 @@ export const seedFeatureFlags = async (
|
||||
.values([
|
||||
{
|
||||
key: 'IS_RELATION_FIELD_TYPE_ENABLED',
|
||||
workspaceId: SeedWorkspaceId,
|
||||
workspaceId: workspaceId,
|
||||
value: true,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
|
||||
export const deleteFeatureFlags = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(`${schemaName}.${tableName}`)
|
||||
.where(`"${tableName}"."workspaceId" = :workspaceId`, { workspaceId })
|
||||
.execute();
|
||||
};
|
||||
|
||||
@ -1,12 +1,35 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { seedUsers } from 'src/database/typeorm-seeds/core/users';
|
||||
import { seedWorkspaces } from 'src/database/typeorm-seeds/core/workspaces';
|
||||
import { seedFeatureFlags } from 'src/database/typeorm-seeds/core/feature-flags';
|
||||
import {
|
||||
seedUsers,
|
||||
deleteUsersByWorkspace,
|
||||
} from 'src/database/typeorm-seeds/core/users';
|
||||
import {
|
||||
seedWorkspaces,
|
||||
deleteWorkspaces,
|
||||
} from 'src/database/typeorm-seeds/core/workspaces';
|
||||
import {
|
||||
seedFeatureFlags,
|
||||
deleteFeatureFlags,
|
||||
} from 'src/database/typeorm-seeds/core/feature-flags';
|
||||
|
||||
export const seedCoreSchema = async (workspaceDataSource: DataSource) => {
|
||||
export const seedCoreSchema = async (
|
||||
workspaceDataSource: DataSource,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
const schemaName = 'core';
|
||||
await seedWorkspaces(workspaceDataSource, schemaName);
|
||||
await seedUsers(workspaceDataSource, schemaName);
|
||||
await seedFeatureFlags(workspaceDataSource, schemaName);
|
||||
await seedWorkspaces(workspaceDataSource, schemaName, workspaceId);
|
||||
await seedUsers(workspaceDataSource, schemaName, workspaceId);
|
||||
await seedFeatureFlags(workspaceDataSource, schemaName, workspaceId);
|
||||
};
|
||||
|
||||
export const deleteCoreSchema = async (
|
||||
workspaceDataSource: DataSource,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
const schemaName = 'core';
|
||||
await deleteUsersByWorkspace(workspaceDataSource, schemaName, workspaceId);
|
||||
await deleteFeatureFlags(workspaceDataSource, schemaName, workspaceId);
|
||||
// deleteWorkspaces should be last
|
||||
await deleteWorkspaces(workspaceDataSource, schemaName, workspaceId);
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
|
||||
import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces';
|
||||
// import { SeedWorkspaceId } from 'src/database/typeorm-seeds/core/workspaces';
|
||||
|
||||
const tableName = 'user';
|
||||
|
||||
@ -13,6 +13,7 @@ export enum SeedUserIds {
|
||||
export const seedUsers = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
@ -34,7 +35,7 @@ export const seedUsers = async (
|
||||
email: 'tim@apple.dev',
|
||||
passwordHash:
|
||||
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
|
||||
defaultWorkspaceId: SeedWorkspaceId,
|
||||
defaultWorkspaceId: workspaceId,
|
||||
},
|
||||
{
|
||||
id: SeedUserIds.Jony,
|
||||
@ -43,7 +44,7 @@ export const seedUsers = async (
|
||||
email: 'jony.ive@apple.dev',
|
||||
passwordHash:
|
||||
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
|
||||
defaultWorkspaceId: SeedWorkspaceId,
|
||||
defaultWorkspaceId: workspaceId,
|
||||
},
|
||||
,
|
||||
{
|
||||
@ -53,8 +54,23 @@ export const seedUsers = async (
|
||||
email: 'phil.schiler@apple.dev',
|
||||
passwordHash:
|
||||
'$2b$10$66d.6DuQExxnrfI9rMqOg.U1XIYpagr6Lv05uoWLYbYmtK0HDIvS6', // Applecar2025
|
||||
defaultWorkspaceId: SeedWorkspaceId,
|
||||
defaultWorkspaceId: workspaceId,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
|
||||
export const deleteUsersByWorkspace = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(`${schemaName}.${tableName}`)
|
||||
.where(`"${tableName}"."defaultWorkspaceId" = :workspaceId`, {
|
||||
workspaceId,
|
||||
})
|
||||
.execute();
|
||||
};
|
||||
|
||||
@ -7,6 +7,7 @@ export const SeedWorkspaceId = '20202020-1c25-4d02-bf25-6aeccf7ea419';
|
||||
export const seedWorkspaces = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
@ -21,7 +22,7 @@ export const seedWorkspaces = async (
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
id: SeedWorkspaceId,
|
||||
id: workspaceId,
|
||||
displayName: 'Apple',
|
||||
domainName: 'apple.dev',
|
||||
inviteHash: 'apple.dev-invite-hash',
|
||||
@ -30,3 +31,16 @@ export const seedWorkspaces = async (
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
|
||||
export const deleteWorkspaces = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
workspaceId: string,
|
||||
) => {
|
||||
await workspaceDataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(`${schemaName}.${tableName}`)
|
||||
.where(`${tableName}."id" = :id`, { id: workspaceId })
|
||||
.execute();
|
||||
};
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export const CastToStringArray = () =>
|
||||
Transform(({ value }: { value: string }) => toStringArray(value));
|
||||
|
||||
const toStringArray = (value: any) => {
|
||||
if (typeof value === 'string') {
|
||||
return value.split(',').map((item) => item.trim());
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
@ -173,4 +173,8 @@ export class EnvironmentService {
|
||||
getSentryDSN(): string | undefined {
|
||||
return this.configService.get<string>('SENTRY_DSN');
|
||||
}
|
||||
|
||||
getDemoWorkspaceIds(): string[] {
|
||||
return this.configService.get<string[]>('DEMO_WORKSPACE_IDS') ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import {
|
||||
} from 'class-validator';
|
||||
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { CastToStringArray } from 'src/integrations/environment/decorators/cast-to-string-array.decorator';
|
||||
|
||||
import { IsDuration } from './decorators/is-duration.decorator';
|
||||
import { StorageType } from './interfaces/storage.interface';
|
||||
@ -145,6 +146,10 @@ export class EnvironmentVariables {
|
||||
@IsOptional()
|
||||
LOG_LEVELS?: LogLevel[];
|
||||
|
||||
@CastToStringArray()
|
||||
@IsOptional()
|
||||
DEMO_WORKSPACE_IDS?: string[];
|
||||
|
||||
@ValidateIf((env) => env.LOGGER_DRIVER === LoggerDriver.Sentry)
|
||||
@IsString()
|
||||
SENTRY_DSN?: string;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { companiesDemo } from './companies-demo';
|
||||
|
||||
export const companyPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.company`, [
|
||||
'name',
|
||||
'domainName',
|
||||
'address',
|
||||
'employees',
|
||||
'linkedinLinkUrl',
|
||||
])
|
||||
.orIgnore()
|
||||
.values(companiesDemo)
|
||||
.returning('*')
|
||||
.execute();
|
||||
};
|
||||
@ -0,0 +1,40 @@
|
||||
import { DataSource, EntityManager } from 'typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
|
||||
import { viewPrefillData } from 'src/workspace/workspace-manager/demo-objects-prefill-data/view';
|
||||
import { companyPrefillData } from 'src/workspace/workspace-manager/demo-objects-prefill-data/company';
|
||||
import { personPrefillData } from 'src/workspace/workspace-manager/demo-objects-prefill-data/person';
|
||||
import { pipelineStepPrefillData } from 'src/workspace/workspace-manager/demo-objects-prefill-data/pipeline-step';
|
||||
import { workspaceMemberPrefillData } from 'src/workspace/workspace-manager/demo-objects-prefill-data/workspace-member';
|
||||
import { seedDemoOpportunity } from 'src/workspace/workspace-manager/demo-objects-prefill-data/opportunity';
|
||||
|
||||
export const demoObjectsPrefillData = async (
|
||||
workspaceDataSource: DataSource,
|
||||
schemaName: string,
|
||||
objectMetadata: ObjectMetadataEntity[],
|
||||
) => {
|
||||
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
|
||||
acc[object.nameSingular] = {
|
||||
id: object.id,
|
||||
fields: object.fields.reduce((acc, field) => {
|
||||
acc[field.name] = field.id;
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// TODO: udnerstand why only with this createQueryRunner transaction below works
|
||||
const queryRunner = workspaceDataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
|
||||
workspaceDataSource.transaction(async (entityManager: EntityManager) => {
|
||||
await companyPrefillData(entityManager, schemaName);
|
||||
await personPrefillData(entityManager, schemaName);
|
||||
await viewPrefillData(entityManager, schemaName, objectMetadataMap);
|
||||
await pipelineStepPrefillData(entityManager, schemaName);
|
||||
await seedDemoOpportunity(entityManager, schemaName);
|
||||
|
||||
await workspaceMemberPrefillData(entityManager, schemaName);
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,76 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
const tableName = 'opportunity';
|
||||
|
||||
const getRandomProbability = () => {
|
||||
const firstDigit = Math.floor(Math.random() * 9) + 1;
|
||||
return firstDigit / 10;
|
||||
};
|
||||
|
||||
const getRandomPipelineStepId = (pipelineStepIds: { id: string }[]) =>
|
||||
pipelineStepIds[Math.floor(Math.random() * pipelineStepIds.length)].id;
|
||||
|
||||
const generateRandomAmountMicros = () => {
|
||||
const firstDigit = Math.floor(Math.random() * 9) + 1;
|
||||
return firstDigit * 10000000000;
|
||||
};
|
||||
|
||||
// Function to generate the array of opportunities
|
||||
// companiesWithPeople - selecting from the db companies and 1 person related to the company.id to use companyId, pointOfContactId and personId
|
||||
// pipelineStepIds - selecting from the db pipeline, getting random id from selected to use as pipelineStepId
|
||||
|
||||
const generateOpportunities = (
|
||||
companies,
|
||||
pipelineStepIds: { id: string }[],
|
||||
) => {
|
||||
return companies.map((company) => ({
|
||||
id: v4(),
|
||||
amountAmountMicros: generateRandomAmountMicros(),
|
||||
amountCurrencyCode: 'USD',
|
||||
closeDate: new Date(),
|
||||
probability: getRandomProbability(),
|
||||
pipelineStepId: getRandomPipelineStepId(pipelineStepIds),
|
||||
pointOfContactId: company.personId,
|
||||
personId: company.personId,
|
||||
companyId: company.id,
|
||||
}));
|
||||
};
|
||||
|
||||
export const seedDemoOpportunity = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
const companiesWithPeople = await entityManager?.query(
|
||||
`SELECT company.*, person.id AS "personId"
|
||||
FROM ${schemaName}.company
|
||||
LEFT JOIN ${schemaName}.person ON company.id = "person"."companyId"
|
||||
LIMIT 50`,
|
||||
);
|
||||
const pipelineStepIds = await entityManager?.query(
|
||||
`SELECT id FROM ${schemaName}."pipelineStep"`,
|
||||
);
|
||||
|
||||
const opportunities = generateOpportunities(
|
||||
companiesWithPeople,
|
||||
pipelineStepIds,
|
||||
);
|
||||
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.${tableName}`, [
|
||||
'id',
|
||||
'amountAmountMicros',
|
||||
'amountCurrencyCode',
|
||||
'closeDate',
|
||||
'probability',
|
||||
'pipelineStepId',
|
||||
'pointOfContactId',
|
||||
'personId',
|
||||
'companyId',
|
||||
])
|
||||
.orIgnore()
|
||||
.values(opportunities)
|
||||
.execute();
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,42 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { peopleDemo } from './people-demo';
|
||||
|
||||
export const personPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
const companies = await entityManager?.query(
|
||||
`SELECT * FROM ${schemaName}.company`,
|
||||
);
|
||||
|
||||
// Iterate through the array and add a UUID for each person
|
||||
const people = peopleDemo.map((person, index) => ({
|
||||
nameFirstName: person.firstName,
|
||||
nameLastName: person.lastName,
|
||||
email: person.email,
|
||||
linkedinLinkUrl: person.linkedinUrl,
|
||||
jobTitle: person.jobTitle,
|
||||
city: person.city,
|
||||
avatarUrl: person.avatarUrl,
|
||||
companyId: companies[Math.floor(index / 2)].id,
|
||||
}));
|
||||
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.person`, [
|
||||
'nameFirstName',
|
||||
'nameLastName',
|
||||
'city',
|
||||
'email',
|
||||
'avatarUrl',
|
||||
'linkedinLinkUrl',
|
||||
'jobTitle',
|
||||
'companyId',
|
||||
])
|
||||
.orIgnore()
|
||||
.values(people)
|
||||
.returning('*')
|
||||
.execute();
|
||||
};
|
||||
@ -0,0 +1,41 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
export const pipelineStepPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.pipelineStep`, ['name', 'color', 'position'])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
name: 'New',
|
||||
color: 'red',
|
||||
position: 0,
|
||||
},
|
||||
{
|
||||
name: 'Screening',
|
||||
color: 'purple',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
name: 'Meeting',
|
||||
color: 'sky',
|
||||
position: 2,
|
||||
},
|
||||
{
|
||||
name: 'Proposal',
|
||||
color: 'turquoise',
|
||||
position: 3,
|
||||
},
|
||||
{
|
||||
name: 'Customer',
|
||||
color: 'yellow',
|
||||
position: 4,
|
||||
},
|
||||
])
|
||||
.returning('*')
|
||||
.execute();
|
||||
};
|
||||
@ -0,0 +1,200 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/metadata/object-metadata/object-metadata.entity';
|
||||
|
||||
export const viewPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
objectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
) => {
|
||||
// Creating views
|
||||
const createdViews = await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.view`, ['name', 'objectMetadataId', 'type'])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
name: 'All Companies',
|
||||
objectMetadataId: objectMetadataMap['company'].id,
|
||||
type: 'table',
|
||||
},
|
||||
{
|
||||
name: 'All People',
|
||||
objectMetadataId: objectMetadataMap['person'].id,
|
||||
type: 'table',
|
||||
},
|
||||
{
|
||||
name: 'All Opportunities',
|
||||
objectMetadataId: objectMetadataMap['opportunity'].id,
|
||||
type: 'kanban',
|
||||
},
|
||||
])
|
||||
.returning('*')
|
||||
.execute();
|
||||
|
||||
const viewIdMap = createdViews.raw.reduce((acc, view) => {
|
||||
acc[view.name] = view.id;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
// Creating viewFields
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.viewField`, [
|
||||
'fieldMetadataId',
|
||||
'viewId',
|
||||
'position',
|
||||
'isVisible',
|
||||
'size',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
// Company
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['name'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['domainName'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['accountOwner'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['createdAt'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['employees'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['company'].fields['address'],
|
||||
viewId: viewIdMap['All Companies'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 170,
|
||||
},
|
||||
// Person
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['name'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 210,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['email'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['company'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['phone'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['createdAt'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 4,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['city'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 5,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['jobTitle'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 6,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['linkedinLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 7,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['person'].fields['xLink'],
|
||||
viewId: viewIdMap['All People'],
|
||||
position: 8,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
// Opportunity
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 0,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 1,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 2,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
fieldMetadataId:
|
||||
objectMetadataMap['opportunity'].fields['pointOfContact'],
|
||||
viewId: viewIdMap['All Opportunities'],
|
||||
position: 3,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
@ -0,0 +1,54 @@
|
||||
import { EntityManager } from 'typeorm';
|
||||
|
||||
import { DemoSeedUserIds } from 'src/database/typeorm-seeds/core/demo/users';
|
||||
|
||||
const WorkspaceMemberIds = {
|
||||
Noah: '20202020-0687-4c41-b707-ed1bfca972a7',
|
||||
Hugo: '20202020-77d5-4cb6-b60a-f4a835a85d61',
|
||||
Julia: '20202020-1553-45c6-a028-5a9064cce07f',
|
||||
};
|
||||
|
||||
export const workspaceMemberPrefillData = async (
|
||||
entityManager: EntityManager,
|
||||
schemaName: string,
|
||||
) => {
|
||||
await entityManager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(`${schemaName}.workspaceMember`, [
|
||||
'id',
|
||||
'nameFirstName',
|
||||
'nameLastName',
|
||||
'locale',
|
||||
'colorScheme',
|
||||
'userId',
|
||||
])
|
||||
.orIgnore()
|
||||
.values([
|
||||
{
|
||||
id: WorkspaceMemberIds.Noah,
|
||||
nameFirstName: 'Noah',
|
||||
nameLastName: 'A',
|
||||
locale: 'en',
|
||||
colorScheme: 'Light',
|
||||
userId: DemoSeedUserIds.Noah,
|
||||
},
|
||||
{
|
||||
id: WorkspaceMemberIds.Hugo,
|
||||
nameFirstName: 'Hugo',
|
||||
nameLastName: 'I',
|
||||
locale: 'en',
|
||||
colorScheme: 'Light',
|
||||
userId: DemoSeedUserIds.Hugo,
|
||||
},
|
||||
{
|
||||
id: WorkspaceMemberIds.Julia,
|
||||
nameFirstName: 'Julia',
|
||||
nameLastName: 'S',
|
||||
locale: 'en',
|
||||
colorScheme: 'Light',
|
||||
userId: DemoSeedUserIds.Julia,
|
||||
},
|
||||
])
|
||||
.execute();
|
||||
};
|
||||
@ -6,6 +6,7 @@ import { ObjectMetadataService } from 'src/metadata/object-metadata/object-metad
|
||||
import { WorkspaceMigrationRunnerService } from 'src/workspace/workspace-migration-runner/workspace-migration-runner.service';
|
||||
import { WorkspaceMigrationService } from 'src/metadata/workspace-migration/workspace-migration.service';
|
||||
import { standardObjectsPrefillData } from 'src/workspace/workspace-manager/standard-objects-prefill-data/standard-objects-prefill-data';
|
||||
import { demoObjectsPrefillData } from 'src/workspace/workspace-manager/demo-objects-prefill-data/demo-objects-prefill-data';
|
||||
import { WorkspaceDataSourceService } from 'src/workspace/workspace-datasource/workspace-datasource.service';
|
||||
import { DataSourceEntity } from 'src/metadata/data-source/data-source.entity';
|
||||
import { RelationMetadataService } from 'src/metadata/relation-metadata/relation-metadata.service';
|
||||
@ -71,6 +72,44 @@ export class WorkspaceManagerService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* InitDemo a workspace by creating a new data source and running all migrations
|
||||
* @param workspaceId
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
public async initDemo(workspaceId: string): Promise<void> {
|
||||
const schemaName =
|
||||
await this.workspaceDataSourceService.createWorkspaceDBSchema(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const dataSourceMetadata =
|
||||
await this.dataSourceService.createDataSourceMetadata(
|
||||
workspaceId,
|
||||
schemaName,
|
||||
);
|
||||
|
||||
await this.setWorkspaceMaxRow(workspaceId, schemaName);
|
||||
|
||||
await this.workspaceMigrationService.insertStandardMigrations(workspaceId);
|
||||
|
||||
await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
const createdObjectMetadata =
|
||||
await this.createStandardObjectsAndFieldsMetadata(
|
||||
dataSourceMetadata.id,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.prefillWorkspaceWithDemoObjects(
|
||||
dataSourceMetadata,
|
||||
workspaceId,
|
||||
createdObjectMetadata,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Create all standard objects and fields metadata for a given workspace
|
||||
@ -256,8 +295,34 @@ export class WorkspaceManagerService {
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('Could not connect to workspace data source');
|
||||
}
|
||||
await standardObjectsPrefillData(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
createdObjectMetadata,
|
||||
);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* We are prefilling a few demo objects with data to make it easier for the user to get started.
|
||||
*
|
||||
* @param dataSourceMetadata
|
||||
* @param workspaceId
|
||||
*/
|
||||
private async prefillWorkspaceWithDemoObjects(
|
||||
dataSourceMetadata: DataSourceEntity,
|
||||
workspaceId: string,
|
||||
createdObjectMetadata: ObjectMetadataEntity[],
|
||||
) {
|
||||
const workspaceDataSource =
|
||||
await this.workspaceDataSourceService.connectToWorkspaceDataSource(
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
standardObjectsPrefillData(
|
||||
if (!workspaceDataSource) {
|
||||
throw new Error('Could not connect to workspace data source');
|
||||
}
|
||||
|
||||
await demoObjectsPrefillData(
|
||||
workspaceDataSource,
|
||||
dataSourceMetadata.schema,
|
||||
createdObjectMetadata,
|
||||
|
||||
Reference in New Issue
Block a user