0

I have an existing Postgres database with various schemas, tables, defined users and data. There are many existing Rails apps, which I didn´t develop, that are connected to it. Now I'm creating a new app, and it's been complicated.

I installed the pg gem via gemfile and bundle. After that, I edited the config/database.yml as I show below:

default: &default
  adapter: postgresql
  database: ****
  schema_order: ****
  encoding: UTF8
  host: ****
  port: ****
  allow_concurrency: true
  username: ****
  password: ****

development:
  adapter: postgresql
  database: ****
  schema_order: ****
  encoding: UTF8
  host: ****
  port: ****
  allow_concurrency: true
  username: ****
  password: ****

production:
  <<: *default

So, I created a default simple view and controller to start coding from there on, but when I run the app in my localhost, the following error pops up:

ActiveRecord::StatementInvalid
PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations

And in the terminal I can see the following query:

ActiveRecord::SchemaMigration Pluck (1.9ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC

Which I don't understand, because I don't have any migrations and therefore theres no db/schema.rb. And also, not less important... Obviously, the schema_migrations table doesn't exist. The db wasn't created using migrations. I understand that ActiveRecord uses migrations for this, but how can I "disable" this? I mean, If all the other apps are working, obviously there is a workaround for this. But I can't find it.

  • Try checking solutions here: https://stackoverflow.com/questions/38271376/rails-pginsufficientprivilege-error-permission-denied-for-relation-schema-m – Gerardo S May 09 '22 at 14:08
  • 1
    I really hope you didn't just post your real database credentials here. Otherwise you need to **immediately** change them and investigate if your data has been leaked. – max May 10 '22 at 11:04
  • NEVER post your DB Credentials publicly. NEVER. – Zamir Manihar May 11 '22 at 07:03
  • They weren't the real credentials, but I removed them to avoid misunderstandings. Really thanks for the advice btw. – Matías Leandro May 12 '22 at 11:34

1 Answers1

0

Well, I kinda got around it. Nevertheless I can't say I fully solved my problem. I discovered that that error won't show up when I used another users. So, for development it's alright. But I'd like to have defined roles for each app that connects to the DB. I have to investigate a little more about the user settings..