Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create UserLevelInfo Table #31429

Merged
merged 7 commits into from Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions dashboard/app/models/user_level_info.rb
@@ -0,0 +1,11 @@
# == Schema Information
#
# Table name: user_level_infos
#
# id :integer not null, primary key
# time_spent :integer default(0)
# user_level_id :integer unsigned
#

class UserLevelInfo < ApplicationRecord
end
@@ -0,0 +1,8 @@
class CreateUserLevelInfos < ActiveRecord::Migration[5.0]
def change
create_table :user_level_infos do |t|
t.integer :time_spent, default: 0
t.bigint :user_level_id, unsigned: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try this instead:

Suggested change
t.bigint :user_level_id, unsigned: true
t.references :user_level, foreign_key: true

To do this, you will need to rollback the migration in its current state, change this code line, and then migrate forward again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was failing yesterday because of the issue that is talked about here: rails/rails#30806 . When I asked in infra channel they said it was okay to move forward without the foreign_key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it. they would know best! sounds good.

end
end
end
7 changes: 6 additions & 1 deletion dashboard/db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20190904030041) do
ActiveRecord::Schema.define(version: 20191023192120) do

create_table "activities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t|
t.integer "user_id"
Expand Down Expand Up @@ -1432,6 +1432,11 @@
t.index ["user_id"], name: "index_user_geos_on_user_id", using: :btree
end

create_table "user_level_infos", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t|
t.integer "time_spent", default: 0
t.bigint "user_level_id", unsigned: true
end

create_table "user_levels", id: :bigint, unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t|
t.integer "user_id", null: false
t.integer "level_id", null: false
Expand Down
13 changes: 13 additions & 0 deletions dashboard/test/factories/user_level_infos.rb
@@ -0,0 +1,13 @@
# == Schema Information
#
# Table name: user_level_infos
#
# id :integer not null, primary key
# time_spent :integer default(0)
# user_level_id :integer unsigned
#

FactoryGirl.define do
factory :user_level_info do
end
end
dmcavoy marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions dashboard/test/models/user_level_info_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class UserLevelInfoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
dmcavoy marked this conversation as resolved.
Show resolved Hide resolved
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we keep these Rails auto generated files around even if we don't have any content in them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♀ I was assuming that as I added things to the table I would probably need to use them for testing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize these were auto generated! Perhaps your first test can just make sure that we can create a user_level_info using the new factory method?