/
migration.rb
57 lines (54 loc) · 2.8 KB
/
migration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Migration responsible for creating a table with notifications
class <%= @migration_name %> < ActiveRecord::Migration<%= "[#{Rails.version.to_f}]" %>
# Create tables
def change
<% if @migration_tables.include?('notifications') %>create_table :notifications do |t|
t.belongs_to :target, polymorphic: true, index: true, null: false
t.belongs_to :notifiable, polymorphic: true, index: true, null: false
t.string :key, null: false
t.belongs_to :group, polymorphic: true, index: true
t.integer :group_owner_id, index: true
t.belongs_to :notifier, polymorphic: true, index: true
t.text :parameters
t.datetime :opened_at
t.timestamps null: false
end<% else %># create_table :notifications do |t|
# t.belongs_to :target, polymorphic: true, index: true, null: false
# t.belongs_to :notifiable, polymorphic: true, index: true, null: false
# t.string :key, null: false
# t.belongs_to :group, polymorphic: true, index: true
# t.integer :group_owner_id, index: true
# t.belongs_to :notifier, polymorphic: true, index: true
# t.text :parameters
# t.datetime :opened_at
#
# t.timestamps null: false
# end<% end %>
<% if @migration_tables.include?('subscriptions') %>create_table :subscriptions do |t|
t.belongs_to :target, polymorphic: true, index: true, null: false
t.string :key, index: true, null: false
t.boolean :subscribing, null: false, default: true
t.boolean :subscribing_to_email, null: false, default: true
t.datetime :subscribed_at
t.datetime :unsubscribed_at
t.datetime :subscribed_to_email_at
t.datetime :unsubscribed_to_email_at
t.text :optional_targets
t.timestamps null: false
end
add_index :subscriptions, [:target_type, :target_id, :key], unique: true<% else %># create_table :subscriptions do |t|
# t.belongs_to :target, polymorphic: true, index: true, null: false
# t.string :key, index: true, null: false
# t.boolean :subscribing, null: false, default: true
# t.boolean :subscribing_to_email, null: false, default: true
# t.datetime :subscribed_at
# t.datetime :unsubscribed_at
# t.datetime :subscribed_to_email_at
# t.datetime :unsubscribed_to_email_at
# t.text :optional_targets
#
# t.timestamps null: false
# end
# add_index :subscriptions, [:target_type, :target_id, :key], unique: true<% end %>
end
end