Skip to content

Instantly share code, notes, and snippets.

@abhishek0
Last active December 20, 2015 21:08
Show Gist options
  • Save abhishek0/6195036 to your computer and use it in GitHub Desktop.
Save abhishek0/6195036 to your computer and use it in GitHub Desktop.
class CreateUsers < ActiveRecord::Migration
def change
create_table :users, id: false do |t|
t.primary_key :id, :uuid, :default => 'uuid_generate_v1()'
t.string :first_name
t.string :last_name
t.string :email
t.string :mobile_number
t.string :locality
t.string :city
t.string :address
t.string :blood_group
t.string :emeregency_number
t.string :user_type
t.integer :dob
t.string :password
t.string :access_token
t.uuid :parent_id
t.timestamps
end
end
end
== CreateUsers: migrating ====================================================
-- create_table(:users, {:id=>false})
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `uuid' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0xaae76ff>/home/abhishek/mine/code/infocus/backend-ror/db/migrate/20130809161249_create_users.rb:18:in `change'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:184:in `create_table'
org/jruby/RubyBasicObject.java:1715:in `__send__'
org/jruby/RubyKernel.java:2217:in `send'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:625:in `method_missing'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:597:in `say_with_time'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:597:in `say_with_time'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:617:in `method_missing'
/home/abhishek/mine/code/infocus/backend-ror/db/migrate/20130809161249_create_users.rb:3:in `change'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:571:in `exec_migration'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:555:in `migrate'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:554:in `migrate'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:553:in `migrate'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:709:in `migrate'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:959:in `execute_migration_in_transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:1005:in `ddl_transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/transactions.rb:209:in `transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:1005:in `ddl_transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:958:in `execute_migration_in_transaction'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:920:in `migrate'
org/jruby/RubyArray.java:1617:in `each'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `migrate'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/home/abhishek/.rvm/gems/jruby-1.7.4/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `(root)'
org/jruby/RubyProc.java:255:in `call'
org/jruby/RubyArray.java:1617:in `each'
org/jruby/RubyArray.java:1617:in `each'
org/jruby/RubyKernel.java:1073:in `load'
Tasks: TOP => db:migrate
class User
validates :first_name,:last_name,:email,:mobile, presence: true
validates :locality,:city, presence: true
validates :email uniqueness: true
belongs_to :parent, :inverse_of => :children, class_name: "User"
has_many :children, :inverse_of => :parent, class_name: "User"
before_create :generate_access_token
:first_name, type: String
:last_name, type: String
:email, type: String
:mobile_number, type: String
:locality, type: String
:city, type: String
:address, type: String
:blood_group, type: String
:emergency_number, type: String
:user_type, type: String
:dob, type: Integer
:password, type: String
:access_token type: String
private
def generate_access_token
access_token = SecureRandom.hex
until User.find_by_access_token(access_token) != nil
access_token = SecureRandom.hex
end
self.access_token = access_token
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment