i'm setting up a RoR project and i've got a database.yml file with a specific database with user and password. What i did was to add this file into my project and want to load it. when i run rails s i get an authentication error for the db user. Should i create a new user? should i create the db? Thing is i want to load the records that already exists on it, that's why i'm a little bit lost.
Important fact: i already have a user created with a specific password (for another db) and the username for the new db is the same as my old user (with different password). Would that be a problem?
A database user can have only one password. Change the password in your database.yml to the password of your existing database user.
You have to create the database user that's specified in the database.yml file.
For Postgres, you have to use createuser for this. You'll also have to set the corresponding password and then add the proper privileges.
This might help: https://www.digitalocean.com/community/tutorials/how-to-use-roles-and-manage-grant-permissions-in-postgresql-on-a-vps--2.
Then you can run bin/rails s. The records won't be deleted.
Related
In my rails app, I am using postgresql as my adapter in database.yml file. I want to rename the database and reassigned them to a different owner. So i went ahead and changed my postgres database by running:
ALTER DATABASE old_name RENAME TO new_name;
CREATE ROLE new_role WITH PASSWORD 'pw123';
ALTER USER new_role CREATEDB;
ALTER USER new_role LOGIN;
Then I also modified my database.yml file accordingly
After all that, when i run the app again, the error: InsufficientPrivilege: ERROR: permission denied for relation schema_migrations
This new role has the exact same privilege of the previous owner, but I don't know why it is yelling at the new owner.
I believe I am missing a tiny thing here, but i would not figure out what. So what should i do to let my app accept the new postgresql changes?
The database has changed ownership, but the objects in it have not. So the schema still belongs to the old user, and the new user has no permissions on it.
When it comes to permissions and ownership, databasea are objects like all other objects. To use an analogy, you don't own everything in a house just because you own the house.
The REASSIGN OWNED SQL command can change ownership of all objects in a database.
I've moved my development environment from sqlite to postgresql on Cloud9 IDE, following this post Cloud9 postgres.
Now just about everything works,
created a new db
migrated table changes
saved data to db with rake tasks
rendered data from the db in views
But when I run rails c and try and load data there, it fails.
Item
=> Item (call 'Item.connection' to establish a connection)
Item.all
=> PG::ConnectionBad: fe_sendauth: no password supplied
I don't think its actually a no password issue because in every other way I can access and work with the database... just not in rails console.
Does maybe something need to be done to setup a new connection here?
the main issue is POSTGRES need a role to be setup , no doubt the app must be working fine, but when u type in rails c , the control access the schema file and tries to load all the table, here the table ITEM must be the first one to be read by control.
all you need to do is create a role in postgres as superuser and type in its credentials in database.yml.
let me know if this works
I have two users in postgresql one of which is called migration and is used when Rails runs migrations on the production server. This user owns the production database. I also have production user who is supposed to have only the following privileges: SELECT, INSERT, UPDATE, DELETE on the production database.
Problem is, every time a new table is created, I have to manually run this in psql:
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO production;
-- next line is needed for each new table which has an auto incrementing field, in this case - table `users`
GRANT USAGE, SELECT ON SEQUENCE users_id_seq TO production;
because permissions for production user on newly created tables are not set automatically. What's the best way to do it automatically when running migrations? Any script available for Rails/Capistrano?
You could use Postgres' ALTER DEFAULT PRIVILEGES to have it automatically assign the rights to production for all newly created tables.
Alternatively, you could write a custom Capistrano task to set the permissions that is called through the after "deploy:migrate", "mycustomtaskname" hook. This pastie might give you a few good hints on how to interact with pgsql through Capistrano, for example how to provide the password interactively.
I have symfony 1.4 installed and had setup my own user model (table). Now, in order to use sfFacebookConnectPlugin, it asks to use sfGuard plugin, so it can easily integrate existing users with facebook account.
Is there a way to use sfGuardPlugin with existing user model ?
OR
is there a better way to implement facebook connect, such that it recognizes the same user (by email), if exists, or creates a new user in the user table with the fb email id and also creates the session.
Thx !
You can use sfGuardPlugin with an existing model, the schema file will be loaded from the plugin's folder and the table names are namespaced in a way that prevents naming collisions.
All you have to do is install the plugin as per its installation instructions and then build your model. To deploy to production you can either copy the SQL that propel generates (in data/sql) and execute it or use a program like Toad for MySQL to generate diff sql upgrade scripts.
Have you tried and failed? I hope I've addressed your concerns.
I'm a Rails novice, but am currently trying to modify an existing application that I inherited.
I'm running some db migrations that create new tables on our staging server (Not local machine) and all the new DB tables create seem to have different permissions than the tables already created.
I am running "rake db:migrate VERSION=20110213100531 RAILS_ENV=staging" with one sshlogin and I have my sql login defined in my database.yml under staging as separate mysql database login.
Is there any particular settings/user I should be running my db migration under?
From what you've said I think most likely your problems are being caused from the way you have your user permissions set up in the remote database. This is not something that can be altered from the rails side.
Your database.yml file will just specify your login details into that database, but it's up to you to modify your user permissions settings in your database.
If you've got admin access into your database, I'd start by comparing the previous user's permissions to your own and seeing what's the difference.
All the best