I just switched my whole app's (dev and test) databases to Postgres and got it working well. I did have a ton of information (users, posts, etc) on my local sqlite database that I would love to transfer over to my new PG local database. Is this even possible? Are there any resources y'all can point me to that can give me an idea of how to accomplish this? Thanks in advance!
The 'taps' gem can do it. Looks like there is an updated one called 'taps-taps.'
See: https://shellycloud.com/blog/2013/10/easy-database-migration-using-taps
Related
I am rather new to rails and I was thinking about how much trouble is it to switch from sqlite to postgres in an app that I´m currently working on. The thing is I have never switched in a middle of the building App process.
My local database has some data, but it is not relevant and may be deleted. I´m more concerned about the tables, columns, models, etc...
My reasons for the switch are:
I want to be able to use the 'groupdate' gem with my 'chartkick' gem in developement.
Later I will deploy to Heroku, I have done that before with adding 'pg' gem to production.
I have Postgres installed on my computer and I also have Postgres.app. I´ve been testing chartkick with groupdate in another project, so Postgres is not the problem.
So the question is basically, how much trouble is to switch from sqlite to PG in a middle of a project and what is the easiest and fastest way to do it?
sorry for the long text, hope someone reads it :)
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.
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.
All of a sudden, I cannot save any models in my PostgreSQL database in Rails. Retrieving data works fine.
m = Model.find(1)
m.save
=> false
When I switched to another database, it is fine. There is no entry in the Rails log.
What could cause this behavior? Is the database corrupt? Is the disk dying? I tried rebooting but that did not help.
How can you check the integrity of the database (I have pgAdmin III installed)? Do I need to do some maintenance? How to figure out what the problem is?
Working in Ubuntu 11.04, Rails 3.0.7 and PostgreSQL 8.3.
Have you added any validations since that object was created? Try this:
> m = Model.find(1)
> m.valid?
> m.errors.full_messages
If something was wrong with your PostgreSQL database you'd probably be seeing exceptions and read errors.
Try a
m.save!
and it should give you more information.
Is the database corrupt? Is the disk dying?
If it is, showing three lines of Ruby code isn't going to help. If you want to know whether your database is working, look at the database. If PgAdmin works, then the db is fine. You might want to turn on query logging in the db then, to see what query (if anything) Rails is sending.
This is probably a stupidly easy question for a Rails person but is causing me no end of confusion. I downloaded several open source Rails projects but am not able to run them. Usually, are you supposed to do a db:migrate before you try to run a Rails project? I thought they were supposed to just run.
I guess it depends on how the database is configured. If it's pointing to a sqlite db, then its probably all ready to go, otherwise if its a full blown RDBMS, then yes the database would need to be migrated assuming of course that the settings in database.yml are configured correctly.