Created
May 11, 2018 14:31
-
-
Save CodePint/057a1521cb740bb08511e8adbebc55c6 to your computer and use it in GitHub Desktop.
gist_send_route01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateComments < ActiveRecord::Migration[5.1] | |
def change | |
create_table :comments do |t| | |
t.references :climbs | |
t.references :users | |
t.text :text | |
t.timestamps | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Membership < ApplicationRecord | |
belongs_to :gym | |
belongs_to :users | |
end | |
class Gym < ApplicationRecord | |
has_many :routes | |
has_many :users, through: :memberships | |
end | |
class Route < ApplicationRecord | |
belongs_to :gym | |
belongs_to :user | |
has_many :climbs | |
has_many :comments | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateRoutes < ActiveRecord::Migration[5.1] | |
def change | |
create_table :routes do |t| | |
t.references :user | |
t.references :gym | |
t.references :climbs | |
t.string :set_by | |
t.integer :grade | |
t.datetime :date_set | |
t.datetime :date_removed | |
t.timestamps | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment