bitwalker / timex_ecto

An adapter for using Timex DateTimes with Ecto
MIT License
162 stars 68 forks source link

Migration instructions #67

Closed pmyjavec closed 7 years ago

pmyjavec commented 7 years ago

I'm curious what a migration should look to set up my database (psql) for use with Timex.Ecto.DateTimeWithTimezone, there has been some commentary on this issue (https://github.com/bitwalker/timex/issues/133) about it and I've used something similar.

Is there a better way to do this?

pmyjavec commented 7 years ago

I should mention I'm using something like this, which I'm personally very happy with:

defmodule ShadyCorner.Repo.Migrations.CatTz do  
  use Ecto.Migration                           

  def change do                                
    execute """                                
    CREATE TYPE datetimetz AS (                
    dt timestamptz,                            
    tz varchar                                 
    );                                         
    """                                        

    alter table(:catdog) do                    
      add :birth_tz, :datetimetz                
    end                                        
  end                                          
end
bitwalker commented 7 years ago

@pmyjavec That's exactly how I would do it :)