davidwkaiser / walkoff

2 stars 0 forks source link

Can't run migration on fresh install #11

Open chagan opened 7 years ago

chagan commented 7 years ago

Ok, so I ran into the same problem @davidwkaiser did while trying to run the app locally. After playing around a bit, looks like the issue is line 7 in scheduler.rb.

games = Game.where.not(state: "POSTGAME")

I commented that out and ran into a different error, but the games reference problem went away. I think maybe the scheduler is running before the migrations are complete or something? Really don't know enough about how rails works to say. But that's where the problem is. Any thoughts, @H12 ?

H12 commented 7 years ago

@chagan, did you run the migrations before trying to start the server?

Any rails app needs to have it's databases created with rails db:create and migrated with rails db:migrate before you can get anything to work.

If the migrations hadn't been run before rails s then it might make sense that it failed at line 7 in the scheduler. The initializers run before everything else, and it looks like that's the first line in any of our initializers which queries the database. So if the database hadn't been set up, that would be the first line to break.

To try to replicate these issues tried dropping the database on my working branch and starting from scratch with master. Un(?)fortunately it worked fine, so I'm not really sure how to proceed on my end.

davidwkaiser commented 7 years ago

So, when deploying on Heroku at least, when you reply the first time, it handles the db:create function itself, but you still need to migrate it with:

heroku run rake db:migrate

David Kaiser, PhD, PCC Language Geek & Coach Turned Coder

On Mar 27, 2017, at 10:27 PM, Henry Firth notifications@github.com wrote:

@chagan https://github.com/chagan, did you run the migrations before trying to start the server?

Any rails app needs to have it's databases created with rails db:create and migrated with rails db:migrate before you can get anything to work.

If the migrations hadn't been run before rails s then it might make sense that it failed at line 7 in the scheduler. The initializers run before everything else, and it looks like that's the first line in any of our initializers which queries the database. So if the database hadn't been set up, that would be the first line to break.

To try to replicate these issues tried dropping the database on my working branch and starting from scratch with master. Un(?)fortunately it worked fine, so I'm not really sure how to proceed on my end.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davidwkaiser/walkoff/issues/11#issuecomment-289652261, or mute the thread https://github.com/notifications/unsubscribe-auth/AKaHJMNZX2A4jAmQUIWh8kJfLb8JKgAFks5rqH4tgaJpZM4MrFTM.

H12 commented 7 years ago

Alright, I've been able to replicate the same issues locally that we've been having on Heroku. I'll bang my head against this and let you know if when/if I come up with anything.

tejaykodali commented 7 years ago

I tried messing around with this last night, not sure if I didn't do the migrations correctly, but I'm unable to replicate locally.

davidwkaiser commented 7 years ago

@tejaykodali couldn't replicate it working or couldn't replicate the error?

tejaykodali commented 7 years ago

Unable to replicate the error.

chagan commented 7 years ago

So I got it to work, but it was a little hacky.

The issue is that before any migrations or setup happens, rails calls environment.rb, which calls the initializer. That leads to the scheduler running before the database is set up.

I got around that by commenting out the initialization in environment.rb, running rake db:create and rake db:setup. Then I uncommenting the initializer line and ran rake db:migrate. After that, I can rails s and see the app running locally.

Not sure if this means we need to rewrite anything (don't know enough about rails, and it is working in most cases it seems), but that's how I got around it.

davidwkaiser commented 7 years ago

Awesome, Chris. I suspect we can upload to Heroku or the dev environment you mentioned the same way, comment out the initializers, run the DB migrations, then upload changes with the functioning initializers.

My guess is that we inadvertently did it this way during the development process.

I think we’re good to go!

David Kaiser, PhD, PCC Language Geek & Coach Turned Coder

On Mar 28, 2017, at 6:59 PM, Chris Hagan notifications@github.com wrote:

So I got it to work, but it was a little hacky.

The issue is that before any migrations or setup happens, rails calls environment.rb https://github.com/davidwkaiser/walkoff/blob/master/config/environment.rb, which calls the initializer. That leads to the scheduler running before the database is set up.

I got around that by commenting out the initialization in environment.rb, running rake db:create and rake db:setup. Then I uncommenting the initializer line and ran rake db:migrate. After that, I can rails s and see the app running locally.

Not sure if this means we need to rewrite anything (don't know enough about rails, and it is working in most cases it seems), but that's how I got around it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davidwkaiser/walkoff/issues/11#issuecomment-289941007, or mute the thread https://github.com/notifications/unsubscribe-auth/AKaHJM402je4gg-ac24EBTeucCBFH-ZQks5rqZ7XgaJpZM4MrFTM.

chagan commented 7 years ago

@davidwkaiser, did you want to give heroku another shot, and if we're still having issues I can set it up on AWS?

davidwkaiser commented 7 years ago

I can, but we would be left with the problem that it will wind down if no one is actively looking at it. Would AWS be different? If so, I think we should deploy there. If not I can deploy to Heroku and we can just ping it every so often to keep it awake...

David Kaiser, PhD, PCC Language Geek & Coach Turned Coder

On Mar 30, 2017, at 8:05 PM, Chris Hagan notifications@github.com wrote:

@davidwkaiser https://github.com/davidwkaiser, did you want to give heroku another shot, and if we're still having issues I can set it up on AWS?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davidwkaiser/walkoff/issues/11#issuecomment-290587540, or mute the thread https://github.com/notifications/unsubscribe-auth/AKaHJGvXohALSwTJzpkTI8U0fPJpf57nks5rrFFJgaJpZM4MrFTM.

davidwkaiser commented 7 years ago

OK, I can’t get this to work on Heroku, or locally, because I already have the original version of walkoff created as a DB on my PC.

Chris, would you be willing to push this to my Heroku if I give you the key and walk you through it? I reserved walkofftwitterbot.herokuap.com http://walkofftwitterbot.herokuap.com/ for us.

Or is it easier to just push to AWS?

David Kaiser, PhD, PCC Language Geek & Coach Turned Coder

On Mar 30, 2017, at 9:16 PM, David Kaiser, PhD, PCC davidwkaiser@yahoo.com wrote:

I can, but we would be left with the problem that it will wind down if no one is actively looking at it. Would AWS be different? If so, I think we should deploy there. If not I can deploy to Heroku and we can just ping it every so often to keep it awake...

David Kaiser, PhD, PCC Language Geek & Coach Turned Coder

On Mar 30, 2017, at 8:05 PM, Chris Hagan <notifications@github.com mailto:notifications@github.com> wrote:

@davidwkaiser https://github.com/davidwkaiser, did you want to give heroku another shot, and if we're still having issues I can set it up on AWS?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davidwkaiser/walkoff/issues/11#issuecomment-290587540, or mute the thread https://github.com/notifications/unsubscribe-auth/AKaHJGvXohALSwTJzpkTI8U0fPJpf57nks5rrFFJgaJpZM4MrFTM.

chagan commented 7 years ago

I can give it a try on Heroku. Is it easier to hand that off here or in slack?

davidwkaiser commented 7 years ago

slack. i can give you the passwords and instructions there

David Kaiser, PhD, PCC Language Geek & Coach Turned Coder

On Apr 1, 2017, at 1:51 PM, Chris Hagan notifications@github.com wrote:

I can give it a try on Heroku. Is it easier to hand that off here or in slack?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davidwkaiser/walkoff/issues/11#issuecomment-290939667, or mute the thread https://github.com/notifications/unsubscribe-auth/AKaHJHV_aVmNS5vaBvOErZeM_7cj-jo8ks5rrpyrgaJpZM4MrFTM.