-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update migrations and model associations for Rails 7 compatibility
- Loading branch information
Showing
20 changed files
with
210 additions
and
347 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
module Rapidfire | ||
class Attempt < ApplicationRecord | ||
belongs_to :survey | ||
has_many :answers, inverse_of: :attempt, autosave: true | ||
|
||
if Rails::VERSION::MAJOR >= 5 | ||
belongs_to :user, polymorphic: true, optional: true | ||
else | ||
belongs_to :user, polymorphic: true | ||
end | ||
has_many :answers, dependent: :destroy, inverse_of: :attempt | ||
belongs_to :user, polymorphic: true, optional: true | ||
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,37 @@ | ||
if Rails::VERSION::MAJOR >= 5 | ||
version = [Rails::VERSION::MAJOR, Rails::VERSION::MINOR].join('.').to_f | ||
base = ActiveRecord::Migration[version] | ||
else | ||
base = ActiveRecord::Migration | ||
end | ||
|
||
class CreateRapidfireTables < base | ||
class CreateRapidfireTables < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :rapidfire_surveys do |t| | ||
t.string :name | ||
t.string :name | ||
t.text :introduction | ||
t.timestamps | ||
end | ||
|
||
create_table :rapidfire_questions do |t| | ||
t.references :survey | ||
t.string :type | ||
t.string :question_text | ||
t.string :default_text | ||
t.string :placeholder | ||
t.references :survey, foreign_key: { to_table: :rapidfire_surveys } | ||
t.string :type | ||
t.string :question_text | ||
t.string :default_text | ||
t.string :placeholder | ||
t.integer :position | ||
t.text :answer_options | ||
t.text :validation_rules | ||
|
||
t.timestamps | ||
end | ||
add_index :rapidfire_questions, :survey_id if Rails::VERSION::MAJOR < 5 | ||
|
||
create_table :rapidfire_attempts do |t| | ||
t.references :survey | ||
t.references :user, polymorphic: true | ||
t.references :survey, foreign_key: { to_table: :rapidfire_surveys } | ||
t.references :user, polymorphic: true, index: true | ||
|
||
t.timestamps | ||
end | ||
add_index :rapidfire_attempts, :survey_id if Rails::VERSION::MAJOR < 5 | ||
add_index :rapidfire_attempts, [:user_id, :user_type] | ||
|
||
create_table :rapidfire_answers do |t| | ||
t.references :attempt | ||
t.references :question | ||
t.references :attempt, foreign_key: { to_table: :rapidfire_attempts } | ||
t.references :question, foreign_key: { to_table: :rapidfire_questions } | ||
t.text :answer_text | ||
|
||
t.timestamps | ||
end | ||
if Rails::VERSION::MAJOR < 5 | ||
add_index :rapidfire_answers, :attempt_id | ||
add_index :rapidfire_answers, :question_id | ||
end | ||
end | ||
end |
9 changes: 1 addition & 8 deletions
9
db/migrate/20170701191411_add_after_survey_content_to_survey.rb
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
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
2 changes: 1 addition & 1 deletion
2
lib/generators/rapidfire/templates/migrations/add_active_to_survey.rb
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
9 changes: 1 addition & 8 deletions
9
lib/generators/rapidfire/templates/migrations/add_after_survey_content_to_survey.rb
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
9 changes: 1 addition & 8 deletions
9
lib/generators/rapidfire/templates/migrations/rename_answer_groups_and_question_groups.rb
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
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
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
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
Oops, something went wrong.