Workspace seeders with version (#10895)
# Introduction close https://github.com/twentyhq/core-team-issues/issues/487 Updated the seeders to infer the workspace's version from the `APP_VERSION` env var To test in local run: `npx nx database:reset twenty-server` with either a defined or not defined `APP_VERSION` in your `.env` ( note that invalid semver values will throw an error and stop the process ) ( valid version ex: `APP_VERSION=1.0.0`)
This commit is contained in:
@ -3,14 +3,13 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import {
|
||||
deleteCoreSchema,
|
||||
seedCoreSchema,
|
||||
} from 'src/database/typeorm-seeds/core/demo';
|
||||
import { seedCoreSchema } from 'src/database/typeorm-seeds/core';
|
||||
import { deleteCoreSchema } from 'src/database/typeorm-seeds/core/demo';
|
||||
import { rawDataSource } from 'src/database/typeorm/raw/raw.datasource';
|
||||
import { InjectCacheStorage } from 'src/engine/core-modules/cache-storage/decorators/cache-storage.decorator';
|
||||
import { CacheStorageService } from 'src/engine/core-modules/cache-storage/services/cache-storage.service';
|
||||
import { CacheStorageNamespace } from 'src/engine/core-modules/cache-storage/types/cache-storage-namespace.enum';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { WorkspaceManagerService } from 'src/engine/workspace-manager/workspace-manager.service';
|
||||
|
||||
@ -22,6 +21,7 @@ export class DataSeedDemoWorkspaceService {
|
||||
protected readonly workspaceRepository: Repository<Workspace>,
|
||||
@InjectCacheStorage(CacheStorageNamespace.EngineWorkspace)
|
||||
private readonly workspaceSchemaCache: CacheStorageService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
async seedDemo(): Promise<void> {
|
||||
@ -43,7 +43,15 @@ export class DataSeedDemoWorkspaceService {
|
||||
await deleteCoreSchema(rawDataSource, workspaceId);
|
||||
}
|
||||
|
||||
await seedCoreSchema(rawDataSource, workspaceId);
|
||||
const appVersion = this.environmentService.get('APP_VERSION');
|
||||
|
||||
await seedCoreSchema({
|
||||
workspaceDataSource: rawDataSource,
|
||||
workspaceId,
|
||||
appVersion,
|
||||
seedBilling: false,
|
||||
seedFeatureFlags: false,
|
||||
});
|
||||
await this.workspaceManagerService.initDemo(workspaceId);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@ -95,8 +95,14 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
|
||||
await rawDataSource.initialize();
|
||||
|
||||
const isBillingEnabled = this.environmentService.get('IS_BILLING_ENABLED');
|
||||
const appVersion = this.environmentService.get('APP_VERSION');
|
||||
|
||||
await seedCoreSchema(rawDataSource, workspaceId, isBillingEnabled);
|
||||
await seedCoreSchema({
|
||||
workspaceDataSource: rawDataSource,
|
||||
workspaceId,
|
||||
seedBilling: isBillingEnabled,
|
||||
appVersion,
|
||||
});
|
||||
|
||||
await rawDataSource.destroy();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user