Skip to content

Commit

Permalink
Merge pull request #98 from craigmcnamara/fixed-length-index-in-migra…
Browse files Browse the repository at this point in the history
…tions

Add length to the url field and index
  • Loading branch information
jpmcgrath authored Apr 30, 2018
2 parents 00ea1ec + e3c956d commit a925cbc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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

0 comments on commit a925cbc

Please sign in to comment.