heroku push tutorials confusing - mysql

When it comes to pushing databases,the problem starts for the amateurs.
i have my local mysql installed in windows 7,and referring to the heroku tutorial
http://devcenter.heroku.com/articles/taps they say that you can specify heroku db:push
mysql://root:mypass#localhost/mydb in the command line My question is Do i have to include
anything in my source code related with postgres? thanks in advance

When on Heroku, unless you have specified otherwise, you'll be running on Postgres. It you're using an ORM to access your database, then chances are you'll be OK.
If not, then there are literally hundreds of differences between PG SQL and MySQL SQL so something will probably need tweaking depending on how complex your queries are.
Also, depending on the platform you're using you might need to include some dependencies for Postgres such as the pg gem for Ruby.
Something worth noting is that if you're using Rails, you can just do heroku db:push and Heroku does the rest for you ;)

Related

Rails: specifying production environment specific migrations [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Database Specific Migration Code
So I run MySQL locally since it's what I have installed and it makes sense to me.
But Heroku uses Postgre and it doesn't have the same field types.
I.e. I use longblob locally and it becomes bytea in my production environment.
I use tinytext locally which becomes just text
How do I specify different environments inside of my migrations so I don't have to edit my migrations just for pushing to heroku? (I would like to keep them syntactically correct for my local machine)
Any other suggestions?
I understand wanting to run what you're used to locally, as it's easier. Plus, IMO, setting up Postgres locally has always been a pain in the past. However, it really is important to run your development on the same DB as your production server. If you're a Mac user there's a good solution now, brought to you by none other than the Heroku postgres team:
http://postgresapp.com/
Use that and you don't have to worry about this. Otherwise, follow the answer posted by Mu, which will let you do the evil two database thing :)
I'm just guessing here but why don't you create two different migration files, one for development and another for production and use something like this:
rake db:migrate VERSION=00000000000001 RAILS_ENV=production
rake db:migrate VERSION=00000000000002 RAILS_ENV=development

Proper way to set two Rails applications on same server

I have two (same) applications running on dev.example.com and beta.example.com with different databases. Everything is set to run with passenger using Apache as web server.
What I have done was to copy the code from one directory to the other (myapp_dev and myapp_beta) and everything seems working fine, until I have to migrate a table. I get an error that the data I want to migrate is already migrated. Probably trying to migrate on the same database. Maybe I have to re-configure the way to run the applications, but don't know how and what to do. Any hints are appreciated.
Thanks!
you can change the used database in config/database.yml

Delvering a modified database from the local env to the production one

I'm working with MySQL databases.
To simplify the problem, let's say I have two environments : the local one (development) and the remote one (production mode).
In the database, I have some tables that contain configuration data.
How can I automate cleanly the delivery from the development mode to the production mode when I modify the database schema and the configuration tables content ?
For instance, I dot it manually by doing a diff between the local and remote databases. But, I find that method not so clean and I believe there is good practice allowing that.
This might be helpful in cases where you have multiple environments and multiple developers making schema changes very often and using php.. https://github.com/davejkiger/mysql-php-migrations
Introduce parameter "version" for your database. This version should be written somewhere in your code and somewhere in your database. Your code will work with database only if they have equal versions
Create a wrapper around your MySQL connection. This wrapper should check versions and if versions are not compatible, it should start upgrade.
"Upgrade" is a process of sequential applying the list of *.sql files with SQL commands, which will move your database from one state to another. It can be schema changes or data manipulation commands.
When you do something with database, do it only through adding new *.sql file and incrementing version.
As a result, when you deploy your database from development enviroment to production, your database will be upgraded automatically in the same way as it was upgraded during development.
I've seen LiquiBase http://www.liquibase.org/ a lot in Java environments.
In most of my projects I use sqlalchemy(a Python tool to manage db plus an ORM). If you have some experience(little more than beginner) with Python I highly recommend using it.
You can check this tool with a little help of that. This is also very useful for migrating your db to other rdbms(for example mysql to postgres or oracle).

Migrating data from Rails on MySQL DB to Postgres SQL for use with Heroku

I have a RAILS 3.x application developed locally using MySQL which has data which needs migrating. Now I want to deploy to Heroku, which uses Postgresql and also transfer the data.
The issue is in dealing with the columns with NULL data which the import process doesn't like.
I've attempted using a number of different strategies such as
yaml_db gem - fails to import at all
rails-backup-migrate gem - doesn't like the encoded NULL element;
taps - fails on import without much detail
Has anyone tried any other strategies, gems or methods? Should I just start over with a Postgresl local DB instead ?
thanks in advance
grant
Should I just start over with a Postgresl local DB instead ?
Heroku recommends that you use Postgres for local development.
Your production and development environment should be as close to identical as possible. This prevents difficult to diagnose bugs introduced by subtle differences between your environments. Every application on Heroku comes with a PostgreSQL database as the default SQL database. Therefore you should use PostgreSQL for your local development database as well. ( http://devcenter.heroku.com/articles/rails3 )
A quick search turned up this:
http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL#MySQL
Good luck!
I had this problem too and found this gem of a blog post.
It says you can use a gem called Valkyrie to migrate the data from a MySQL database to a PostgreSQL database. You just have to install the gem using gem install valkyrie and then use this command:
valkyrie mysql://datachomp#localhost/seppuku?password=QuickAndPainless postgres://datachomp#127.0.0.1/seppuku

Has anyone successfully connected to MySQL from Ruby?

I'm starting to get a bit desperate in my attempts to get a ruby script to connect to MySQL.
I've given up on DBI, as I just don't seem to be able to get it to work no matter what I do. I figured I might have more luck with just using mysql.rb from ruby-mysql. However, in using that I get the following error:
./mysql.rb:453:in `read': Client does not support authentication protocol requested by server; consider upgrading MySQL client (Mysql::Error)
I gather from googling that error message that this means my version of MySQL is too recent and doesn't support old-style passwords. I'm on a shared server and don't have root access, so I can't make the changes recommended to the MySQL config.
My version, btw, is:
mysql Ver 14.7 Distrib 4.1.22, for pc-linux-gnu (i686) using readline 4.3
Has anyone succeeded in getting ruby to connect to MySQL? I've been trying under Windows, since I have admin access on my Windows machine, but if there's a way to do it without root access on Linux, that'd be even better.
Sounds like you've run in to a MySQL quirk. Some time around version 5.0 they changed the format of connect passwords. It's an easy fix, though: http://dev.mysql.com/doc/refman/5.1/en/old-client.html
(Also, check out the Ruby Sequel gem, it lets you do some real fun stuff with all sorts of databases and without the overhead of ActiveRecord: http://sequel.rubyforge.org/documentation.html )
There is a good summary of how to do this here: http://rubylearning.com/satishtalim/ruby_activerecord_and_mysql.html
I haven't had any issues with connecting to MySQL from Ruby on my test machines.
You mention that you're using a shared hosting provider. If they have that old of a ruby-mysql version that it's not compatible with the new style passwords, perhaps their support staff can make the changes you need made to the user row(s) in MySQL.
What are you looking to do? I think it is possible to use the ActiveRecord component of Rails to establish a connection to MySQL. I'll see if i can find some documentation to back this up, and i'll update this answer.
link to ActiveRecord/MySQL integration
Update: to use ActiveRecord for the purpose are looking for, you will need to create the various model classes that represent the tables you are pulling data from, and specify their relationships. Once that is done, you will be able to do something like:
SomeModel.find(:all, :conditions => ['some_column = ?', some_value]
I've used this approach in the past to provide my Rails apps with access to WordPress data.
It may be that you're using an older version of mysql and need to upgrade it.