question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] Seeds behaviour

See original GitHub issue

Hey everyone! 👋

Adonis is currently reading all files within the database/seeds directory and run them in an alphabetical order.

This create multiple issues.

  1. You need to change the name of your file to define an order and it becomes hard to change when you want to add a seeds at position 7 but you already have 8+ seeds (need to change the name of all of them).
  2. You cannot define which seeds need to run in a specific environment.
  3. You cannot organise your seed files in multiple directory.

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:21
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
mcordobacommented, Mar 7, 2018

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'
    ]
  }
}
4reactions
raphaelramalhocommented, Dec 17, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] Seeds behaviour · Issue #307 · adonisjs/lucid
Hey everyone! Adonis is currently reading all files within the database/seeds directory and run them in an alphabetical order.
Read more >
[RFC] Seeds behaviour #307
Hey everyone!. Adonis is currently reading all files within the database/seeds directory and run them in an alphabetical order.
Read more >
RFC 5669 - The SEED Cipher Algorithm and Its Use ... - faqs.org
RFC 5669 - The SEED Cipher Algorithm and Its Use with the Secure.
Read more >
RFC 1541 - Dynamic Host Configuration Protocol
DHCP captures the behavior of BOOTP relay agents [7, 23], and DHCP participants can interoperate with BOOTP participants [9]. Due to some errors...
Read more >
RFC 1542: Clarifications and Extensions for the Bootstrap ...
The client behavior description also suffered in certain ways. ... Clearly, once this "seed" mis-information is planted, an attacker can further compromise ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found