0

我正在尝试在 Ruby 中设置 Sequel。我去了http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html并创建了我的第一个迁移。然后我让 Postgres.app 作为我的服务器运行,并做了一个 createdb Qsario。当我尝试使用迁移来创建数据库字段时,问题就来了:

$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 文件是目录中唯一的东西。

4

1 回答 1

1

只是为了记录,这里是固定迁移的样子,并围绕修复/改进进行评论,以防其他人犯我犯的同样错误。mu 太短了,因为我帮我解决了这个问题,所以值得称赞。

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
于 2012-07-14T01:51:12.820 回答