Search code examples
rubypostgresqlsequelpadrino

Sequel Migration: uninitialized constant Jsonb (NameError)


I'm using Sequel with Padrino and the following migration raised the uninitialized constant Jsonb (NameError) error:

Sequel.migration do
  up do
    alter_table :same_table do
      add_column :not_working, Jsonb
    end
  end
end

The create_table migration for the sale table used Jsonb without issue:

Sequel.migration do
  up do
    create_table :same_table do
      Jsonb :worked
    end
  end
end

Solution

  • As by Sequel source code, the column type should not be capitalized. In general, DSL is about defining class methods, not constants.

    Sequel.migration do
      up do
        alter_table :same_table do
        #                          ⇓⇓ NOTE SYMBOL     
          add_column :not_working, :jsonb
        end
      end
    end
    
    Sequel.migration do
      up do
        create_table :same_table do
        # ⇓ NOTE DOWNCASE
          jsonb :worked
        end
      end
    end