Skip to content
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

[IDEA] Add priority for seed files (Discussion wanted) #107

Open
halvardssm opened this issue Apr 20, 2021 · 3 comments
Open

[IDEA] Add priority for seed files (Discussion wanted) #107

halvardssm opened this issue Apr 20, 2021 · 3 comments
Labels
discussion Let's discuss this and get some feedback enhancement New or improved feature or request good first issue Good for newcomers idea New idea for the project up for grabs If you have an implementation in mind, feel free to help us out by making a PR

Comments

@halvardssm
Copy link
Owner

halvardssm commented Apr 20, 2021

Is your feature request related to a problem? Please describe.

The seed files are currently run without any set order (if any it is alphabetical). We should add a property to the migration files which tells Nessie in which order the files should be run and if there are any dependencies/priorities.

As far as my imagination goes, we could do it the following ways, but feel free to chime in if you have another idea (not ordered, but numbered for easy reference):

  1. Have a property in the abstract seed class to set priority
    • Seed files with higher priority (larger number) are done first.
    • When two files have the same priority, the order doesn't matter and it will default to alphabetical.
    • Might be slower (and heavier) if the seed files are large as it requires each seed file to be imported before sorting.
    • My preference, but I am not too fond of the cons
  2. Have the priority in the file name
    • Will be faster as sorting can be done prior to module import.
    • I think this will be ugly and I would prefer not to go for this option (my opinionated opinion).
  3. Use a comment on the first line of the file which can be read before importing
    • Will probably be faster 1, but slower than 2
    • Could be an antipattern
  4. Have a separate priority const export similar to 1, but for the file instead of the class
    • Not sure if this is also an antipattern
    • Could be as slow as 1

Update:
I will leave this open until I get some feedback or I figure out a solid way of doing this. It will not be included in the v2 release, but might be a part of a v2 minor release further down the line

@halvardssm halvardssm added enhancement New or improved feature or request up for grabs If you have an implementation in mind, feel free to help us out by making a PR idea New idea for the project discussion Let's discuss this and get some feedback labels Apr 20, 2021
@halvardssm halvardssm changed the title [IDEA] Add priority for seed files [IDEA] Add priority for seed files (Discussion wanted) May 9, 2021
@kluzzebass
Copy link

I've just been prefixing the seed files with a number (like 10_my_seed_file.ts), which seems to work fine.

@ebebbington
Copy link
Contributor

@halvardssm why not take the laravel approach, and the user create/define a base seeder class that runs the other seeders? for example from a php project:

<?php

// database/seeders/DatabaseSeeder.php

namespace Database\Seeds;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // Run in this order
        $this->call(A::class);
        $this->call(B::class);

        $this->call(C::class);
        $this->call(D::class);
    }
}

@halvardssm
Copy link
Owner Author

I am inclined to the approach from @ebebbington but the question is then the implementation. I would say that the default behaviour should be the seed name in ascending order, and then an optional property in the config object (or a CLI flag) can give a path to a seed runner file. The only thing on my end which I am not too sure about is whether this should be a class or a function, but seeing as Nessie is fully class-based, we might as well continue on this path. I won't have time to implement this in the forseable future, so anyone are free to pick this up and send a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Let's discuss this and get some feedback enhancement New or improved feature or request good first issue Good for newcomers idea New idea for the project up for grabs If you have an implementation in mind, feel free to help us out by making a PR
Projects
None yet
Development

No branches or pull requests

3 participants