class InitSchema < ActiveRecord::Migration[5.2]
  def up
    # These are extensions that must be enabled in order to support this database
    enable_extension 'plpgsql'
    create_table 'agencies', force: :cascade do |t|
      t.string   'name'
      t.string   'street_address'
      t.string   'city'
      t.integer  'state_id'
      t.string   'zipcode'
      t.text     'description'
      t.string   'telephone'
      t.string   'email'
      t.string   'website'
      t.string   'lead_officer'
      t.datetime 'created_at',     null: false
      t.datetime 'updated_at',     null: false
      t.string   'slug'
      t.float    'longitude'
      t.float    'latitude'
      t.string   'jurisdiction'
    end
    create_table 'ahoy_events', id: :uuid, default: nil, force: :cascade do |t|
      t.uuid     'visit_id'
      t.integer  'user_id'
      t.string   'name'
      t.text     'properties'
      t.datetime 'time'
    end
    add_index 'ahoy_events', ['time'], name: 'index_ahoy_events_on_time', using: :btree
    add_index 'ahoy_events', ['user_id'], name: 'index_ahoy_events_on_user_id', using: :btree
    add_index 'ahoy_events', ['visit_id'], name: 'index_ahoy_events_on_visit_id', using: :btree
    create_table 'article_agencies', force: :cascade do |t|
      t.integer  'article_id'
      t.integer  'agency_id'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    create_table 'article_officers', force: :cascade do |t|
      t.integer  'article_id'
      t.integer  'officer_id'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    create_table 'articles', force: :cascade do |t|
      t.string   'title'
      t.datetime 'created_at',                   null: false
      t.datetime 'updated_at',                   null: false
      t.integer  'user_id'
      t.integer  'category_id'
      t.date     'date'
      t.integer  'state_id'
      t.string   'city'
      t.string   'address'
      t.string   'zipcode'
      t.float    'longitude'
      t.float    'latitude'
      t.string   'avatar'
      t.string   'slug'
      t.string   'video_url'
      t.string   'state'
      t.integer  'age'
      t.text     'overview'
      t.text     'community_action'
      t.text     'litigation'
      t.string   'country'
      t.boolean  'remove_avatar'
      t.text     'summary'
      t.integer  'follows_count',    default: 0, null: false
    end

    unless index_exists? :articles, :slug, name: 'index_articles_on_slug'
      add_index 'articles', ['slug'], name: 'index_articles_on_slug', unique: true, using: :btree
    end

    add_index 'articles', ['user_id'], name: 'index_articles_on_user_id', using: :btree
    create_table 'categories', force: :cascade do |t|
      t.string   'name'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    create_table 'comments', force: :cascade do |t|
      t.text     'content'
      t.integer  'commentable_id'
      t.string   'commentable_type'
      t.datetime 'created_at',       null: false
      t.datetime 'updated_at',       null: false
      t.integer  'user_id'
    end
    add_index 'comments', ['commentable_id', 'commentable_type'], name: 'index_comments_on_commentable_id_and_commentable_type', using: :btree
    create_table 'ethnicities', force: :cascade do |t|
      t.string   'title'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    create_table 'event_statuses', force: :cascade do |t|
      t.string   'name'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    create_table 'follows', force: :cascade do |t|
      t.integer  'followable_id',                   null: false
      t.string   'followable_type',                 null: false
      t.integer  'follower_id',                     null: false
      t.string   'follower_type',                   null: false
      t.boolean  'blocked',         default: false, null: false
      t.datetime 'created_at'
      t.datetime 'updated_at'
    end
    add_index 'follows', ['followable_id', 'followable_type'], name: 'fk_followables', using: :btree
    add_index 'follows', ['follower_id', 'follower_type'], name: 'fk_follows', using: :btree
    create_table 'friendly_id_slugs', force: :cascade do |t|
      t.string   'slug',                      null: false
      t.integer  'sluggable_id',              null: false
      t.string   'sluggable_type', limit: 50
      t.string   'scope'
      t.datetime 'created_at'
    end
    add_index 'friendly_id_slugs', ['slug', 'sluggable_type', 'scope'], name: 'index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope', unique: true, using: :btree
    add_index 'friendly_id_slugs', ['slug', 'sluggable_type'], name: 'index_friendly_id_slugs_on_slug_and_sluggable_type', using: :btree
    add_index 'friendly_id_slugs', ['sluggable_id'], name: 'index_friendly_id_slugs_on_sluggable_id', using: :btree
    add_index 'friendly_id_slugs', ['sluggable_type'], name: 'index_friendly_id_slugs_on_sluggable_type', using: :btree
    create_table 'genders', force: :cascade do |t|
      t.string   'sex'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    create_table 'links', force: :cascade do |t|
      t.string   'url'
      t.integer  'article_id'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
    end
    add_index 'links', ['article_id'], name: 'index_links_on_article_id', using: :btree
    create_table 'mailboxer_conversation_opt_outs', force: :cascade do |t|
      t.integer 'unsubscriber_id'
      t.string  'unsubscriber_type'
      t.integer 'conversation_id'
    end
    add_index 'mailboxer_conversation_opt_outs', ['conversation_id'], name: 'index_mailboxer_conversation_opt_outs_on_conversation_id', using: :btree
    add_index 'mailboxer_conversation_opt_outs', ['unsubscriber_id', 'unsubscriber_type'], name: 'index_mailboxer_conversation_opt_outs_on_unsubscriber_id_type', using: :btree
    create_table 'mailboxer_conversations', force: :cascade do |t|
      t.string   'subject',    default: ''
      t.datetime 'created_at',              null: false
      t.datetime 'updated_at',              null: false
    end
    create_table 'mailboxer_notifications', force: :cascade do |t|
      t.string   'type'
      t.text     'body'
      t.string   'subject',              default: ''
      t.integer  'sender_id'
      t.string   'sender_type'
      t.integer  'conversation_id'
      t.boolean  'draft',                default: false
      t.string   'notification_code'
      t.integer  'notified_object_id'
      t.string   'notified_object_type'
      t.string   'attachment'
      t.datetime 'updated_at',                           null: false
      t.datetime 'created_at',                           null: false
      t.boolean  'global',               default: false
      t.datetime 'expires'
    end
    add_index 'mailboxer_notifications', ['conversation_id'], name: 'index_mailboxer_notifications_on_conversation_id', using: :btree
    add_index 'mailboxer_notifications', ['notified_object_id', 'notified_object_type'], name: 'index_mailboxer_notifications_on_notified_object_id_and_type', using: :btree
    add_index 'mailboxer_notifications', ['sender_id', 'sender_type'], name: 'index_mailboxer_notifications_on_sender_id_and_sender_type', using: :btree
    add_index 'mailboxer_notifications', ['type'], name: 'index_mailboxer_notifications_on_type', using: :btree
    create_table 'mailboxer_receipts', force: :cascade do |t|
      t.integer  'receiver_id'
      t.string   'receiver_type'
      t.integer  'notification_id',                            null: false
      t.boolean  'is_read',                    default: false
      t.boolean  'trashed',                    default: false
      t.boolean  'deleted',                    default: false
      t.string   'mailbox_type',    limit: 25
      t.datetime 'created_at',                                 null: false
      t.datetime 'updated_at',                                 null: false
    end
    add_index 'mailboxer_receipts', ['notification_id'], name: 'index_mailboxer_receipts_on_notification_id', using: :btree
    add_index 'mailboxer_receipts', ['receiver_id', 'receiver_type'], name: 'index_mailboxer_receipts_on_receiver_id_and_receiver_type', using: :btree
    create_table 'organizations', force: :cascade do |t|
      t.string   'name'
      t.text     'description'
      t.string   'website'
      t.string   'telephone'
      t.string   'avatar'
      t.datetime 'created_at',  null: false
      t.datetime 'updated_at',  null: false
    end
    create_table 'states', force: :cascade do |t|
      t.string   'name'
      t.string   'iso'
      t.datetime 'created_at', null: false
      t.datetime 'updated_at', null: false
      t.string   'ansi_code'
    end
    create_table 'subjects', force: :cascade do |t|
      t.string   'name'
      t.integer  'age'
      t.integer  'gender_id'
      t.integer  'ethnicity_id'
      t.boolean  'unarmed'
      t.boolean  'mentally_ill'
      t.boolean  'veteran'
      t.datetime 'created_at',   null: false
      t.datetime 'updated_at',   null: false
      t.integer  'article_id'
      t.boolean  'homeless'
    end
    create_table 'users', force: :cascade do |t|
      t.string   'email',                  default: '',    null: false
      t.string   'encrypted_password',     default: '',    null: false
      t.string   'reset_password_token'
      t.datetime 'reset_password_sent_at'
      t.datetime 'remember_created_at'
      t.integer  'sign_in_count',          default: 0,     null: false
      t.datetime 'current_sign_in_at'
      t.datetime 'last_sign_in_at'
      t.inet     'current_sign_in_ip'
      t.inet     'last_sign_in_ip'
      t.datetime 'created_at'
      t.datetime 'updated_at'
      t.boolean  'admin',                  default: false
      t.float    'latitude'
      t.float    'longitude'
      t.string   'name'
      t.text     'description'
      t.integer  'state_id'
      t.string   'state'
      t.string   'city'
      t.string   'facebook_url'
      t.string   'twitter_url'
      t.string   'linkedin'
      t.string   'slug'
      t.boolean  'subscribed'
      t.boolean  'analyst',                default: false
    end
    add_index 'users', ['email'], name: 'index_users_on_email', unique: true, using: :btree
    add_index 'users', ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, using: :btree
    add_index 'users', ['slug'], name: 'index_users_on_slug', unique: true, using: :btree
    create_table 'version_associations', force: :cascade do |t|
      t.integer 'version_id'
      t.string  'foreign_key_name', null: false
      t.integer 'foreign_key_id'
    end
    add_index 'version_associations', ['foreign_key_name', 'foreign_key_id'], name: 'index_version_associations_on_foreign_key', using: :btree
    add_index 'version_associations', ['version_id'], name: 'index_version_associations_on_version_id', using: :btree
    create_table 'versions', force: :cascade do |t|
      t.string   'item_type',      null: false
      t.integer  'item_id',        null: false
      t.string   'event',          null: false
      t.string   'whodunnit'
      t.text     'object'
      t.datetime 'created_at'
      t.text     'object_changes'
      t.string   'ip'
      t.integer  'transaction_id'
      t.text     'comment'
      t.integer  'author_id'
    end
    add_index 'versions', ['item_type', 'item_id'], name: 'index_versions_on_item_type_and_item_id', using: :btree
    add_index 'versions', ['transaction_id'], name: 'index_versions_on_transaction_id', using: :btree
    create_table 'visits', id: :uuid, default: nil, force: :cascade do |t|
      t.uuid     'visitor_id'
      t.string   'ip'
      t.text     'user_agent'
      t.text     'referrer'
      t.text     'landing_page'
      t.integer  'user_id'
      t.string   'referring_domain'
      t.string   'search_keyword'
      t.string   'browser'
      t.string   'os'
      t.string   'device_type'
      t.integer  'screen_height'
      t.integer  'screen_width'
      t.string   'country'
      t.string   'region'
      t.string   'city'
      t.string   'utm_source'
      t.string   'utm_medium'
      t.string   'utm_term'
      t.string   'utm_content'
      t.string   'utm_campaign'
      t.datetime 'started_at'
    end
    add_index 'visits', ['user_id'], name: 'index_visits_on_user_id', using: :btree
    add_foreign_key 'links', 'articles'
    add_foreign_key 'mailboxer_conversation_opt_outs', 'mailboxer_conversations', column: 'conversation_id', name: 'mb_opt_outs_on_conversations_id'
    add_foreign_key 'mailboxer_notifications', 'mailboxer_conversations', column: 'conversation_id', name: 'notifications_on_conversation_id'
    add_foreign_key 'mailboxer_receipts', 'mailboxer_notifications', column: 'notification_id', name: 'receipts_on_notification_id'
  end

  def down
    raise ActiveRecord::IrreversibleMigration, 'The initial migration is not revertable'
  end
end
