Skip to content

Instantly share code, notes, and snippets.

@CodePint
Created May 11, 2018 15:01
Show Gist options
  • Save CodePint/5dea59b3670364f4e675ffca7a7ab4d4 to your computer and use it in GitHub Desktop.
Save CodePint/5dea59b3670364f4e675ffca7a7ab4d4 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
class DeviseCreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
## Database authenticatable
t.string :first_name, null: false
t.string :last_name, null: false
t.string :user_name, null: false
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
## User types
t.boolean :climber, default: true
t.boolean :route_setter, default: false
t.boolean :gym_owner, default: false
## References
t.references :comments
t.references :routes
t.references :climbs
## Timestamps
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
class CreateGyms < ActiveRecord::Migration[5.1]
def change
create_table :gyms do |t|
t.references :routes
t.string :gym_name, null: false
t.text :about
t.string :address
t.string :email
t.timestamps
# setting the list of people who own the gym and are allowed to route set for the gym
# must also have the relevant field set to true in the user model
# these will be the username seperated by commas and then split into an array in ruby when called
t.string :route_setter_list
t.string :gym_owner_list
end
end
end
class CreateMemberships < ActiveRecord::Migration[5.1]
def change
create_table :memberships do |t|
t.boolean :route_setter
t.boolean :gym_owner
t.boolean :climber
t.timestamps
end
end
end
class CreateRoutes < ActiveRecord::Migration[5.1]
def change
create_table :routes do |t|
t.references :user
t.references :gym
t.references :climbs
t.integer :grade
t.datetime :date_set
t.datetime :date_removed
t.timestamps
end
end
end
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :climbs
has_many :routes
has_many :commentsb
has_many :gyms, through: :memberships
end
class Route < ApplicationRecord
belongs_to :gym
belongs_to :user
has_many :climbs
has_many :comments
end
class Membership < ApplicationRecord
belongs_to :gym
belongs_to :users
end
class Gym < ApplicationRecord
has_many :routes
has_many :users, through: :memberships
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment