Sha256: 7d96676892dec1f5f2d90928aefdd931f57503c21298b4a826d319231151cb12

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

# This migration comes from adherent (originally 20150412145132)
class CreateQueryMember < ActiveRecord::Migration
  def up 
    self.connection.execute %Q(CREATE OR REPLACE VIEW adherent_query_members AS
      SELECT adherent_members.id, organism_id, number, name, forname, birthdate,
       adherent_coords.mail AS mail, adherent_coords.tel AS tel,
      (SELECT to_date FROM adherent_adhesions
         WHERE adherent_adhesions.member_id = adherent_members.id
         ORDER BY to_date DESC LIMIT 1 ) AS m_to_date,
      (SELECT SUM(adherent_reglements.amount) FROM adherent_reglements,
         adherent_adhesions
       WHERE adherent_reglements.adhesion_id = adherent_adhesions.id AND
         adherent_adhesions.member_id = adherent_members.id) AS t_reglements,
      (SELECT SUM(amount) FROM adherent_adhesions
         WHERE adherent_adhesions.member_id = adherent_members.id) AS t_adhesions
      FROM adherent_members
      LEFT JOIN adherent_coords ON adherent_members.id = adherent_coords.member_id; 
    )
  end
  
  def down 
    self.connection.execute "DROP VIEW IF EXISTS adherent_query_members"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
adherent-0.2.7 spec/dummy/db/migrate/20150412145762_create_query_member.adherent.rb
adherent-0.2.6 spec/dummy/db/migrate/20150412145762_create_query_member.adherent.rb
adherent-0.2.5 spec/dummy/db/migrate/20150412145762_create_query_member.adherent.rb
adherent-0.2.4 spec/dummy/db/migrate/20150412145762_create_query_member.adherent.rb