Add standardObject seeds (#2140)
* Add standardObject seeds * use for of
This commit is contained in:
@ -45,9 +45,10 @@ export class MigrationRunnerService {
|
|||||||
|
|
||||||
// Loop over each migration and create or update the table
|
// Loop over each migration and create or update the table
|
||||||
// TODO: Should be done in a transaction
|
// TODO: Should be done in a transaction
|
||||||
flattenedPendingMigrations.forEach(async (migration) => {
|
|
||||||
|
for (const migration of flattenedPendingMigrations) {
|
||||||
await this.handleTableChanges(queryRunner, schemaName, migration);
|
await this.handleTableChanges(queryRunner, schemaName, migration);
|
||||||
});
|
}
|
||||||
|
|
||||||
// Update appliedAt date for each migration
|
// Update appliedAt date for each migration
|
||||||
// TODO: Should be done after the migration is successful
|
// TODO: Should be done after the migration is successful
|
||||||
|
|||||||
@ -0,0 +1,32 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Airbnb",
|
||||||
|
"domainName": "airbnb.com",
|
||||||
|
"address": "San Francisco",
|
||||||
|
"employees": 5000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Qonto",
|
||||||
|
"domainName": "qonto.com",
|
||||||
|
"address": "San Francisco",
|
||||||
|
"employees": 800
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Stripe",
|
||||||
|
"domainName": "stripe.com",
|
||||||
|
"address": "San Francisco",
|
||||||
|
"employees": 8000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Figma",
|
||||||
|
"domainName": "figma.com",
|
||||||
|
"address": "San Francisco",
|
||||||
|
"employees": 800
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Notion",
|
||||||
|
"domainName": "notion.com",
|
||||||
|
"address": "San Francisco",
|
||||||
|
"employees": 400
|
||||||
|
}
|
||||||
|
]
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
import companySeeds from './companies.seeds.json';
|
||||||
|
|
||||||
|
export const standardObjectsSeeds = {
|
||||||
|
companyV2: companySeeds,
|
||||||
|
};
|
||||||
@ -8,8 +8,10 @@ import { ObjectMetadataService } from 'src/metadata/object-metadata/services/obj
|
|||||||
import { DataSourceMetadataService } from 'src/metadata/data-source-metadata/data-source-metadata.service';
|
import { DataSourceMetadataService } from 'src/metadata/data-source-metadata/data-source-metadata.service';
|
||||||
import { FieldMetadata } from 'src/metadata/field-metadata/field-metadata.entity';
|
import { FieldMetadata } from 'src/metadata/field-metadata/field-metadata.entity';
|
||||||
import { ObjectMetadata } from 'src/metadata/object-metadata/object-metadata.entity';
|
import { ObjectMetadata } from 'src/metadata/object-metadata/object-metadata.entity';
|
||||||
|
import { DataSourceMetadata } from 'src/metadata/data-source-metadata/data-source-metadata.entity';
|
||||||
|
|
||||||
import { standardObjectsMetadata } from './standard-objects/standard-object-metadata';
|
import { standardObjectsMetadata } from './standard-objects/standard-object-metadata';
|
||||||
|
import { standardObjectsSeeds } from './standard-objects/standard-object-seeds';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TenantInitialisationService {
|
export class TenantInitialisationService {
|
||||||
@ -51,6 +53,11 @@ export class TenantInitialisationService {
|
|||||||
dataSourceMetadata.id,
|
dataSourceMetadata.id,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.prefillWorkspaceWithStandardObjects(
|
||||||
|
dataSourceMetadata,
|
||||||
|
workspaceId,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,4 +97,38 @@ export class TenantInitialisationService {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async prefillWorkspaceWithStandardObjects(
|
||||||
|
dataSourceMetadata: DataSourceMetadata,
|
||||||
|
workspaceId: string,
|
||||||
|
) {
|
||||||
|
const objects =
|
||||||
|
await this.objectMetadataService.getObjectMetadataFromDataSourceId(
|
||||||
|
dataSourceMetadata.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
const worksapceDataSource =
|
||||||
|
await this.dataSourceService.connectToWorkspaceDataSource(workspaceId);
|
||||||
|
|
||||||
|
for (const object of objects) {
|
||||||
|
const seedData = standardObjectsSeeds[object.nameSingular];
|
||||||
|
|
||||||
|
if (!seedData) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fields = standardObjectsMetadata[object.nameSingular].fields;
|
||||||
|
|
||||||
|
const columns = fields.map((field: FieldMetadata) =>
|
||||||
|
Object.values(field.targetColumnMap),
|
||||||
|
);
|
||||||
|
|
||||||
|
worksapceDataSource
|
||||||
|
?.createQueryBuilder()
|
||||||
|
.insert()
|
||||||
|
.into(`${dataSourceMetadata.schema}.${object.targetTableName}`, columns)
|
||||||
|
.values(seedData)
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user