Hey everyone! 馃憢
Adonis is currently reading all files within the database/seeds directory and run them in an alphabetical order.
This create multiple issues.
This is why I believe this feature needs to change.
One solution could be that the command adonis seed would only run one file, called DatabaseSeeder.
This file would have one function called run().
const Seeder = use('Seeder')
class DatabaseSeeder extends Seeder {
async run () {
//
}
}
From here, you can define in which order and how you want to run your seeds.
// Pseudo code syntax
async run () {
await this.callInOrder([
'Seeds/User/AdministratorSeeder',
'Seeds/User/ModeratorSeeder',
// ...
])
await this.callInParallel([
'Seeds/Lang/FrenchSeeder',
'Seeds/Lang/EnglishSeeder',
'Seeds/Lang/ChineseSeeder',
// ...
])
}
We could also think about adding an optional parameter that would define which function to run inside the DatabaseSeeder file.
# $ adonis seed production
This command would call the production() function inside the DatabaseSeeder class.
It would help to define different seeds for different environment.
See https://github.com/adonisjs/adonis-lucid/issues/307#issuecomment-379006516
Let me know what you think about it!
c/c @teachmeanything
I like this proposal since the DatabaseSeeder is in control of all the seeds while still allowing to run single, individual files. The possibility to store the seed files in different directories would also be very helpful since my current folder structure is getting messy. https://files.gitter.im/adonisjs/adonis-framework/sUq0/image.png
Why don't use dependencies?
In each seed file you can indicate which seeds need to be executed before that and resolve the dependency tree when executing the seed command.
Something like:
class PageSeeder {
async dependencies() {
return [
'BookSeeder'
]
}
}
@RomainLanz I tried with the following code, But it throws me into an error saying that Error: Cannot find module 'Seeder'
@mfauzaan It's an RFC and this code doesn't work until it is implemented
I found this issue by trying to search this option = adonis seed production
One option would also be for a cmd adonis seed --folders=core, production so i can have different seeds for enviroment.
Good addition @alanaasmaa!
I like that you can select one or multiple folders (and by default it goes in the root).
Then it searches for DatabaseSeeder inside those folders and start doing what it needs to do 馃憤
@Kamnag RFC's are not meant to discuss issues. Please use the forum and or the discord server
I've just been discussing this with @karl-roberts - @RomainLanz idea seems similar to how laravel works.
I do not know if this subject has already been solved in a standard way, but it follows my solution for anyone still in search:
It's not implemented yet, it will be in the next version of Lucid.
@RomainLanz Thanks for your attention.
I know it has not been implemented yet, I just found a simple way to solve it. Please take a look, as this may be a fairly viable solution to implement in the next release. It would only be necessary to modify the CLI to run the DatabaseSeeder.js file by default, and modify the structure of the run () method to static.
@mcordoba
Why don't use dependencies?
In each seed file you can indicate which seeds need to be executed before that and resolve the dependency tree when executing the seed command.
Something like:
class PageSeeder { async dependencies() { return [ 'BookSeeder' ] } }
its add a problem: recursive call, need to make graph dependency and check it
PageSeeder -> dependencies -> PageSeeder
but first post its good idea, maybe check in array or set, default unique
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Still relevant I believe
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Let's move this to a proper RFC in https://github.com/adonisjs/rfcs/.
Most helpful comment
Why don't use dependencies?
In each seed file you can indicate which seeds need to be executed before that and resolve the dependency tree when executing the seed command.
Something like: