Installation rake task breaks if Postgres is not setup


(Jordan Elver) #1

If you run the install (rails g push_type:install) without first changing the config/database.yml to use Postgres, the error below occurs.

[I] ~/D/P/p/push_type_demo (master) $ rails g push_type:install
      create  config/initializers/push_type.rb
      insert  config/routes.rb
- Copying migrations
        rake  railties:install:migrations
Copied migration 20150824205449_create_push_type_users.push_type.rb from push_type
Copied migration 20150824205450_create_push_type_nodes.push_type.rb from push_type
Copied migration 20150824205451_create_push_type_node_hierarchies.push_type.rb from push_type
Copied migration 20150824205452_create_push_type_assets.push_type.rb from push_type
Copied migration 20150824205453_create_push_type_taxonomies.push_type.rb from push_type
Copied migration 20150824205454_create_push_type_taxonomy_hierarchies.push_type.rb from push_type
Copied migration 20150824205455_add_field_store_default_values.push_type.rb from push_type
Copied migration 20150824205456_devise_extend_push_type_users.push_type_auth.rb from push_type_auth
- Running migrations
        rake  db:migrate
== 20150824205449 CreatePushTypeUsers: migrating ==============================
-- extension_enabled?("uuid-ossp")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `extension_enabled?' for #<CreatePushTypeUsers:0x007fc0e27e3970>/Users/jord/Dropbox/Projects/push_type/push_type_demo/db/migrate/20150824205449_create_push_type_users.push_type.rb:4:in `change'
NoMethodError: undefined method `extension_enabled?' for #<CreatePushTypeUsers:0x007fc0e27e3970>
/Users/jord/Dropbox/Projects/push_type/push_type_demo/db/migrate/20150824205449_create_push_type_users.push_type.rb:4:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

We should probably a) Handle this error better; and b) Explicitly mention editing the config/database.yml in the setup instructions. The installation instructions say “Assuming you have a Rails app ready to go”, but I think this will be a common mistake.

We can find out what database is being used with this

ActiveRecord::Base.connection.adapter_name
=> "PostgreSQL"

What do you think?


PushType development roadmap
(Aaron Russell) #2

Fair shout. Do you want to sort this out @jordelver?

I think the PushType::InstallGenerator should check ActiveRecord::Base.connection.adapter_name as the first thing it does, and then print out a friendly message if we’re not on Postgres.

Is it possible to also check the postgres version? We need 9.4 so it would be good if we could check that too.

In terms of docs, posgres is already a documented requirement, but I’ll take a look at the installation instructions and see if we can reinforce that point.


(Jordan Elver) #3

Yeah, sure. I’ll take a look at this.


(Jordan Elver) #4

How do I get the tests running? I cd’d into the core directory and ran rake test_app as instructed but when I run rake test it fails saying I should run the migrations, but when I try that it too fails.

bundle exec rake db:migrate RAILS_ENV=test
rake aborted!
Don't know how to build task 'db:migrate'

(Aaron Russell) #5

Not totally sure but think you maybe need to bundle in each of the four gems within the project, like so:

cd core && bundle
cd ../admin && bundle
cd ../auth && bundle
cd ../wysiwyg && bundle

And then you should be able to go to the root and run the tests.

Let me know - if that gets you up and running then there should probably be a setup rake task.


(Aaron Russell) #6

Hey @jordelver, did you manage to get the tests up and running?


(Trickierstinky) #7

Hey guys,

Just wondering if this ever got fixed?

After seeing your little note on the BathRuby Opensource board, I thought I’d check it out and seems that I still can’t run rails g push_type:install for sqlite.

Sorry I know the requirements do state that postgres is required, but thought it could be interesting to see if it would be possible.

Thanks
Matt


(Aaron Russell) #8

@Trickierstinky thanks for checking it out. PushType depends on Postgres because it makes heavy use of the jsonb datatype. It’ll probably never work with SQLite or MySQL.

What we do want to do is handle situations where people try to install it in to a app with an incompatible database better - basically with a friendly message instead of a error stack.

Let me know if you need any help getting set up.


(Emin) #9

Fixed by installing this: sudo apt-get install postgresql-contrib-9.4


I have a similar problem.

PostgreSQL 9.4 on Raspberry Pi 3.

Rails 4.2.6 and ruby 2.3.1p112 (2016-04-26 revision 54768) [armv7l-linux-eabihf]

pi@superyumruk:~/super $ rails g push_type:install
Running via Spring preloader in process 22146
      create  config/initializers/push_type.rb
      insert  config/routes.rb
- Copying migrations
        rake  railties:install:migrations
Copied migration 20161127023449_create_push_type_users.push_type.rb from push_type
Copied migration 20161127023450_create_push_type_nodes.push_type.rb from push_type
Copied migration 20161127023451_create_push_type_node_hierarchies.push_type.rb from push_type
Copied migration 20161127023452_create_push_type_assets.push_type.rb from push_type
Copied migration 20161127023453_add_field_store_default_values.push_type.rb from push_type
Copied migration 20161127023454_drop_legacy_push_type_taxonomies.push_type.rb from push_type
Copied migration 20161127023455_devise_extend_push_type_users.push_type_auth.rb from push_type_auth
- Running migrations
        rake  db:migrate
== 20161127023449 CreatePushTypeUsers: migrating ==============================
-- extension_enabled?("uuid-ossp")
   -> 0.0035s
-- enable_extension("uuid-ossp")
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::UndefinedFile: ERROR:  could not open extension control file "/usr/share/postgresql/9.4/extension/uuid-ossp.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
/home/pi/super/db/migrate/20161127023449_create_push_type_users.push_type.rb:4:in `change'
ActiveRecord::StatementInvalid: PG::UndefinedFile: ERROR:  could not open extension control file "/usr/share/postgresql/9.4/extension/uuid-ossp.control": No such file or directory
: CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
/home/pi/super/db/migrate/20161127023449_create_push_type_users.push_type.rb:4:in `change'
PG::UndefinedFile: ERROR:  could not open extension control file "/usr/share/postgresql/9.4/extension/uuid-ossp.control": No such file or directory
/home/pi/super/db/migrate/20161127023449_create_push_type_users.push_type.rb:4:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

(Mark Kramer) #10

What about those who are getting this error even after PostgreSQL is set up and running? I have been running into an unblievable amount of errors trying to get PostgreSQL to work, it’s a complete nightmare. After two days of trying to get it to work, it finally does. I can run queries on it and I can connect to it from a local network using phppgadmin, yet when I try to install Push_Type I still get:

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `extension_enabled?’ for #<CreatePushTypeUsers:0x000000053d5dd8

And yes, postgresql-contrib-9.5 is already installed.

UPDATE: I found out all the errors I couldn’t fix were due to using SSH, doing all my work directly on the system I had no issues at all.