From e3618bdbecd9b5d86eb6d2c8c256ba3fcdf05189 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 17 Jan 2015 14:14:12 +0000 Subject: Add support for multiple email addresses per user (#4244). git-svn-id: http://svn.redmine.org/redmine/trunk@13886 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- db/migrate/20150113194759_create_email_addresses.rb | 12 ++++++++++++ db/migrate/20150113211532_populate_email_addresses.rb | 14 ++++++++++++++ db/migrate/20150113213922_remove_users_mail.rb | 9 +++++++++ .../20150113213955_add_email_addresses_user_id_index.rb | 9 +++++++++ 4 files changed, 44 insertions(+) create mode 100644 db/migrate/20150113194759_create_email_addresses.rb create mode 100644 db/migrate/20150113211532_populate_email_addresses.rb create mode 100644 db/migrate/20150113213922_remove_users_mail.rb create mode 100644 db/migrate/20150113213955_add_email_addresses_user_id_index.rb (limited to 'db/migrate') diff --git a/db/migrate/20150113194759_create_email_addresses.rb b/db/migrate/20150113194759_create_email_addresses.rb new file mode 100644 index 000000000..a0babce62 --- /dev/null +++ b/db/migrate/20150113194759_create_email_addresses.rb @@ -0,0 +1,12 @@ +class CreateEmailAddresses < ActiveRecord::Migration + def change + create_table :email_addresses do |t| + t.column :user_id, :integer, :null => false + t.column :address, :string, :null => false + t.column :is_default, :boolean, :null => false, :default => false + t.column :notify, :boolean, :null => false, :default => true + t.column :created_on, :timestamp, :null => false + t.column :updated_on, :timestamp, :null => false + end + end +end 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 diff --git a/db/migrate/20150113213922_remove_users_mail.rb b/db/migrate/20150113213922_remove_users_mail.rb new file mode 100644 index 000000000..8a8b48429 --- /dev/null +++ b/db/migrate/20150113213922_remove_users_mail.rb @@ -0,0 +1,9 @@ +class RemoveUsersMail < ActiveRecord::Migration + def self.up + remove_column :users, :mail + end + + def self.down + raise IrreversibleMigration + end +end diff --git a/db/migrate/20150113213955_add_email_addresses_user_id_index.rb b/db/migrate/20150113213955_add_email_addresses_user_id_index.rb new file mode 100644 index 000000000..b7fb90c97 --- /dev/null +++ b/db/migrate/20150113213955_add_email_addresses_user_id_index.rb @@ -0,0 +1,9 @@ +class AddEmailAddressesUserIdIndex < ActiveRecord::Migration + def up + add_index :email_addresses, :user_id + end + + def down + remove_index :email_addresses, :user_id + end +end -- cgit v1.2.3