-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple instances #30
Comments
Kiril, that's something that you should be able to achieve with NestJs itself. I need to think over on how to make the config something that you can inject multiple times into the service. Something like this: import { Injectable, Module } from '@nestjs/common';
import { MorpheusModule, MorpheusService } from 'morpheus4j';
import { ConfigService, ConfigModule } from '@nestjs/config';
@Injectable()
export class CustomMigrationService {
constructor(
private readonly morpheusService: MorpheusService,
private readonly configService: ConfigService,
) {}
async onApplicationBootstrap() {
const configs = [
{
scheme: this.configService.get('DB1_SCHEME'),
host: this.configService.get('DB1_HOST'),
port: this.configService.get('DB1_PORT'),
username: this.configService.get('DB1_USERNAME'),
password: this.configService.get('DB1_PASSWORD'),
migrationsPath: './neo4j/db1/migrations',
},
{
scheme: this.configService.get('DB2_SCHEME'),
host: this.configService.get('DB2_HOST'),
port: this.configService.get('DB2_PORT'),
username: this.configService.get('DB2_USERNAME'),
password: this.configService.get('DB2_PASSWORD'),
migrationsPath: './neo4j/db2/migrations',
},
];
for (const config of configs) {
await this.morpheusService.runMigrationsFor(config);
}
}
}
@Module({
imports: [
ConfigModule.forRoot(),
MorpheusModule,
],
providers: [CustomMigrationService],
})
export class DbModule {} This way you can define your own service and execute the migrations for each config that you have. Again, in order to do this I need to do some refactoring, so I'll think it over. |
Hello again, I had pretty much the same vision. It would be very neat. Thanks for considering it! |
@marianozunino Hi, I packaged the project and installed it as npm dependency locally. I have this rather ugly code with the two deletes for testing purposes:
I feel like I am at verge of making it work, however I have a problem with the DependencyScanner which is used in the morpheus project, more specifically in the MigrationService, that I am unable to solve.
I am not sure if the issue comes from my setup or something is off at the root. I ll be looking into it more but I decided to share it with you in case it might be helpful. |
I pushed another commit making the lazy module optional. Also, your code should look like this: Neo4jModule.forRootAsync({
imports: [MorpheusModule],
inject: [MorpheusService],
useFactory: async (morpheusService: MorpheusService): Promise<Neo4jInstance[]> => {
const neo4jInstanceManager = Neo4jInstancesManager.getInstance();
const neo4jInstances = await neo4jInstanceManager.getDbInstances();
const instancesAndDrivers = await createDrivers(neo4jInstances);
for (const instance of neo4jInstances) {
delete instance.databaseType
delete instance.database
await morpheusService.runMigrationsFor(instance);
}
return Object.values(instancesAndDrivers).map((pair, index) => ({
...neo4jInstances[index],
pair,
}));
},
}) No need to execute |
@marianozunino Hi again, sorry I didn't have the chance to test it again until now.
to
for security reasons? This way people will know on which database the migrations are executed without logging the password. Again, thank you very much! |
# [3.1.0](v3.0.2...v3.1.0) (2023-06-19) ### Features * expose MorpheusService [#30](#30) ([469e232](469e232))
Hello,
We are running multiple instances of Neo4j and use them in a NestJs application. We perform our migrations on application bootstrap with the help of Morpheus4j.
Hence, we are wondering if there is a way to apply the migrations to all instances which are loaded in the application - each instance is a separate host.
Thanks in advance,
Kiril
The text was updated successfully, but these errors were encountered: