2012-07-08 3 views
0

Ruby에서 Sequel로 설정하려고합니다. 나는 http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html에 가서 첫 번째 마이 그 레이션을 만들었습니다. 그런 다음 Postgres.app를 내 서버로 실행하고 createdb Qsario를 수행했습니다. 같은Migration failed with Error : NoMethodError : 정의되지 않은 메소드 'Migration'

$sequel -E -m . postgres://localhost/Qsario 
I, [2012-07-08T13:53:49.659795 #6258] INFO -- : (0.000374s) SET standard_conforming_strings = ON 
I, [2012-07-08T13:53:49.660113 #6258] INFO -- : (0.000153s) SET client_min_messages = 'WARNING' 
I, [2012-07-08T13:53:49.660359 #6258] INFO -- : (0.000163s) SET DateStyle = 'ISO' 
I, [2012-07-08T13:53:49.664679 #6258] INFO -- : (0.000952s) SELECT NULL FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.665179 #6258] INFO -- : (0.000214s) SELECT * FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.665544 #6258] INFO -- : (0.000166s) SELECT 1 AS "one" FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.666100 #6258] INFO -- : (0.000325s) SELECT COUNT(*) AS "count" FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.666461 #6258] INFO -- : (0.000179s) SELECT "version" FROM "schema_info" LIMIT 1 
Error: NoMethodError: undefined method `Migration' for Sequel:Module/Users/me/Projects/Qsario/db/migrate/001_create_user_and_file_tables.rb:3:in `<top (required)>' 

여기 001_create_user_and_file_tables.rb 보이는 내용은 다음과 같습니다 :

Sequel.Migration do 
    no_transaction 

    change do 
    create_table(:users) do 
     primary_key :id 
     String  :username, :unique=>true 
     String  :email, :unique=>true 
     String  :password_hash 
     String  :password_salt 
     DateTime :joined_at, :null => false 
     FalseClass :banned, default=>false 
     String  :role, default=>"user" 
    end 

    create_table(:files) do 
     primary_key :id 
     foreign_key :user_id, :users 
     String  :filename, :null => false 
     DateTime :uploaded_at, :null => false 
    end 

    create_table(:users_files) do 
     primary_key :id 
     foreign_key :user_id, :users 
     foreign_key :file_id, :files 
    end 
    end 
end 

더 Rakefile이 없음을 참고하거나 이런 건 아직 때문에 나는 데이터베이스 필드를 만들 내 마이그레이션을 사용하려고 할 때 문제가 온다 나는 아직도 일을 시작하려고 노력하고있어. 나는 Rails를 사용하지 않는다. 따라서 .rb 파일이 디렉토리의 유일한 것입니다.

+1

당신이 원하는 ['Sequal.migration'가 아닌'Sequel.Migration'] (http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html). –

+0

Sequal? 그건별로 도움이되지 않을 :) :) Sequel.migration DID는 일단 기본값을 default로 변경하면 작동합니다. 감사! – Qsario

+0

하나 맞춤법 mistaek 또 다른 가치가있다 :) –

답변

1

고정 된 마이그레이션은 다음과 같습니다. 다른 사람들이 내가 한 것과 동일한 실수를 저지른 경우의 수정/개선에 대한 의견이 있습니다. 뮤가 너무 짧으면 해결할 수있는 도움을받을 자격이 있습니다.

Sequel.migration do # Lowercase 'm' in migration 
    # That no_transaction bit was totally unnecessary. 

    change do 
    create_table(:users) do 
     primary_key :id 
     String  :username, :unique=>true 
     String  :email,  :unique=>true 
     String  :password_hash 
     String  :password_salt 
     DateTime :joined_at, :null => false 
     FalseClass :banned,  :default=>false # default needs to be :default 
     String  :role,  :default=>"user" 
    end 

    create_table(:files) do 
     primary_key :id 
     foreign_key :user_id, :users 
     String  :filename, :null => false 
     DateTime :uploaded_at, :null => false 
    end 

    # A nicer way to make the old :users_files table. 
    create_join_table(:user_id => :users, :file_id => :files) 
    end 
end