Mochi
  • Introduction
  • Installation
  • Usage
  • Guides
    • Configuration
    • Authenticable
      • Introduction
      • CLI Installation
      • Manual Installation
      • Views
        • Layouts
          • _session.ecr
        • Session
          • new.ecr
        • User
          • edit.ecr
          • show.ecr
          • new.ecr
      • Models
        • granite_user.cr
        • jennifer_ser.cr
      • Controllers
        • user_controller.cr
        • session_controller.cr
      • Pipes
        • authenticate.cr
    • Confirmable
      • Introduction
      • CLI Installation
      • Manual Installation
      • Controllers
        • registration_controller.cr
      • Mailers
        • confirmation_mailer.ecr
        • confirmation_mailer.text.ecr
    • Trackable
      • Introduction
      • CLI Installation
      • Manual Installation
    • Omniauthable
      • Introduction
      • CLI Installation
      • Manual Installation
    • Recoverable
      • Introduction
      • CLI Installation
      • Manual Installation
      • Controllers
        • registration_controller.cr
      • Mailers
        • confirmation_mailer.ecr
        • confirmation_mailer.text.ecr
    • Mochi Mailer
  • Roadmap
  • Contributing
  • Contributors
Powered by GitBook
On this page

Was this helpful?

  1. Guides
  2. Trackable

Manual Installation

  1. Create a migration and paste in the following:

    Granite:

     -- +micrate Up
     ALTER TABLE users ADD COLUMN sign_in_count VARCHAR NULL;
     ALTER TABLE users ADD COLUMN current_sign_in_ip VARCHAR NULL;
     ALTER TABLE users ADD COLUMN last_sign_in_ip VARCHAR NULL;
     ALTER TABLE users ADD COLUMN current_sign_in_at TIMESTAMP NULL;
     ALTER TABLE users ADD COLUMN last_sign_in_at TIMESTAMP NULL;
    
     -- +micrate Down
     ALTER TABLE users DROP COLUMN sign_in_count VARCHAR NULL;
     ALTER TABLE users DROP COLUMN current_sign_in_ip VARCHAR NULL;
     ALTER TABLE users DROP COLUMN last_sign_in_ip VARCHAR NULL;
     ALTER TABLE users DROP COLUMN current_sign_in_at TIMESTAMP NULL;
     ALTER TABLE users DROP COLUMN last_sign_in_at TIMESTAMP NULL;

    or

    Jennifer:

     class AddTrackableToUsers < Jennifer::Migration::Base
         def up
         change_table(:users) do |t|
             t.add_column(:sign_in_count, :string)
             t.add_column(:current_sign_in_ip, :string)
             t.add_column(:last_sign_in_ip, :string)
             t.add_column(:current_sign_in_at, :timestamp)
             t.add_column(:last_sign_in_at, :timestamp)
         end
         end
    
         def down
         change_table(:users) do |t|
             t.drop_column :sign_in_count
             t.drop_column :current_sign_in_ip
             t.drop_column :last_sign_in_ip
             t.drop_column :current_sign_in_at
             t.drop_column :last_sign_in_at
         end
         end
     end
  2. Migrate:

    Granite:

     amber db migrate

    or

    Jennifer:

     crystal sam.cr -- db:migrate
  3. Mixin the neccessary modules:

    Granite:

    Add :trackable to your mochi_granite macro call

     mochi_granite(:trackable)

    or

    Jennifer:

    Add :trackable to your mochi_jennifer macro call

     mochi_jennifer(:trackable)
  4. Done!

PreviousCLI InstallationNextOmniauthable

Last updated 5 years ago

Was this helpful?