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

Seed doesn't execute, marked as succeeded #301

Closed
mtitolo opened this issue May 11, 2016 · 20 comments
Closed

Seed doesn't execute, marked as succeeded #301

mtitolo opened this issue May 11, 2016 · 20 comments

Comments

@mtitolo
Copy link

mtitolo commented May 11, 2016

I've been struggling with this for almost an entire day. The TL;DR is that all of the db:seed commands will execute and not throw an error when they don't actually do anything. I've been pulling my hair out trying to figure out what the hell is going on but since there's no real documentation, it's been extremely tough.

None of the seed commands ever work. Not seed --seed, not seed:undo, not seed:all (no seeds! great!), not seed:undo:all (again there are no seeds! wat). I switched to the json seeder cache and have been manually modifying it because even though the seed doesn't do anything it gets marked as complete.

Seeders that don't execute should not be marked as a success. And I know it didn't execute because I have no data in my database (I had to remove it all manually because again undo doesn't work).

'use strict';

module.exports = {
  up: function (queryInterface, Sequelize) {
    return 
      queryInterface.bulkInsert('Users', [
        {email: "aphrodite@olympus.org", name: "Aphrodite",  createdAt: Date.now(), updatedAt: Date.now() },
        {email: "athena@olympus.org", name: "Athena", createdAt: Date.now(), updatedAt: Date.now() },
        {email: "zeus@olympus.org", name: "Zeus", createdAt: Date.now(), updatedAt: Date.now() },
        {email: "apollo@olympus.org", name: "Apollo", createdAt: Date.now(), updatedAt: Date.now() }
        ]
      );
  },

  down: function (queryInterface, Sequelize) {
    return 
    queryInterface.bulkDelete('Users', null, {});
  }
};

I do not have a schema. I've tried wrapping the returned queryInterface in an array as some Stack Overflow posts have suggested, nothing. I've tried {tableName: 'Users'} and nothing. I've tried an empty string schema, also nothing. I've added a {schema: 'whatever'} after the data array, nothing. I added an empty hash after the data array, nothing. So something is going on but it's just not executing my inserts or deletes, and it's not telling me there's an error. Silence is the absolute worst thing.

This is with Sequelize 3.23.0, CLI 2.4.0

@jocull
Copy link

jocull commented May 11, 2016

Just curious, but is the empty space after return causing a JS bug?
http://encosia.com/in-javascript-curly-brace-placement-matters-an-example/

@Americas
Copy link
Collaborator

@jocull great catch! Tested it in my code and you are absolutely right. The seed just returns instantly.

@jocull
Copy link

jocull commented May 12, 2016

@Americas Thanks, I thought that might be it. :) I actually came to this issue looking for why my seeders had stopped recording their runs in my database. What I ended up discovering is that the "seederStorage" is now none by default. I had to manually set this to "seqeulize" to make them start storing again. This is a big breaking change on a minor version increase, as my database now seeds over and over until I stop it. Could these please be major version bumps in the future?

@mtitolo This almost certainly something a linter would catch in the future. Hope that helps :)

@mtitolo
Copy link
Author

mtitolo commented May 12, 2016

That fixes db:seed but none of the other commands work.

@jocull
Copy link

jocull commented May 12, 2016

@mtitolo Try setting your "seederStorage" like I mentioned above. If nothing is being recorded, you may not have anything to :undo

@mtitolo
Copy link
Author

mtitolo commented May 12, 2016

sequelize-data.json:

[
  "20160511015238-users-and-groups.js"
]

config.json:

  "development": {
    "dialect": "sqlite",
    "storage": "./db.development.sqlite",
    "seederStorage": "json",
    "host": "127.0.0.1"
  },

undo:all outputs a different error:

$ node_modules/.bin/sequelize db:seed:undo:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

And when I clear the DB/seederStorage and try to run seed:all:

$ node_modules/.bin/sequelize db:seed:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

None of the :all methods work.

Edit: Apparently :undo needs to pass in a seed name. That makes no sense as I just want to undo the one and only change.

@jocull
Copy link

jocull commented May 12, 2016

Is it possible that the seeder path is looking in the wrong place? Where
are your seeders stored relative to your project root?

On Thu, May 12, 2016 at 11:14 AM, Michele notifications@github.com wrote:

sequelize-data.json:

[
"20160511015238-users-and-groups.js"
]

config.json:

"development": {
"dialect": "sqlite",
"storage": "./db.development.sqlite",
"seederStorage": "json",
"host": "127.0.0.1"
},

$ node_modules/.bin/sequelize db:seed:undo

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
Unspecified flag "seed". Check the manual for further details.

undo:all outputs a different error:

$ node_modules/.bin/sequelize db:seed:undo:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

And when I clear the DB/seederStorage and try to run seed:all:

$ node_modules/.bin/sequelize db:seed:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

None of this works.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#301 (comment)

@mtitolo
Copy link
Author

mtitolo commented May 12, 2016

They are in seeders/

@jocull
Copy link

jocull commented May 12, 2016

Can you try turning on logging? This is why my .sequelizerc file looks like. You might be able to cut it down to just module.exports.logging = true but I'm not sure what all is required.

'use strict'

var path = require('path')
var config = require('config')

config.database.config = __filename

module.exports = config.database
module.exports['migrations-path'] = 'build/migrations'
module.exports['seeders-path'] = 'build/seeders'
module.exports.logging = false

@jocull
Copy link

jocull commented May 12, 2016

Derp, you probably just need to set logging = true in your config...

@mtitolo
Copy link
Author

mtitolo commented May 12, 2016

Magically :seed:all started working. I didn't change anything. This makes no sense. This is ridiculous.

And there's no real info on why undo:all isn't working:

$ node_modules/.bin/sequelize db:seed:undo:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
DEPRECATION WARNING: The logging-option should be either a function or false. Default: console.log
Executing (default): SELECT 1+1 AS result
No seeders found.

@jocull
Copy link

jocull commented May 12, 2016

Strange, I wonder what this means?

Executing (default): SELECT 1+1 AS result

@mtitolo
Copy link
Author

mtitolo commented May 12, 2016

WAIT I did change something. I dropped the table in the DB that used to store the changes instead of the JSON file.

So if there's a SequelizeData table and I'm storing seed migrations in json, :seed:all will not work. Without the table, :seed:all works. :undo:all still doesn't work with or without the table when json is the seederStorage.

If I use sequelize as the seederStorage the commands all work as expected. Something is up with the JSON seederStorage setting that's causing the commands to fail.

@jocull
Copy link

jocull commented May 12, 2016

That should help narrow it down at least! I have been using sequelize for
seederStorage and that fixed my original issue, but the semantics of this
have changed significantly over the past few minor version releases. (Which
is what I was trying to point out earlier)

On Thu, May 12, 2016 at 11:31 AM, Michele notifications@github.com wrote:

WAIT I did change something. I dropped the table in the DB that used to
store the changes instead of the JSON file.

So if there's a SequelizeData table and I'm storing seed migrations in
json, :seed:all will not work. Without the table, :seed:all works.
:undo:all still doesn't work with or without the table when json is the
seederStorage.

If I use sequelize as the seederStorage the commands all work as
expected. Something is up with the JSON seederStorage setting that's
causing the commands to fail.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#301 (comment)

@jocull
Copy link

jocull commented May 12, 2016

I did just try to run sequelize db:seed:undo:all with sequelize
seederStorage and that did nothing, however. I don't usually try to undo,
so I hadn't uncovered this before.

On Thu, May 12, 2016 at 11:35 AM, James O'Cull jocull@delmarsd.com wrote:

That should help narrow it down at least! I have been using sequelize
for seederStorage and that fixed my original issue, but the semantics of
this have changed significantly over the past few minor version releases.
(Which is what I was trying to point out earlier)

On Thu, May 12, 2016 at 11:31 AM, Michele notifications@github.com
wrote:

WAIT I did change something. I dropped the table in the DB that used to
store the changes instead of the JSON file.

So if there's a SequelizeData table and I'm storing seed migrations in
json, :seed:all will not work. Without the table, :seed:all works.
:undo:all still doesn't work with or without the table when json is the
seederStorage.

If I use sequelize as the seederStorage the commands all work as
expected. Something is up with the JSON seederStorage setting that's
causing the commands to fail.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#301 (comment)

@dave-irvine
Copy link

Looks like there are lots of issues with seeders right now. #403 #408

Is there anything like umzug for running seeders programatically rather than via the cli?

@marconi
Copy link

marconi commented May 30, 2017

Seeds are applied in order so if I want seed:undo to always undo the recent migration I use this script entry from my package.json:

"seed:down": "sequelize --seed $(ls ./src/seeds | sort | tail -n 1) db:seed:undo"

But you have to keep in mind before running that you applied all pending seeds, otherwise it'll try to undo a seed that hasn't been applied and that can cause unexpected result depending on that migration's down method.

@Ju66ernaut
Copy link

Ju66ernaut commented Dec 18, 2018

I know this is an old issue but I had a very similar issue and this thread kept coming up when I searched for answers. My problem was I was trying to run a seeder file and it was completing but not actually populating my table. The problem came from the seeder file trying to populate a field that didn't exist. It didn't give me any error. Hope this helps someone else.

codetriage-readme-bot pushed a commit to codetriage-readme-bot/cli that referenced this issue Jun 5, 2019
…-track-status

Return error message for unknown track status
codetriage-readme-bot pushed a commit to codetriage-readme-bot/cli that referenced this issue Jun 5, 2019
@stale
Copy link

stale bot commented Jun 21, 2020

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.

@stale stale bot added the stale label Jun 21, 2020
@stale stale bot closed this as completed Jun 28, 2020
@Jason9071
Copy link

Hay ~ I found the problem here. You're missing await here.
You need to wait for the promise to come back~
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants