Sha256: a601097284858791e2b56d2fb602a3bafe2e5ef01d133d4d6b3cf5c4dbfa7649
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
class CreateUsers < ActiveRecord::Migration def self.up if !table_exists? :users create_table :users do |t| t.string :provider t.string :uid t.string :email t.string :username t.boolean :verified t.boolean :admin t.string :referred_by t.string :token t.string :access_token t.text :tags t.text :referred t.text :access_tokens t.boolean :subscribed t.string :display t.text :identities t.timestamps end else safe_column :users, :provider, :string safe_column :users, :uid, :string safe_column :users, :email, :string safe_column :users, :username, :string safe_column :users, :verified, :boolean safe_column :users, :admin, :boolean safe_column :users, :referred, :string safe_column :users, :token, :string safe_column :users, :access_token, :string safe_column :users, :tags, :text safe_column :users, :referred, :text safe_column :users, :access_tokens, :text safe_column :users, :display, :string safe_column :users, :subscribed, :boolean safe_column :users, :identities, :text end end def self.down drop_table :users end private def table_exists? table ActiveRecord::Base.connection.table_exists?(table.to_s) end def column_exists?(table, column) begin ActiveRecord::Base.connection.columns(table.to_s).map(&:name).include?(column.to_s) rescue NoMethodError #actual_columns is empty and it doesn't respond to the map method false end end def safe_column table, name, type add_column table.to_sym, name.to_sym, type.to_sym unless column_exists? table, name end end
Version data entries
3 entries across 3 versions & 1 rubygems