Mostrando entradas con la etiqueta postgresql. Mostrar todas las entradas
Mostrando entradas con la etiqueta postgresql. Mostrar todas las entradas

lunes, 23 de noviembre de 2009

Active Record Without Rails and PostgreSQL

a script for connect a database and copy a single table in two tables, copy and save with the .rb extension for execute with Ruby, for example "inicio2tablas.rb" and run in a command line

 cmonterrosa@dibd02:~$ ./inicio2tablas.rb mydatabase myhost  




#!/usr/bin/ruby -w

require 'rubygems'
require 'active_record'

#--------- Carlos Augusto Monterrosa Lopez / cmonterrosa@gmail.com

def usage
STDERR.puts "Uso:
#{File.basename $0} dbname host
"
exit 1
end

usage if ARGV.size != 2
dbname = ARGV[0]
host = ARGV[1]

ActiveRecord::Base.establish_connection(
:adapter => 'postgresql',
:database => dbname,
:username => 'your-user',
:password => 'your-password',
:encoding => 'utf8',
:host => host )


#------ Declaramos las clases para mapear las tablas --------
class Inicio < ActiveRecord::Base
set_table_name :inicio
end

class Palabra < ActiveRecord::Base
set_table_name :palabras
has_many :significados
end

class Significado < ActiveRecord::Base
set_table_name :significados
belongs_to :palabra
end


puts "Cargando palabras..."
@contador=0
@inicio= Inicio.find(:all)
@inicio.each do |inicio|
@palabra = Palabra.create(:palabra => inicio.palabra,
:abreviatura => inicio.abreviatura)
@contador+=1

#------------ Vinculamos los significados -------------
(1..12).each do |num|
next if inicio["significado#{num}"].nil? || inicio["significado#{num}"].empty?
@palabra.significados.create(:significado => inicio["significado#{num}"])
end
end
puts "Finalizo la carga de palabras.."
puts "Total: #{@contador}"

viernes, 16 de octubre de 2009

How to migrate MySQL backup to PostgreSQL

Hi, the first step is generate a dump with all data from your mysql database. for example. I am working in Ubuntu 8.04 Hardy Heron


cmonterrosa@dibd02:~$ mysqldump dbname > file.sql -u root -p


enter your password and mysqldump generate a file with the BD backup. then you have tu run the script to format this file.sql into postgresql valid format.

This script is available in:

http://pgfoundry.org/frs/download.php/1535/mysql2pgsql.perl


cmonterrosa@dibd02:~$ perl mysql2pgsql.perl file.sql file-pgsql.sql



where file-pgsql.sql is the file valid for introduce the schema and data into postgresql.Now we are going to restore the schema and the rows.


cmonterrosa@dibd02:~$ psql -h localhost -d diccionarios -U cmonterrosa -W


where -h option is host, in this case is the localhost, -d is the database and -U is the owner of the database.

Comments with

Carlos Augusto Monterrosa Lopez
cmonterrosa@gmail.com / cmonterrosa@sef-chiapas.gob.mx

lunes, 20 de julio de 2009

Error Please install the postgresql adapter: `gem install activerecord-postgresql-adapter

I'm installing postgresql adapter for Ruby on Rails 1.2.6 and I found this error for create a model, then I installed 2 files, I am working on Ubuntu 8.04 Hardy Heron, I only write:

sudo apt-get install libdbi-ruby1.8 libpgsql-ruby1.8 ruby1.8-dev

I can create a model and database migration.

comments at cmonterrosa at gmail.com