Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ notes
*~
*.DS_Store

# dotenv env variable definitions
# Ignore dotenv env variable definitions
.env

# Ignore byebug history
.byebug_history
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Copyright 2011-2015 Rice University. Licensed under the Affero General Public
<!-- Copyright 2011-2019 Rice University. Licensed under the Affero General Public
License version 3 or later. See the COPYRIGHT file for details. -->

OpenStax Exercises
Expand All @@ -11,14 +11,12 @@ OpenStax Exercises
OpenStax Exercises is an open homework and test question bank, where questions are written
by the community and access is free. Successor to Quadbase.

Check it out at ~~http://quadbase.org~~.

Requirements
------------

To run Exercises, you must have the following dependencies installed:

* Ruby 2.2.3
* Ruby 2.6.1

License
-------
Expand Down Expand Up @@ -65,18 +63,16 @@ See [OpenStax Swerve](http://github.com/openstax/swerve) for more information.
### Install everything yourself

1. Install a ruby version manager on your machine, such as rbenv or rvm
2. Install ruby 2.2.3
2. Install ruby 2.6.1
3. Run the following shell commands from the OpenStax Exercises folder:

```sh
$ bundle --without production
$ createuser --superuser ox_exercises
$ createdb ox_exercises_dev
$ rake db:migrate
$ rake db:seed
$ rails db:setup
$ rails s
```

If any of the above commands fail, try prepending `bundle exec`, e.g. `bundle exec rake db:migrate`
If any of the above commands fail, try prepending `bundle exec`, e.g. `bundle exec rails db:setup`

You should then be able to point a web browser to http://localhost:3000 and access OpenStax Exercises.
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
default: &default
adapter: postgresql
host: localhost
username: <%= ENV['OXE_DB_USER'] || 'ox_exercises' %>
password: <%= ENV['OXE_DB_PASS'] || 'ox_exercises' %>

Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20140724183745_acts_as_votable_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class ActsAsVotableMigration < ActiveRecord::Migration[4.2]
def self.up
create_table :votes do |t|

t.references :votable, :polymorphic => true
t.references :voter, :polymorphic => true
t.references :votable, polymorphic: true
t.references :voter, polymorphic: true

t.boolean :vote_flag
t.string :vote_scope
Expand Down
26 changes: 13 additions & 13 deletions db/migrate/20140724183919_install_commontator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ def change
t.integer :creator_id
t.string :editor_type
t.integer :editor_id
t.integer :thread_id, :null => false
t.text :body, :null => false
t.integer :thread_id, null: false
t.text :body, null: false
t.datetime :deleted_at

t.integer :cached_votes_up, :default => 0
t.integer :cached_votes_down, :default => 0
t.integer :cached_votes_up, default: 0
t.integer :cached_votes_down, default: 0

t.timestamps null: false
end

add_index :commontator_comments, [:creator_id, :creator_type, :thread_id],
:name => 'index_commontator_comments_on_c_id_and_c_type_and_t_id'
name: 'index_commontator_comments_on_c_id_and_c_type_and_t_id'
add_index :commontator_comments, [:thread_id, :created_at]

add_index :commontator_comments, :cached_votes_up
add_index :commontator_comments, :cached_votes_down

create_table :commontator_subscriptions do |t|
t.string :subscriber_type, :null => false
t.integer :subscriber_id, :null => false
t.integer :thread_id, :null => false
t.string :subscriber_type, null: false
t.integer :subscriber_id, null: false
t.integer :thread_id, null: false

t.timestamps
end

add_index :commontator_subscriptions, [:subscriber_id, :subscriber_type, :thread_id],
:unique => true,
:name => 'index_commontator_subscriptions_on_s_id_and_s_type_and_t_id'
unique: true,
name: 'index_commontator_subscriptions_on_s_id_and_s_type_and_t_id'
add_index :commontator_subscriptions, :thread_id

create_table :commontator_threads do |t|
Expand All @@ -47,7 +47,7 @@ def change
end

add_index :commontator_threads, [:commontable_id, :commontable_type],
:unique => true,
:name => 'index_commontator_threads_on_c_id_and_c_type'
unique: true,
name: 'index_commontator_threads_on_c_id_and_c_type'
end
end
16 changes: 8 additions & 8 deletions db/migrate/20140724183932_install_fine_print.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
class InstallFinePrint < ActiveRecord::Migration[4.2]
def change
create_table :fine_print_contracts do |t|
t.string :name, :null => false
t.string :name, null: false
t.integer :version
t.string :title, :null => false
t.text :content, :null => false
t.string :title, null: false
t.text :content, null: false

t.timestamps null: false
end

add_index :fine_print_contracts, [:name, :version], :unique => true
add_index :fine_print_contracts, [:name, :version], unique: true

create_table :fine_print_signatures do |t|
t.belongs_to :contract, :null => false
t.belongs_to :user, :polymorphic => true, :null => false
t.belongs_to :contract, null: false
t.belongs_to :user, polymorphic: true, null: false

t.timestamps
end

add_index :fine_print_signatures, :contract_id
add_index :fine_print_signatures,
[:user_id, :user_type, :contract_id],
:name => 'index_fine_print_signatures_on_u_id_and_u_type_and_c_id',
:unique => true
name: 'index_fine_print_signatures_on_u_id_and_u_type_and_c_id',
unique: true
end
end
10 changes: 5 additions & 5 deletions db/migrate/20140724184012_create_openstax_accounts_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
class CreateOpenStaxAccountsAccounts < ActiveRecord::Migration[4.2]
def change
create_table :openstax_accounts_accounts do |t|
t.integer :openstax_uid, :null => false
t.string :username, :null => false
t.integer :openstax_uid, null: false
t.string :username, null: false
t.string :access_token
t.string :first_name
t.string :last_name
Expand All @@ -13,9 +13,9 @@ def change
t.timestamps null: false
end

add_index :openstax_accounts_accounts, :openstax_uid, :unique => true
add_index :openstax_accounts_accounts, :username, :unique => true
add_index :openstax_accounts_accounts, :access_token, :unique => true
add_index :openstax_accounts_accounts, :openstax_uid, unique: true
add_index :openstax_accounts_accounts, :username, unique: true
add_index :openstax_accounts_accounts, :access_token, unique: true
add_index :openstax_accounts_accounts, :first_name
add_index :openstax_accounts_accounts, :last_name
add_index :openstax_accounts_accounts, :full_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class CreateOpenStaxAccountsGroups < ActiveRecord::Migration[4.2]
def change
create_table :openstax_accounts_groups do |t|
t.integer :openstax_uid, :null => false
t.integer :openstax_uid, null: false
t.boolean :is_public, null: false, default: false
t.string :name
t.text :cached_subtree_group_ids
Expand All @@ -11,7 +11,7 @@ def change
t.timestamps null: false
end

add_index :openstax_accounts_groups, :openstax_uid, :unique => true
add_index :openstax_accounts_groups, :openstax_uid, unique: true
add_index :openstax_accounts_groups, :is_public
end
end
8 changes: 0 additions & 8 deletions db/migrate/20160610191504_remove_uuid_from_cnxfeature_tags.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ class ChangePublicationsNumberToPublicationGroupId < ActiveRecord::Migration[4.2
def up
add_column :publications, :publication_group_id, :integer

number_publishable_type_pairs = Publication.unscoped.uniq.pluck(:number, :publishable_type)
number_publishable_type_pairs.each do |number, publishable_type|
publication_group = PublicationGroup.create! number: number,
publishable_type: publishable_type

Publication.unscoped.where(number: number, publishable_type: publishable_type)
.update_all(publication_group_id: publication_group.id)
end

change_column_null :publications, :publication_group_id, false
add_index :publications, :publication_group_id
remove_column :publications, :number
Expand Down
4 changes: 0 additions & 4 deletions db/migrate/20161006223624_add_uuid_to_publications.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class AddUuidToPublications < ActiveRecord::Migration[4.2]
def change
ActiveRecord::Base.connection.execute 'CREATE EXTENSION IF NOT EXISTS "pgcrypto";'

add_column :publications, :uuid, :uuid

Publication.unscoped.update_all('uuid = gen_random_uuid()')

change_column_null :publications, :uuid, false
add_index :publications, :uuid, unique: true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,5 @@
class MoveListExercisesAndListVocabTermsToListPublicationGroups < ActiveRecord::Migration[4.2]
def up
exercise_id_list_id_pairs = \
ActiveRecord::Base.connection.execute('SELECT list_id, exercise_id FROM list_exercises;')

vocab_term_id_list_id_pairs = \
ActiveRecord::Base.connection.execute('SELECT list_id, vocab_term_id FROM list_vocab_terms;')

all_list_ids = exercise_id_list_id_pairs.map { |hash| hash['list_id'] } +
vocab_term_id_list_id_pairs.map { |hash| hash['list_id'] }

list_by_list_id = List.where(id: all_list_ids).index_by(&:id)

all_exercise_ids = exercise_id_list_id_pairs.map { |hash| hash['exercise_id'] }

publication_group_by_exercise_id = {}
PublicationGroup.joins(:publications)
.where(publishable_type: 'Exercise',
publications: { publishable_id: all_exercise_ids })
.select([:id, Publication.arel_table[:publishable_id]])
.each do |pg|
publication_group_by_exercise_id[pg.publishable_id] = pg
end

exercise_id_list_id_pairs.each do |exercise_id, list_id|
list = list_by_list_id[list_id]
pg = publication_group_by_exercise_id[exercise_id]
# Using #create instead of #create! so we don't error out on duplicates
ListPublicationGroup.create(list: list, publication_group: pg)
end

all_vocab_term_ids = vocab_term_id_list_id_pairs.map { |hash| hash['vocab_term_id'] }

publication_group_by_vocab_term_id = {}
PublicationGroup.joins(:publications)
.where(publishable_type: 'VocabTerm',
publications: { publishable_id: all_vocab_term_ids })
.select([:id, Publication.arel_table[:publishable_id]])
.each do |pg|
publication_group_by_vocab_term_id[pg.publishable_id] = pg
end

vocab_term_id_list_id_pairs.each do |vocab_term_id, list_id|
list = list_by_list_id[list_id]
pg = publication_group_by_exercise_id[vocab_term_id]
# Using #create instead of #create! so we don't error out on duplicates
ListPublicationGroup.create(list: list, publication_group: pg)
end

drop_table :list_exercises
drop_table :list_vocab_terms
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@ class RenameDistractorTermNumberToDistractorPublicationGroupId < ActiveRecord::M
def up
add_column :vocab_distractors, :distractor_publication_group_id, :integer

all_distractor_term_numbers = VocabDistractor.pluck(:distractor_term_number)
vocab_term_publication_group_by_number = PublicationGroup
.where(publishable_type: 'VocabTerm', number: all_distractor_term_numbers)
.index_by(&:number)

VocabDistractor.find_each do |vd|
pg = vocab_term_publication_group_by_number[vd.distractor_term_number]
vd.update_attribute :distractor_publication_group, pg
end

change_column_null :vocab_distractors, :distractor_publication_group_id, false
add_index :vocab_distractors, :distractor_publication_group_id
add_index :vocab_distractors, [:vocab_term_id, :distractor_publication_group_id],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# This migration comes from openstax_accounts (originally 10)
class AssignMissingUuidsForLocalAccounts < ActiveRecord::Migration[4.2]
def change
enable_extension 'pgcrypto'

OpenStax::Accounts::Account.where(uuid: nil).update_all('"uuid" = gen_random_uuid()')
enable_extension :pgcrypto

change_column :openstax_accounts_accounts, :uuid, :uuid, using: 'uuid::uuid',
default: 'gen_random_uuid()',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,6 @@ def change
add_column :publication_groups, :latest_version, :integer
add_column :publication_groups, :latest_published_version, :integer

reversible do |dir|
dir.up do
PublicationGroup.update_all(
<<-UPDATE_SQL.strip_heredoc
"latest_version" = (
SELECT MAX("publications"."version")
FROM "publications"
WHERE "publications"."publication_group_id" = "publication_groups"."id"
),
"latest_published_version" = (
SELECT MAX("publications"."version")
FROM "publications"
WHERE "publications"."publication_group_id" = "publication_groups"."id"
AND "publications"."published_at" IS NOT NULL
)
UPDATE_SQL
)
end
end

change_column_null :publication_groups, :latest_version, false

add_index :publication_groups, [ :id, :latest_version ]
Expand Down
Loading