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

db:create not working on branch bump-7-2 #415

Closed
dorner opened this issue Oct 31, 2024 · 14 comments · Fixed by #418
Closed

db:create not working on branch bump-7-2 #415

dorner opened this issue Oct 31, 2024 · 14 comments · Fixed by #418

Comments

@dorner
Copy link
Contributor

dorner commented Oct 31, 2024

When I try running rake db:create, I get the following error:

ActiveRecord::Tasks::DatabaseNotSupported: Rake tasks not supported by 'postgis' adapter (ActiveRecord::Tasks::DatabaseNotSupported)

If I add this in an initializer, it works:

ActiveRecord::Tasks::DatabaseTasks.register_task(/postgis/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")

Not sure if this is something that used to be handled automatically and no longer is with Rails 7.2. I can whip up a PR if y'all like, just wanted to double check if I was doing something wrong.

@BuonOmo
Copy link
Member

BuonOmo commented Oct 31, 2024

Yep, open a PR!

@dorner
Copy link
Contributor Author

dorner commented Oct 31, 2024

Started looking at how we could possibly add a test for this, but I went down a rabbit hole and there isn't anything simple. There's definitely something complicated, which would involve us creating a mini-Rails app, or manually loading all the Rails DB tasks. What's your suggestion - do I just ignore tests for now, or try to get something working?

@keithdoggett
Copy link
Member

@dorner we used to have a test for tasks in older versions. This PR removed the deprecated tasks, but this is the file we used to test them: https://github.com/rgeo/activerecord-postgis-adapter/pull/353/files#diff-7b02d5d1111ed5b54c5fe75fb4796e01b12d15ba0db38212fb628f8516e379a4. That should be a sufficient structure to test this on.

@keithdoggett
Copy link
Member

Actually, @dorner it appears this is already in the branch:

Tasks::DatabaseTasks.register_task(/postgis/, "ActiveRecord::Tasks::PostgreSQLDatabaseTasks")
. Not sure why it's not working as expected though.

@dorner
Copy link
Contributor Author

dorner commented Oct 31, 2024

Ah good catch! I'll do some spelunking to see if there's a loading issue. I'll try to bring back that file just to test this for backwards compability with existing Rails tasks.

@BuonOmo BuonOmo mentioned this issue Nov 1, 2024
@keithdoggett
Copy link
Member

Hey @dorner I just made a new rails app and was able to run db:create from the 7.2 branch. Are you seeing that issue as well or is this occurring on an existing app?

@dorner
Copy link
Contributor Author

dorner commented Nov 1, 2024

It was a new one. I'm going to try to dig into this either today or next week.

@dorner
Copy link
Contributor Author

dorner commented Nov 4, 2024

Tried this again and it seems to be working. No idea what happened before. Closing this, will reopen if I figure out anything else :)

@dorner dorner closed this as completed Nov 4, 2024
@dorner
Copy link
Contributor Author

dorner commented Nov 4, 2024

OK interesting. rails db:reset works but rails db:create does not.

@dorner dorner reopened this Nov 4, 2024
@dorner
Copy link
Contributor Author

dorner commented Nov 4, 2024

Yup. Looks like the PostgisAdapter file is not loaded on db:create since it's first loaded when a connection is attempted. db:create doesn't attempt a connection before running.

I'm wondering if something else in your new app is "accidentally" creating a connection and hence the adapter registration happens.

The code itself is super easy (just add the register call to the very base Ruby file). The test file you linked doesn't really help because it calls the database module directly - the whole issue here seems to be related to a loading problem. Would it be OK to put in a PR without a corresponding test?

@keithdoggett
Copy link
Member

@dorner I think that's fine since it's just a loading issue

@dorner
Copy link
Contributor Author

dorner commented Nov 5, 2024

PR is up! #418

@dorner
Copy link
Contributor Author

dorner commented Nov 6, 2024

Got the problem! The issue is happening only when there are multiple databases, and a secondary database is postgis.

Using this database.yml:

development:
  primary:
    host: <%= ENV['DB_HOST'] %>
    database: <%= ENV['DB_DATABASE'] %>
    username: <%= ENV['DB_USERNAME'] %>
    password: '<%= ENV['DB_PASSWORD'] %>'
    adapter: trilogy
    port: 3306
  other:
    host: <%= ENV['DB_HOST'] %>
    database: <%= ENV['DB_DATABASE'] %>
    username: <%= ENV['DB_USERNAME'] %>
    password: '<%= ENV['DB_PASSWORD'] %>'
    adapter: postgis
    port: 5432
    encoding: utf8

test:
  primary:
    host: <%= ENV['DB_HOST'] %>
    database: <%= ENV['DB_DATABASE'] %>
    username: <%= ENV['DB_USERNAME'] %>
    password: '<%= ENV['DB_PASSWORD'] %>'
    adapter: trilogy
    port: 3306
  other:
    host: <%= ENV['DB_HOST'] %>
    database: <%= ENV['DB_DATABASE'] %>
    username: <%= ENV['DB_USERNAME'] %>
    password: '<%= ENV['DB_PASSWORD'] %>'
    adapter: postgis
    port: 5432
    encoding: utf8

@dorner
Copy link
Contributor Author

dorner commented Nov 6, 2024

I'm not sure how common this case is, but in my case I'm writing a pipeline viewer that collates data across multiple microservices' data stores, which is where I ran into this.

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

Successfully merging a pull request may close this issue.

3 participants