summaryrefslogtreecommitdiffstats
path: root/db/migrate/20150113211532_populate_email_addresses.rb
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrate/20150113211532_populate_email_addresses.rb')
-rw-r--r--db/migrate/20150113211532_populate_email_addresses.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/db/migrate/20150113211532_populate_email_addresses.rb b/db/migrate/20150113211532_populate_email_addresses.rb
new file mode 100644
index 000000000..80a5fb016
--- /dev/null
+++ b/db/migrate/20150113211532_populate_email_addresses.rb
@@ -0,0 +1,14 @@
+class PopulateEmailAddresses < ActiveRecord::Migration
+ def self.up
+ t = EmailAddress.connection.quoted_true
+ n = EmailAddress.connection.quoted_date(Time.now)
+
+ sql = "INSERT INTO #{EmailAddress.table_name} (user_id, address, is_default, notify, created_on, updated_on)" +
+ " SELECT id, mail, #{t}, #{t}, '#{n}', '#{n}' FROM #{User.table_name} WHERE type = 'User' ORDER BY id"
+ EmailAddress.connection.execute(sql)
+ end
+
+ def self.down
+ EmailAddress.delete_all
+ end
+end