【问题标题】:Sequel Migration not running up?续集迁移没有运行?
【发布时间】:2010-04-13 06:31:38
【问题描述】:

在续集的迁移中遇到了一些麻烦,可以使用另一双眼睛。 我正在运行一个看起来不错但没有创建表的迁移。它肯定是连接的,因为我可以看到 schema_info 表已经创建。 -M 0/1 改变了你所期望的版本,但仍然没有表。

命令:

sequel -m . -M 1 ~/Desktop/dbtest/testdb.yml

001_testdb.rb:

class TestDb < Sequel::Migration
  def up
    create_table( "terminals") do
      primary_key :id
      Integer :location_id
      Integer :merchant_id
      BigDecimal :terminal_id, :size=>[11, 0]
      String :reference, :size=>255
      DateTime :created_at
      DateTime :updated_at
      String :image, :default=>"default.jpg", :size=>255
  end
end
  def down
    drop_table :terminals
  end
end

Postgres 中的输出:

test_db=# \dt
        List of relations
Schema |    Name     | Type  |  Owner   
--------+-------------+-------+----------
public | schema_info | table | postgres
(1 row)

test_db=# select * from schema_info;
version 
---------
   1
(1 row)

【问题讨论】:

  • 您似乎应该使用小写标识符?
  • 您看到的 def up 是使用 Sequels 自己的表转储创建的。所以语法应该没问题。它也同意似乎存在于该主题的仅有的两个教程......谢谢,但我不认为就是这样。我认为这可能与命名有关,但我不知道是什么。也找不到关于此的任何文档。咕噜。

标签: ruby sequel


【解决方案1】:

运行

sequel -m . -E > ~/Desktop/dbtest/testdb.yml

-E 添加了一个记录器,以便您查看实际发生的情况,而 > 将输出重定向到 testdb.yml 日志文件。如果这是您的第一次迁移,您可能希望删除数据库并重新创建它(或至少是 schema_info 表)。显然,您必须位于带有 -m 迁移的目录中。上班。

我还建议迁移类使用以下语法:

Class.new(Sequel::Migration) do
  def up
    create_table(:terminals) do
      primary_key :id
      Integer :location_id
      Integer :merchant_id
      BigDecimal :terminal_id, :size=>[11, 0]
      String :reference, :size=>255
      DateTime :created_at
      DateTime :updated_at
      String :image, :default=>"default.jpg", :size=>255
    end
  end
  def down
    drop_table :terminals
  end
end

使用匿名类而不是命名类可以降低命名空间冲突的风险。

【讨论】:

  • 请注意,现在更好的匿名迁移是通过Sequel.migration do … end 完成的。有关更多信息,请参阅the migrations document
猜你喜欢
  • 2020-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多