1

Sequel の Migrations に問題があり、別の目を使うことができます。問題ないように見える移行を実行していますが、テーブルが作成されていません。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)
4

1 に答える 1

4

走る

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

名前付きクラスの代わりに匿名クラスを使用すると、名前空間の衝突のリスクが軽減されます。

于 2010-04-16T15:41:58.673 に答える