Kathan
Kathan

Reputation: 1458

Rails 4 - Move DB Column from One App to Another

I am wondering if there is a way to move a single column of a database from one rails app to another.

The reason for this: I just programmed a fresh, new version of my website. It is much cleaner. In the new version, I have also eliminated many unnecessary columns to the database. Essentially, what I would like to do is pull in the old database (which is on heroku) to my new app, while accounting for columns that no longer exist. I figured the best way to go, in this case, would be column by column. The tables and columns have the same names.

Any recommendations? Not sure the best way to go about this and having a hard time finding any documentation.

Upvotes: 1

Views: 69

Answers (1)

Richard Peck
Richard Peck

Reputation: 76774

You generally migrate SQL db's by exporting (dumping) the SQL data and then transferring to another database.


With Heroku's PGSQL you should use pg_dump & pg_restore;

heroku pg:backups capture #-> do this on your "old" app -- captures your database
heroku pg:backups restore 'https://s3.amazonaws.com/path/to/public/db.dump' DATABASE_URL #-> do this on your "new" app

Looks like there is a plugin for this (heroku-pg-transfer):

 heroku plugins:install https://github.com/ddollar/heroku-pg-transfer

 $ env DATABASE_URL=postgres://localhost/myapp-development heroku pg:transfer

Overview

I've done this countless times (in MYSQL) by downloading a .sql file from one db, and then using it to populate another. The .sql file is simply a list of queries for each table, populating with the data inside the database.

Here's how you do it with PHPMyAdmin (for demonstration purposes):

enter image description here

You then get a .sql file:

enter image description here

You can read up about it (kind of) here: MYSQL Migration

It's the same in PGSQL - you're downloading an SQL dump, and then uploading it to a new server.

This - of course - will give you exactly the same database as you had before; if you want to change it, you'll either have to go through the .sql file, or change the table once it's up in your new environment.

Upvotes: 1

Related Questions