Search code examples
ruby-on-railspostgresqltaps

Sqlite3 to Postgresql migration via taps error on pull


I'm trying to migrate my sqlite3 db to Postgresql (i'm following the Railscasts #342, but i'm on ubuntu). After a rake db:create:all on my aperitime_development database i started a Sinatra server with Taps (to push mi sqlite3 db), but when i try to do

taps pull postgres://willy:piero@localhost/aperitime_development http://willy:ciao@localhost:5000'

the datas are not copied on postgres db and console doesn't terminate properly:

Receiving schema
Schema:          0% |                                          | ETA:  --:--:--
Schema:         25% |==========                                | ETA:  00:00:07
Schema:         50% |=====================                     | ETA:  00:00:03
Schema:         75% |===============================           | ETA:  00:00:01
Schema:        100% |==========================================| Time: 00:00:04
Receiving data
4 tables, 800 records
/usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in 'async_exec': PG::Error: ERROR:  integer out of range (Sequel::DatabaseError)
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in `block (2 levels) in execute'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/database/logging.rb:28:in `log_yield'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in `block in execute'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:158:in `check_disconnect_errors'
from /usr/lib/ruby/gems/1.9.1/gems/sequel-3.20.0/lib/sequel/adapters/postgres.rb:175:in `execute'

and erros go on.

any ideas?

That's my database.yml

development:
adapter: postgresql
encoding: unicode
database: aperitime_development
pool: 5
username: willy
password: piero

test:
adapter: postgresql
encoding: unicode
database: aperitime_test
pool: 5
username: willy
password: piero

here is my schema.rb

ActiveRecord::Schema.define(:version => 20120630154954) do

create_table "locals", :force => true do |t|
t.string   "nome"
t.string   "indirizzo"
t.text     "descrizione"
t.integer  "Tel", :limit => 8
t.integer  "voto"
t.string   "mappa"
t.datetime "created_at",  :null => false
t.datetime "updated_at",  :null => false
end

create_table "users", :force => true do |t|
t.string   "nome"
t.string   "email"
t.datetime "created_at",                         :null => false
t.datetime "updated_at",                         :null => false
t.string   "password_digest"
t.string   "remember_token"
t.boolean  "admin",           :default => false
end

add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"

end

Solution

  • The Tel column is set as integer, some of your data is overflowing postgresql's integer type Normally I see phone numbers being stored as Strings in the database. since at some point you might need an extension or the like that won't work as an int.

    To change your existing table from integer to character varying in posgresql you create a migration with the following.

    def up 
        execute <<-SQL
            ALTER TABLE locals ALTER COLUMN Tel type character varying(255)
        SQL
    end
    

    This should change the column type to rails default string representation. It should also convert the existing integers over. But be sure to test.