class CreatePlans < ActiveRecord::Migration[5.0]
  def change
    enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
    create_table :plans, id: :uuid, default: 'gen_random_uuid()' do |t|
      t.integer :trainer_id
      t.references :subscription,   foreign_key: true, type: :uuid
      t.references :user,           foreign_key: true
      t.integer :programa_id,       default: 0

      # inbody & 
      t.string :kg,                 default: "0"
      t.string :tmb,                default: "0"
      t.string :corporal_fat,       default: "0"
      t.string :macros_protein,     default: "0"
      t.string :macros_carbs,       default: "0"
      t.string :macros_fats,        default: "0"

      # photos
      t.string :back,               default: ""
      t.string :side,               default: ""
      t.string :front,              default: ""

      # comments / diary
      t.string :adjust,             default: "" # Mensaje de ajuste por entrenador
      t.string :trace_comments,     default: "" # Mensaje de usuario a entrenador

      # Descipción de rutina, instrucciones y suplementos unifican campos de meals & routines
      t.text :meals_record
      t.text :cardio
      t.text :supplements

      # Inicio de plan, término
      t.date :init
      t.date :finish

      # Comentarios de usuario al terminar el plan
      t.text :recommendations
      t.text :sessions_notes
      t.text :comments

      # usuario que registrará cargas
      t.boolean :charge,  default: false

      t.timestamps
    end
    add_index :plans, :trainer_id

    # MEALS
    # hour y title ya no es relevante
    remove_column :meals, :hour
    remove_column :meals, :title
    # add_column :meals, :number, :integer, null: false, default: 0
    add_reference :meals, :plan, foreign_key: true, type: :uuid
    # ROUTINES
    remove_column :routines, :viewed
    add_column :routines, :safe_url, :string,     null: false, default: ""
    # add_column :routines, :days_completed, :text
    add_column :routines, :history, :text
    add_column :routines, :days, :string, default: ""
    add_reference :routines, :plan, foreign_key: true, type: :uuid

  end

end