Skip to content

Commit

Permalink
Merge branch 'main' into rails7
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Nov 19, 2023
2 parents d037121 + 0f7ec12 commit d87ac8a
Show file tree
Hide file tree
Showing 21 changed files with 1,475 additions and 816 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ group :development, :test do
gem 'rspec-rails'
gem 'vcr'
gem 'webmock'
gem 'factory_bot_rails'
gem 'factory_bot_rails', '~> 6.2.0'
gem 'rails-controller-testing'
gem 'simplecov'
gem 'parallel_tests'
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ GEM
sxp (~> 1.3)
unicode-types (~> 1.8)
erubi (1.12.0)
factory_bot (6.4.0)
factory_bot (6.2.1)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.0)
factory_bot (~> 6.4)
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
railties (>= 5.0.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
Expand Down Expand Up @@ -501,7 +501,7 @@ DEPENDENCIES
date_validator
devise
dotenv-rails
factory_bot_rails
factory_bot_rails (~> 6.2.0)
faraday_middleware
friendly_id
geocoder
Expand Down
2 changes: 1 addition & 1 deletion app/models/jpno_record.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class JpnoRecord < ApplicationRecord
belongs_to :manifestation
validates :body, presence: true
validates :body, presence: true, uniqueness: true
strip_attributes
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/ndla_record.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class NdlaRecord < ApplicationRecord
belongs_to :agent
validates :body, presence: true
validates :body, presence: true, uniqueness: true
end

# == Schema Information
Expand Down
1 change: 0 additions & 1 deletion app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Profile < ApplicationRecord
validates :user, uniqueness: true, associated: true, allow_blank: true
validates :locale, presence: true
validates :user_number, uniqueness: true, format: { with: /\A[0-9A-Za-z_]+\z/ }, allow_blank: true
validates :user_id, uniqueness: true, allow_blank: true
validates :birth_date, format: { with: /\A\d{4}-\d{1,2}-\d{1,2}\z/ }, allow_blank: true

strip_attributes only: :user_number
Expand Down
6 changes: 4 additions & 2 deletions app/views/manifestations/index.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ wb.add_worksheet do |sheet|
sheet.add_row (Manifestation.csv_header(role: current_user_role_name) + Item.csv_header(role: current_user_role_name))
@manifestations.each do |manifestation|
if policy_scope(manifestation.items).empty?
sheet.add_row manifestation.to_hash(role: current_user_role_name).values
sheet.add_row manifestation.to_hash(role: current_user_role_name).values,
types: manifestation.to_hash(role: current_user_role_name).count.times.map { :string }
else
policy_scope(manifestation.items).each do |item|
sheet.add_row (manifestation.to_hash(role: current_user_role_name).values + item.to_hash(role: current_user_role_name).values)
sheet.add_row (manifestation.to_hash(role: current_user_role_name).values + item.to_hash(role: current_user_role_name).values),
types: (manifestation.to_hash(role: current_user_role_name).count + item.to_hash(role: current_user_role_name).count).times.map { :string }
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddUniqueIndexToAcceptsOnItemId < ActiveRecord::Migration[6.1]
def change
remove_index :accepts, :item_id
add_index :accepts, :item_id, unique: true

remove_index :withdraws, :item_id
add_index :withdraws, :item_id, unique: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class AddUniqueIndexToCheckedItemsOnBasketIdAndItemId < ActiveRecord::Migration[6.1]
def change
remove_index :checked_items, :item_id
add_index :checked_items, [:item_id, :basket_id], unique: true

remove_index :checkins, :item_id
add_index :checkins, [:item_id, :basket_id], unique: true

remove_index :checkouts, [:item_id, :basket_id]
add_index :checkouts, [:item_id, :basket_id, :user_id], unique: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUniqueIndexToLibrariesOnName < ActiveRecord::Migration[6.1]
def change
add_index :libraries, :name, unique: true
add_index :libraries, :isil, unique: true, where: "isil != '' AND isil IS NOT NULL"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUniqueIndexToItemsOnItemIdentifier < ActiveRecord::Migration[6.1]
def change
remove_index :items, :item_identifier
add_index :items, :item_identifier, unique: true, where: "item_identifier != '' AND item_identifier IS NOT NULL"
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddUniqueIndexToCarrierTypeHasCheckoutTypesOnCarrierTypeIdAndCheckoutTypeId < ActiveRecord::Migration[6.1]
def change
remove_index :carrier_type_has_checkout_types, :carrier_type_id
add_index :carrier_type_has_checkout_types, [:carrier_type_id, :checkout_type_id], unique: true, name: 'index_carrier_type_has_checkout_types_on_carrier_type_id'

remove_index :user_group_has_checkout_types, :user_group_id
add_index :user_group_has_checkout_types, [:user_group_id, :checkout_type_id], unique: true, name: 'index_user_group_has_checkout_types_on_user_group_id'
end
end
20 changes: 11 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_08_18_154419) do
ActiveRecord::Schema[7.0].define(version: 2023_10_28_035847) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand All @@ -21,7 +21,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["basket_id"], name: "index_accepts_on_basket_id"
t.index ["item_id"], name: "index_accepts_on_item_id"
t.index ["item_id"], name: "index_accepts_on_item_id", unique: true
t.index ["librarian_id"], name: "index_accepts_on_librarian_id"
end

Expand Down Expand Up @@ -275,7 +275,7 @@
t.integer "position"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["carrier_type_id"], name: "index_carrier_type_has_checkout_types_on_m_form_id"
t.index ["carrier_type_id", "checkout_type_id"], name: "index_carrier_type_has_checkout_types_on_carrier_type_id", unique: true
t.index ["checkout_type_id"], name: "index_carrier_type_has_checkout_types_on_checkout_type_id"
end

Expand All @@ -298,7 +298,7 @@
t.datetime "updated_at", null: false
t.bigint "user_id"
t.index ["basket_id"], name: "index_checked_items_on_basket_id"
t.index ["item_id"], name: "index_checked_items_on_item_id"
t.index ["item_id", "basket_id"], name: "index_checked_items_on_item_id_and_basket_id", unique: true
t.index ["librarian_id"], name: "index_checked_items_on_librarian_id"
t.index ["user_id"], name: "index_checked_items_on_user_id"
end
Expand All @@ -311,7 +311,7 @@
t.datetime "updated_at", null: false
t.integer "lock_version", default: 0, null: false
t.index ["basket_id"], name: "index_checkins_on_basket_id"
t.index ["item_id"], name: "index_checkins_on_item_id"
t.index ["item_id", "basket_id"], name: "index_checkins_on_item_id_and_basket_id", unique: true
t.index ["librarian_id"], name: "index_checkins_on_librarian_id"
end

Expand Down Expand Up @@ -360,7 +360,7 @@
t.bigint "library_id"
t.index ["basket_id"], name: "index_checkouts_on_basket_id"
t.index ["checkin_id"], name: "index_checkouts_on_checkin_id"
t.index ["item_id", "basket_id"], name: "index_checkouts_on_item_id_and_basket_id", unique: true
t.index ["item_id", "basket_id", "user_id"], name: "index_checkouts_on_item_id_and_basket_id_and_user_id", unique: true
t.index ["item_id"], name: "index_checkouts_on_item_id"
t.index ["librarian_id"], name: "index_checkouts_on_librarian_id"
t.index ["library_id"], name: "index_checkouts_on_library_id"
Expand Down Expand Up @@ -769,7 +769,7 @@
t.index ["bookstore_id"], name: "index_items_on_bookstore_id"
t.index ["checkout_type_id"], name: "index_items_on_checkout_type_id"
t.index ["circulation_status_id"], name: "index_items_on_circulation_status_id"
t.index ["item_identifier"], name: "index_items_on_item_identifier"
t.index ["item_identifier"], name: "index_items_on_item_identifier", unique: true, where: "(((item_identifier)::text <> ''::text) AND (item_identifier IS NOT NULL))"
t.index ["manifestation_id"], name: "index_items_on_manifestation_id"
t.index ["required_role_id"], name: "index_items_on_required_role_id"
t.index ["shelf_id"], name: "index_items_on_shelf_id"
Expand Down Expand Up @@ -833,7 +833,9 @@
t.float "latitude"
t.float "longitude"
t.index "lower((name)::text)", name: "index_libraries_on_lower_name", unique: true
t.index ["isil"], name: "index_libraries_on_isil", unique: true, where: "(((isil)::text <> ''::text) AND (isil IS NOT NULL))"
t.index ["library_group_id"], name: "index_libraries_on_library_group_id"
t.index ["name"], name: "index_libraries_on_name", unique: true
end

create_table "library_group_translations", force: :cascade do |t|
Expand Down Expand Up @@ -1713,7 +1715,7 @@
t.datetime "updated_at", null: false
t.integer "current_checkout_count"
t.index ["checkout_type_id"], name: "index_user_group_has_checkout_types_on_checkout_type_id"
t.index ["user_group_id"], name: "index_user_group_has_checkout_types_on_user_group_id"
t.index ["user_group_id", "checkout_type_id"], name: "index_user_group_has_checkout_types_on_user_group_id", unique: true
end

create_table "user_groups", force: :cascade do |t|
Expand Down Expand Up @@ -1831,7 +1833,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["basket_id"], name: "index_withdraws_on_basket_id"
t.index ["item_id"], name: "index_withdraws_on_item_id"
t.index ["item_id"], name: "index_withdraws_on_item_id", unique: true
t.index ["librarian_id"], name: "index_withdraws_on_librarian_id"
end

Expand Down
17 changes: 17 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'

services:
web:
environment:
- WEBPACKER_DEV_SERVER_HOST=webpacker
- SELENIUM_DRIVER_URL=http://selenium:4444/wd/hub

selenium:
image: selenium/standalone-chrome:114.0
networks:
internal:
expose:
- 4444
- 7900
- 5900
shm_size: 2gb
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ services:
internal:
expose:
- 6379
restart: always
healthcheck:
test: ["CMD-SHELL", "redis-cli ping"]
interval: 30s
Expand Down
55 changes: 55 additions & 0 deletions lib/tasks/enju_leaf_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,59 @@ namespace :enju_leaf do
migrate_attachment
end
end

desc 'Migrate identifiers'
task :migrate_identifiers => :environment do
IdentifierType.find_each do |identifier_type|
Identifier.where(identifier_type: identifier_type).find_each do |identifier|
Manifestation.transaction do
case identifier_type.name
when 'isbn'
IsbnRecordAndManifestation.create(
manifestation: identifier.manifestation,
isbn_record: IsbnRecord.find_by(body: identifier.body)
)
when 'issn'
IssnRecordAndManifestation.create(
manifestation: identifier.manifestation,
issn_record: IssnRecord.find_by(body: identifier.body)
)
when 'issn_l'
IssnRecordAndManifestation.create(
manifestation: identifier.manifestation,
issn_record: IssnRecord.find_by(body: identifier.body)
)
when 'jpno'
JpnoRecord.create(
manifestation: identifier.manifestation,
body: identifier.body
)
when 'iss_itemno'
NdlBibIdRecord.create(
manifestation: identifier.manifestation,
body: identifier.body
)
when 'ncid'
NcidRecord.create(
manifestation: identifier.manifestation,
body: identifier.body
)
when 'lccn'
LccnRecord.create(
manifestation: identifier.manifestation,
body: identifier.body
)
when 'doi'
DoiRecord.create(
manifestation: identifier.manifestation,
body: identifier.body
)
end

identifier.destroy
Rails.logger.info "#{identifier_type.name} #{identifier.body} migrated"
end
end
end
end
end
Loading

0 comments on commit d87ac8a

Please sign in to comment.