Migrating existing rails app from SQLite to PostgreSQL - ruby-on-rails

I saw some of the tutorials on how to migrate from sqlite to postgresql, but it is either for mac or it is for a new/fresh app. What if I already have an App with data sqlite in it. I am using rails 3.2.2 and windows 7. Anyone knows which is the best way to migrate sqlite to postgresql? Thanks

erm, if in development ,u re using sqlite and maybe you have to deploy to heroku, then it is just changing the gem for database. But the data will be blank, if you want to total migrate with data, I guess you have to dump the data and load it in postgresql

Related

Access to database tables location created with migrate in Rails

I did a homework on Rails using RubyMine.
I need to submit the homework with the database tables . But I can't access database tables file location, because I don't know under the which folder I created with migrate. I have migrated tables at the rubymine terminal
I used postgresql for database.
I will be so happy if you could help me. Thank you from now.
There is a schema.rb file that represents your database under db/ folder. So this is the answer for your first question.
The answer to second question is in order to deploy your code on a different computer, the third-party softwares need to be installed. In your scenario, this third-party is postgres as db server. To deploy your code, just type on your terminal rake db:setup. This command will create your database, run migrations and finally seed your database if db/seed.rb contains something. As a result, after rails s there should be some output.
It is worth to note that Rails is db agnostic framework. If you did not use postgres specific features then you would use mysql or sqlite on different computers/servers. But keep in mind that you should change the adapter from config/database.yml if you want to use another database.
Ödev sunumunda başarılar.

Ubuntu utility or ruby gem to convert sqlite to CoreData?

I'm developing rails app for mobile devises.
Now I face a problem - how to convert sqlite3 database into CoreData for iOS devises...
My rails app is runnning on Ubuntu server.
Do you now some ubuntu utility or ruby gem, which help me convert sqlite3 database into CoreData database?
If you're already using SQLite, you're probably better off continuing to use SQLite. In that case there are a couple of convenient Objective-C SQLite wrappers-- FMDB and PLDatabase. With either (or with SQLite's native API, if you know that) you can just use the SQLite file as is, with no conversion.

Rails and SQlite3 - Migrations from SQlite3 to PostgreSQL

I am learning RoR using M Hartls Rails tutorial book. I am very much new to the world of databases. I created the application(simple one, just on 3rd chapter) and did my RSpec and made few static pages. I wanted to migrate from sqllite3 to postgres.
I changed the database.yml to postgres deleting the full sqlite3 specifications. Now I run my app it does not work? It says 'PG:' Error.
I need to first understand how the data is stored in sqlite? I searched the db directory and I could not find the development.rb or any database file (probably because I altered the database.yml file)
In this case, I did not enter any data as such,(it still does not work , gives me error) but generally, where does the data get stored? and since I changed the database.yml file to postgres, what will happen to the existing data?
what does rake db:migrate command do?
It would be great if someone gives a simple analogy or explanation is to how this is stored then finding a solution for this problem becomes much easier.
sqlite stores its data in files in a folder on your filesystem, using its own system of storage.
postgres will do a similar thing, but in a different folder, using a different system.
You will generally never touch these folders. You don't need to know where they are or how the dbms (database management system, eg sqlite or postgres) stores the data. All your interaction with your dbms will be done either via the terminal, or the dmbs's shell client (which you launch in the terminal aka the shell), or via a desktop client, or via your rails app's own connection with the dbms.
When you make a new rails project you need to create the database it will use. If you switch to using a different dbms then you will need to create a new database in that dbms for your app to use. Google how to do this.
If you have data in one dbms and you want to bring it into a different dbms then you will need to export it from the first dbms and import it into the second dbms. Google how to do this.
rake db:migrate will run any migrations which haven't been run in your current database (ie the one in your database.yml). Rails creates a table in your database to store which migrations have been run already: this is how it keeps track. It will fail if you haven't created the database yet.

Copy sqlite database table to Postgres

Is there a way to copy my local sqlite database table into my postgres database on production? I'm very new to Rails so any help is appreciated!
You need a tool to export data from Sqlite and import it to Postgres. You can use https://github.com/ricardochimal/taps.
Here is a tutorial for this: http://railscasts.com/episodes/342-migrating-to-postgresql
You can use taps
notice
I saw you have a question about heroku a few day before. Does this question involved with Heroku? If so, you should not use sqlite locally and postgres remotely.
Take a look at yaml_db for dumping and loading data. Easy to use.

porting and backing up databases

I am using sqlite3 in development and mysql in production on a Rails 3.2 app.
I'd like to be able to backup the mysql, and also to create a sqlite copy of it for use in the development environment. Anyone know how to do this, or the preferred way to back up mysql at least?
I'm partial to this one, and use it to convert to/from MSSQL, sqlite and MySQL quite a lot:
https://github.com/unixmonkey/rails_db_convert_using_adapters
This may not be feasible if you have a large DB, but I am working with a rather small one (about 10MB).
(1) I back up all of my model classes into a .zip file using a rake task, and then
(2) have a button (with admin authentication) that runs another rake task to reload the data.
So I can backup the data in dev/prod mode, push my files to the other environment, and reload the data from backup (it's in .csv files, so it's DB-independent). This worked for me switching between sqlite3 and mysql2 (I am using Rails 4.0.1 if that's relevant).
I can post code if that would be helpful to people, but it's a little messy so I'll save the eyesore unless someone would find it helpful. I've found the .csv into .zip file backup to be a nice workaround for different SQL systems, if you're working on the order of megabytes.

Resources