Add Array of Types in a Column using Postgres and Rails
Recently I found a nice feature when defining a column on migrations, is to use array option in the creation of a column: class MyMigration < ActiveRecord::Migration[5.2] def change # Defines a column that stores an array of a type. add_column :transactions, :categories, :string, array: true, default: [] end end With this on categories you can storage an array of values, it’s useful instead of use jsonb because as json you may also need to create the key to store values (hash)....