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

Add length to the url field and index #98

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ After you install Shortener run the generator:

This generator will create a migration to create the shortened_urls table where your shortened URLs will be stored.

*Note:* The default length of the url field in the generated migration is 2083. This is because MySQL requires fixed length indicies and browsers have a defacto limit on URL length. This may not be right for you or your database. The discussion can be seen here https://github.com/jpmcgrath/shortener/pull/98

Then add to your routes:

get '/:id' => "shortener/shortened_urls#show"
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/shortener/templates/migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def change
t.string :owner_type, limit: 20

# the real url that we will redirect to
t.text :url, null: false
t.text :url, null: false, length: 2083

# the unique key
t.string :unique_key, limit: 10, null: false
Expand All @@ -26,7 +26,7 @@ def change
# we will lookup the links in the db by key, urls and owners.
# also make sure the unique keys are actually unique
add_index :shortened_urls, :unique_key, unique: true
add_index :shortened_urls, :url
add_index :shortened_urls, :url, length: 2083
add_index :shortened_urls, [:owner_id, :owner_type]
add_index :shortened_urls, :category
end
Expand Down