Rake file is seeing old version of database on Heroku - postgresql

I'm using a rakefile to seed my database. I was seeing weird behavior (see Additional user attributes results in UnknownAttributeError and NoMethodError) and have concluded that it is operating on an old version of my database (at the very least, an old version of my Users table, perhaps more).
Running the rakefile on localhost works fine
On Heroku, printing User.column_names within the rakefile shows the old version of the table
On Heroku, printing User.column_names from within the main app shows the new version of the table
Within Heroku rails console, User.column_names shows the new version of the table
Any ideas how to resolve?

One thing to make sure you do on heroku is restart your dynos correctly. A client of mine once tried something like this:
heroku run rake db:migrate db:seed_data
Heroku's documentation at https://devcenter.heroku.com/articles/rake mentions that you should restart your app in between migrations:
After running a migration you’ll want to restart your app with heroku
restart to reload the schema and pickup any schema changes.
So the answer might be to not batch it in the same process; i.e. try something like
heroku run rake db:migrate; heroku run rake db:seed_data

Related

Keystone Next not showing database type and always select postgresql by default

I'am new user for using keystone and will create simple project with keystone, but I've some problem when generating project by yarn always select postgresql as default database type.
Below is example screenshot when I'am create new project with keystone next
[1]: https://i.stack.imgur.com/GX4i4.png
The yarn create keystone-app command your running uses create-keystone-app, documented here. The resultant app simply expects a Postgres database. If you don't already have it, you can install Postgres using brew or Postgres.app (on MacOS) or one of the official installers.
If you don't want to use Postgres you'll need to create your project another way. Clone the Keystone repo and have a look at the examples directory. It's full of very simply starting points that use an SQLite db instead.
Sept 2021 Update
create-keystone-app has been updated to use SQLite by default now so it won't prompt for a DB connection string at all. You can still switch to Postgres manually if you want but it's a manual step.
The walkthrough has details.

Did anyone manage to get the DVDRental example using Direct to SwiftUI running?

I've loaded the finished DVDRental demo app
with
git clone -b branches/10-customized \
https://github.com/DirectToSwift/DVDRental.git
as well as tried it with
git clone -b branches/01-default-rulemodel \
https://github.com/DirectToSwift/DVDRental.git
(see http://www.alwaysrightinstitute.com/directtoswiftui/) and restored the demo database.
Currently, I am trying to execute the app, following the instructions on http://www.alwaysrightinstitute.com/directtoswiftui/ and ReadMe from https://github.com/DirectToSwift/DVDRental. Which means I have named the database accordingly and built the app. In fact, you should only install the database, download the project and it should be running without any change. However, the app remains on the launch screen, showing a "connecting database" message.
Through an exhaustive debugging process, I came to the conclusion that there is something wrong with the authentication. However, I could not determine what exactly goes wrong.
Is there anybody who tried it and it worked?
Using:
Xcode 11.3.1; Swift 5; iOS 13; Postgres.app Version 2.3.3e; PostgreSQL 12
Any idea how to solve the problem?
Update: there is no problem with the database. I can connect via psql, clients such as postico or navicat, or with my own apps using PostgresClientKit. The problem has been tracked down to the authentication process. Therefore I'm pretty sure that the problem lies somewhere there
Apparently, the developers "forgot" to enable authentication.
Right, it is quite possible that I didn't have auth on. I'll see
whether I can give it a try on the weekend.
needless to say, two months later it is still not fixed

How do I run mongo-express (without authentication)?

According to the official documentation for the web-based MongoDB admin interface mongo-express, one starts the tool using
cd YOUR_PATH/node_modules/mongo-express/ && node app.js
However, this does not seem to work. If I execute it on my system, I only get the "Usage" info console output. No error output. The same is true when using whatever combination of username / password / database parameters.
The mongod process works perfectly. Even the alternative tool mongomate (read-only) works fine on my system. I have created a simple test database, no authentication. All config settings on default.
Am I supposed to configure anything before using the application? I remember very clearly that I managed to get this to work very easily on another system some time ago, but now I just don't manage to get it started. Googling for "mongo-express" doesn't yield any helpful results either.
mongod db version is v3.2.0.
mongo-express version is 0.27.6.
OK, after reinstallation with the current version it worked again.
Current Version of mongo-express version is now 0.28.8.
Further investigation: After an experimental downgrade to the original version 0.27.6, it stopped working again, meaning that there was something wrong with that release. Upgrading to a newer version solved the issue.

Grouping rake tasks from other gems

To avoid having to trigger many rake tasks when I want to reinitialize my project I created the following task in lib/task/twiddle.rake:
task :twiddle => %w(db:drop db:create railties:install:migrations db:migrate db:seed spree_sample:load)
Triggering each of these command from the command line works.
However running rake twiddle hangs when it reaches spree_sample:load with the following error:
NoMethodError: undefined method `slug' for #<Spree::Product:0x0000000ec9b9f0>
Could someone explain why running a set of specific tasks would works on the CLI and not through the rake task? Should I require some libraries?
The answer's relatively simple actually - Rails loads schema information from the database only when it boots. (You can do something like reset_schema_information to force it to reload)
You generally don't ever do db:migrate followed by db:seed right after because Rails won't reload the app between the migration and the seeding. Therefore, when db:seed runs, it will have no table information. This is why you see different results if you run them individually -- the act of running them individually makes Rails reload itself and fixes the catch-22 of trying work with a schema that is only made available by the previous command.
Also railties:install:migrations makes no sense in your task-- you only run that yourself as the developer 1 time, it creates several migration files (which you check-in to git), and then those files live in your app forever. You don't re-run railties:install:migrations on regular basis, since you've already created those migration files. (You do re-run it when you upgrade spree, but that's a different matter)

symfony2 locale and deployment

I am in the proces of creating a web application in symfony2. I have done all the development locally(OSX), but now I want to show a first version in a presentation where I can not use my own laptop.
I am deploying to an ubuntu 10 server. I also tested it on another small ubuntu 11 vps, but got the same problems.
I double checked with this tutorial whether php is set up correctly for symfony on my ubuntu server:
http://www.joelverhagen.com/blog/2011/05/how-to-configure-symfony-2-0-on-ubuntu-server-2011-4/
For deployment I followed these steps:
Moving app to production mode in Symfony 2
However the first step ( php app/console cache:clear --env=prod --no-debug ) gives me following error (this error also occurs when running this command locally):
php app/console cache:clear --env=prod --no-debug
Clearing the cache for the prod environment with debug false
[ReflectionException]
Class Packed\Bundle\UserBundle\Entity\Rapport does not exist
cache:clear [--no-warmup] [--no-optional-warmers]
Which is a bit weird since Packed\Bundle\UserBundle\Entity\Rapport does not exist, Packed\Bundle\ScoreModelBundle\Entity\Rapport however does.
since the app doe not need to go into production for some time this is not very urgent, what is very urgent is to get it running in development mode, so I tried using it through app_dev.php.
If I remove the localhost-check in app_dev.php everything works as expected but the i8n is not working... I can not switch to other locales as was possible locally:
xxx.com/app_dev.php/en
And it does not use the messages.nl.yml, messages.en.yml, ... and other files.
Any idea what might be causing this?
I checked the symfony and apache log but nothing weird there. Any other logs I should check?
Thanks!
Joris
Try to rebuild your bootstrap file. If you're using APC-cache restart it from cli. If it doesn't help.
Easiest way to do it is run composer and do the update.
To check the translations (the templates should be cached on the server) check the config.yml translator service must be enabled there. You may have it enabled in config_dev.yml but not in the config_prod.yml