Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normal that my primary key is "MUL"? #25

Open
9mm opened this issue Mar 13, 2013 · 7 comments
Open

Normal that my primary key is "MUL"? #25

9mm opened this issue Mar 13, 2013 · 7 comments

Comments

@9mm
Copy link

9mm commented Mar 13, 2013

I'm looking at my MySQL table after I set :primary_key => true, and it's saying instead of PRI it's "MUL". Is this okay?

@9mm
Copy link
Author

9mm commented Mar 13, 2013

Also, How do I make it a v1 UUID instead of v4?

@pyromaniac
Copy link
Collaborator

Regarding the first question - please, show your sources.
The second - try to redefine https://github.com/jashmenn/activeuuid/blob/master/lib/activeuuid/uuid.rb#L119 at your model.

@9mm
Copy link
Author

9mm commented Mar 13, 2013

Migration:

class CreateSurveys < ActiveRecord::Migration
  def change
    create_table :surveys, :id => false do |t|
      t.references :employee, :null => false
      t.uuid :id, :primary_key => true
      t.datetime :expired_at
      t.timestamps
    end
    add_index :surveys, :id
  end
end       

survey.rb

class Survey < ActiveRecord::Base

  include ActiveUUID::UUID

  belongs_to :employee

  validates :employee, :presence => true  

end

@pyromaniac
Copy link
Collaborator

Looks proper, except add_index :surveys, :id, primary keys in sql are indexed by default.
Still didn't get you. What is "MUL" then? Where did you see this?

@pyromaniac
Copy link
Collaborator

Ah, got it. It is MUL because of add_index :surveys, :id. Just remove this line and it will become PRI

@9mm
Copy link
Author

9mm commented Mar 13, 2013

That fixed it! Thanks! I saw the add_index line right on the documentation, as well as a few guides online. I don't know why everyone has that in their examples if it's not supposed to be on a primary key... hmm.

I'm sure you are busy but would you mind answering a few straggling questions of mine, just for the sake of learning?

  1. Do you think its important I try to override the v4 to be v1? I read on the issues here that v4 isn't as secure. The purpose of me using a UUID is because each hour I need to email surveys out where a user will click a link. I don't want the link in the email to be sequentially numbered as a normal key so people cant find out other ID's. I will also be looking up surveys by UUID so that is important as well.
  2. Is there any particular way I can remove dashes (for the URL). I'd rather not have them when people see the URL. Currently I'm just using the code below. I'm not sure if it's acceptable to use that, and then to convert back, maybe add the dashes back in the correct spot. Or.. if there is something magic about this where my assumption would be foolish.
def token                                
  id.hexdigest                           
end                                      

def self.id_from_token(token)            
  UUIDTools::UUID.parse_hexdigest(token) 
end                                      

Thanks!

@pyromaniac
Copy link
Collaborator

If you ask me - there is no indication to use activeuuid at all. In your place, I would make a usual autoincrement id and additional token field with uniq index to store hex values. And use simply before_save to generate this token.

I do not know about the difference between v1 and v4, but you can use whatever you need with http://www.ruby-doc.org/stdlib-1.9.3/libdoc/securerandom/rdoc/SecureRandom.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants