Home > Software design >  Trying to connect Rails 7 to existing PG DB
Trying to connect Rails 7 to existing PG DB

Time:05-14

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.

CodePudding user response:

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..

  • Related