Sha256: fc28f4276f0ddb05e3dfeb912f8e85cb73099e66e223ca846285550cab7e2632
Contents?: true
Size: 1.13 KB
Versions: 11
Compression:
Stored size: 1.13 KB
Contents
class CreateChoices < ActiveRecord::Migration def self.up create_table :choices, :force => true do |t| # t.column :name, :string t.column :elt_id, :string, :null => false t.column :person_id, :string t.column :created_on, :datetime, :null => false t.column :value, :integer, :default => 1, :null => false end execute 'ALTER TABLE choices ADD CONSTRAINT fk_elt_id FOREIGN KEY ( elt_id ) REFERENCES elts( id ) ' execute 'ALTER TABLE choices ADD CONSTRAINT fk_person_id FOREIGN KEY ( person_id ) REFERENCES people( id ) ' execute 'ALTER TABLE choices ADD CONSTRAINT elt_person_key UNIQUE ( elt_id, person_id ) ' execute 'INSERT INTO choices (elt_id, person_id, created_on, value) SELECT id AS elt_id, person_id, created_on, 1 AS value FROM elts ' puts "#{Choice.count} choices" elts = Elt.find(:all, :conditions => ["body LIKE '%%+1%%' OR body LIKE '%%0%%' OR body LIKE '%%-1%%'"]) puts "#{elts.size} potential choices" elts.each { |e| e.parent.vote(Regexp.last_match(1), e.person) if e.body =~ /^\s*(-1|0|\+1)(\s*|$)/ } puts "#{Choice.count} choices" end def self.down drop_table :choices end end
Version data entries
11 entries across 11 versions & 1 rubygems