Sha256: 525a5673fbddb5878dbfacefa8bee58fe4fac649b668a38ba8cfb431bccacd80

Contents?: true

Size: 815 Bytes

Versions: 5

Compression:

Stored size: 815 Bytes

Contents

class CreateShortenedUrlsTable < ActiveRecord::Migration
  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.string :url, :null => false

      # the unique key
      t.string :unique_key, :limit => 10, :null => false

      # how many times the link has been clicked
      t.integer :use_count, :null => false, :default => 0

      t.timestamps
    end

    # we will lookup the links in the db by key 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, [:owner_id, :owner_type]
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shortener-0.3.1 spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb
shortener-0.3.0 spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb
shortener-0.2.0 spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb
shortener-0.1.2 spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb
shortener-0.1.1 spec/dummy/db/migrate/20120213084304_create_shortened_urls_table.rb