I have a Rails 3.1 app, which lets end user to add/update customer's information list. Now I have a request to sync this cust_info table with a db on a remote machine. So whenever a change has been made in Rails, it automatically update the remote db. What's the best way to approach this?
I'm thinking of setting up a remote db access in config/database.yml and create a model to establish a connection to that db. But in my controller, when a customer's info gets saved, how do I use that remote db connection to update one table? Should I write a raw sql query?
Thanks.
Related
I have a remote Firebird 3.0 server with a database. In this database, there is a big table. The client very often queries this table during their work. There are too many clients and bad internet connection, so the work with this table is terrible. I made a local copy of this table via IBExpert into a temporary database, which is distributed with client application.
But now there is a need in a change of some values in this table (add new values and edit some olds). So I need some kind of synchronization - copying of remote modified table to client's local database.
The client application was made by use of Delphi Berlin 10.1. So the synchronization should be done by Delphi code.
Can you give me an idea, how it will be correctly to synchronize such a big table, please?
You could fire POST_EVENT on master database (for insert, update, delete (triggers)) to notify client applications that there are changes.
Then your client would need to fire procedure (on local DB) to do a sync. This could be done by EXECUTE STATEMENT ON EXTERNAL
FOR EXECUTE STATEMENT ('SELECT ... WHERE CURRENT_TIMESTAMP >= tablename.modifiedon')
ON EXTERNAL 'SERVER/PORT:DBPATH'
You should include date of insert/modified/delete in master DB.
What I'm trying to do is to transfer my Company model that has a lot of associations, depots, products, users, owners, etc, to another database(server). I've tried cloning the company but it doesn't get the associations. How exactly can I get the Company data and it's children to the other database? I don't want to dump my data and restore it, I want to establish a connection between the two databases and be able to transfer what data I have from the first server to the second.
I'd suggest instead do this on the data base level rather than the application level. This would result in a more reliably faithful copy of the data.
For Postgres, you can do the following (found at https://www.google.com.tw/search?q=postgres+backup+and+restore&ie=utf-8&oe=utf-8):
Backup a local postgres database and restore to remote server using single command:
$ pg_dump dbname | psql -h hostname dbname. ...
I'm migrating the previous database to my new application I have a dump file imported from heroku and there are some tables missing in the dump file as well in almost every table there are some attributes missing so for this I'm creating a new database and imported the dump in that database, and when I imported that from that DB and close the connection so that I can create a new connection with the production database where I need to migrate the data the connection is closed but the instance variables which I stored the data from the previous database is also reset so can anybody tell me how to close the Postgre DB connection and open a new connection to a different PG DB without loosing the saved data fetched from previous DB to populate the second DB.
I am using this to establish the connection
ActiveRecord::Base.establish_connection('DB')
and I'm using to close the DB connection
ActiveRecord::Base.clear_active_connections!
Please answer my question?
I solved this by creating setup for two databases in the database.yml
and added two methods for database connections one for one database connection using the
def xyz_connection
ActiveRecord::Base.establish_connection('DB')
end
and second for second DB connection like
def abc_connection
ActiveRecord::Base.establish_connection('DB')
end
and called them both where required and I did my insertions and DB manipulations and after that I suspended the connection from required DB.
I've added heroku postgres addon.
The DATABASE_URL is something like postgres://xxxxxxxxx:xxxxxxxx#xxxxxxxxx.compute-1.amazonaws.com:5432/ddo2ahvosfggq
I want the database name to be like my_app_database. I want to rename ddo2ahvosfggq to my_app_database.
How can I do that?
Can I use ALTER DATABASE? http://www.postgresql.org/docs/9.1/static/sql-alterdatabase.html
There is already a question in StackOverflow How to rename database in Heroku?
But the answers is to rename the app. I don't know how renaming app will work?
If my_app is the name of my heroku app. Will the below DATABASE_URL work?
postgres://xxxxxxxxx:xxxxxxxx#xxxxxxxxx.compute-1.amazonaws.com:5432/my_app
You can't. It's a Database-as-a-Service (DBaaS) and database name is not customizable there. You just get it from the service and use. Since it's not a user-facing detail for web applications, pretty names are of no use. So why bother?
Most actions you can do with your database are listed on Heroku Postgres website. You can:
regenerate credentials (that don't include database name, only username and password)
wipe the database (that doesn't rename the database as well, just drops the tables)
create one more database (but it will be named randomly, just as all the others)
You don't ever really need to type in the name of the production database on Heroku.
Heroku has a post commit hook which writes the production DB details into /config/database.yml.
If you ever really need to to query the database without a model you would establish a connection by:
ActiveRecord::Base.establish_connection
query = ActiveRecord::Base.connection.execute('SELECT * FROM foo;')
I am currently writing RoR applications and deploying using Heroku.
Is there any way to connect directly to the DB using a connection string?
I guess what I am asking here is can I connect directly to the DB, is there a connection string, how can I get the connection string, etc. I want to be able to perform querys on the DB outside of the terminal I am developing. My current solution is using
heroku db:pull 'anotherPOSTGRESQLdatabasesCONNECTIONstring'
and then performing queries on that database, but this is not a valid solution, because I am developing this application for users who are not code savvy, and they should be able to perform queries on the database without me or them using the terminal.
I think what you might be asking is available here: https://postgres.heroku.com/
Click "Try For Free", Select the option where you already have a heroku account, login with the correct credentials.
Now you can choose the database you want to perform actions on, and create "Data Clips" that your clients can run to get data reports etc (data clips can be used to run arbitrary select SQL commands).