Search code examples
postgresqlelixirecto

Setting a default value of the current time to a datetime column in an Ecto migration


I'm looking for something similar to this SQL.

column_name my_timestamp_column NOT NULL DEFAULT CURRENT_TIMESTAMP

Note that I require that the name of the column be specifiable, so the timestamps macro is not suitable.


Solution

  • You can execute SQL in migration like this

    def change do
      execute("ALTER TABLE some_table ADD some_column timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP")
    end