Class: CreateShortenedUrlsTable
- Inherits:
-
Object
- Object
- CreateShortenedUrlsTable
- Defined in:
- lib/generators/url_shortner/templates/migration.rb
Instance Method Summary collapse
Instance Method Details
#change ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/url_shortner/templates/migration.rb', line 2 def change create_table :shortened_urls do |t| # we can link this to a user for interesting things # t.integer :owner_id # t.string :owner_type, limit: 20 # the real url that we will redirect to t.text :original_url, null: false, length: 2083 t.text :short_url, null: false, length: 2083 # the unique key # t.string :unique_key, limit: 10, null: false # a category to help categorize shortened urls # t.string :category # how many times the link has been clicked # t.integer :use_count, null: false, default: 0 # valid until date for expirable urls # t.datetime :expires_at t. end # 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 :short_url, :url, length: 2083 # add_index :shortened_urls, [:owner_id, :owner_type] # add_index :shortened_urls, :category end |