|
| 1 | +class SetupEntropiSocial < ActiveRecord::Migration |
| 2 | + def up |
| 3 | + create_table :users do |t| |
| 4 | + t.string :username |
| 5 | + t.integer :invitation_limit, :default => 0 |
| 6 | + t.database_authenticatable :null => false |
| 7 | + t.invitable |
| 8 | + t.recoverable |
| 9 | + t.rememberable |
| 10 | + t.trackable |
| 11 | + t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both |
| 12 | + t.timestamps |
| 13 | + end |
| 14 | + |
| 15 | + # Setup Indexes for Users table |
| 16 | + add_index :users, :email, :unique => true |
| 17 | + add_index :users, :reset_password_token, :unique => true |
| 18 | + add_index :users, :unlock_token, :unique => true |
| 19 | + add_index :users, :username, :unique => true |
| 20 | + add_index :users, :invitation_token |
| 21 | + |
| 22 | + create_table :profiles do |t| |
| 23 | + t.references :user |
| 24 | + t.string :first_name |
| 25 | + t.string :last_name |
| 26 | + t.date :birth_date |
| 27 | + t.integer :avatar_id |
| 28 | + t.text :about |
| 29 | + t.timestamps |
| 30 | + end |
| 31 | + |
| 32 | + create_table :groups do |t| |
| 33 | + t.string :title |
| 34 | + t.integer :avatar_id |
| 35 | + t.references :profile |
| 36 | + t.references :groupable, :polymorphic => true |
| 37 | + t.timestamps |
| 38 | + end |
| 39 | + |
| 40 | + create_table :friendships do |t| |
| 41 | + t.integer :inviter_id |
| 42 | + t.integer :invited_id |
| 43 | + t.string :status |
| 44 | + t.timestamps |
| 45 | + end |
| 46 | + |
| 47 | + create_table :memberships do |t| |
| 48 | + t.integer :group_id |
| 49 | + t.integer :profile_id |
| 50 | + t.boolean :admin |
| 51 | + t.timestamps |
| 52 | + end |
| 53 | + |
| 54 | + create_table :likes do |t| |
| 55 | + t.integer :user_id |
| 56 | + t.references :likable, :polymorphic => true |
| 57 | + t.timestamps |
| 58 | + end |
| 59 | + |
| 60 | + add_index :likes, :likable_id |
| 61 | + add_index :likes, :likable_type |
| 62 | + |
| 63 | + create_table :photos do |t| |
| 64 | + t.boolean :is_primary |
| 65 | + t.string :asset |
| 66 | + t.references :photoable, :polymorphic => true |
| 67 | + t.references :profile_id |
| 68 | + t.timestamps |
| 69 | + end |
| 70 | + |
| 71 | + add_index :photos, :photoable_id |
| 72 | + add_index :photos, :photoable_type |
| 73 | + |
| 74 | + create_table :comments do |t| |
| 75 | + t.text :comment |
| 76 | + t.references :commentable, :polymorphic => true |
| 77 | + t.references :profile |
| 78 | + t.string :role, :default => "comments" |
| 79 | + t.timestamps |
| 80 | + end |
| 81 | + |
| 82 | + add_index :comments, :commentable_type |
| 83 | + add_index :comments, :commentable_id |
| 84 | + add_index :comments, :profile_id |
| 85 | + |
| 86 | + create_table :accesses do |t| |
| 87 | + t.integer :group_id |
| 88 | + t.references :accessible, :polymorphic => true |
| 89 | + t.timestamps |
| 90 | + end |
| 91 | + |
| 92 | + add_index :accesses, :group_id |
| 93 | + add_index :accesses, :accessible_id |
| 94 | + add_index :accesses, :accessible_type |
| 95 | + |
| 96 | + create_table :albums do |t| |
| 97 | + t.string :name |
| 98 | + t.string :description |
| 99 | + t.references :profile |
| 100 | + t.timestamps |
| 101 | + end |
| 102 | + |
| 103 | + create_table :sessions do |t| |
| 104 | + t.string :session_id, :null => false |
| 105 | + t.text :data |
| 106 | + t.timestamps |
| 107 | + end |
| 108 | + |
| 109 | + add_index :sessions, :session_id |
| 110 | + add_index :sessions, :updated_at |
| 111 | + |
| 112 | + # Create Default User |
| 113 | + profile = Profile.new |
| 114 | + profile.first_name = 'System' |
| 115 | + profile.last_name = 'Administrator' |
| 116 | + profile.birth_date = Time.now |
| 117 | + User.create!(:profile => profile, :username => 'timeline', :email => 'administrator@timeline.com', :password => 'password', :password_confirmation => "password") |
| 118 | + |
| 119 | + end |
| 120 | + |
| 121 | + def down |
| 122 | + |
| 123 | + drop_table :users |
| 124 | + drop_table :profiles |
| 125 | + drop_table :groups |
| 126 | + drop_table :friendships |
| 127 | + drop_table :memberships |
| 128 | + drop_table :comments |
| 129 | + drop_table :likes |
| 130 | + drop_table :photos |
| 131 | + drop_table :accesses |
| 132 | + |
| 133 | + end |
| 134 | +end |
0 commit comments