enju_circulation 0.2.0.beta.3 → 0.2.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/checkouts_controller.rb +4 -5
  3. data/app/controllers/reserves_controller.rb +4 -4
  4. data/app/helpers/items_helper.rb +2 -2
  5. data/app/models/concerns/enju_circulation/enju_accept.rb +1 -0
  6. data/app/models/concerns/enju_circulation/enju_item.rb +7 -6
  7. data/app/models/reserve.rb +1 -1
  8. data/app/models/reserve_state_machine.rb +4 -2
  9. data/app/views/checked_items/new.html.erb +2 -1
  10. data/app/views/checkouts/_index.html.erb +2 -2
  11. data/app/views/checkouts/_index_item.html.erb +2 -2
  12. data/app/views/checkouts/_index_overdue.html.erb +2 -2
  13. data/app/views/checkouts/_index_user.html.erb +5 -5
  14. data/app/views/checkouts/index.txt.erb +1 -1
  15. data/app/views/lending_policies/index.html.erb +2 -2
  16. data/app/views/profiles/_checkout_list.html.erb +3 -3
  17. data/app/views/reserves/_title.html.erb +1 -1
  18. data/app/views/reserves/index.html.erb +4 -4
  19. data/db/migrate/032_create_checkins.rb +3 -6
  20. data/db/migrate/033_create_checkouts.rb +8 -13
  21. data/db/migrate/035_create_reserves.rb +6 -11
  22. data/db/migrate/121_create_checked_items.rb +4 -5
  23. data/db/migrate/127_create_use_restrictions.rb +1 -1
  24. data/db/migrate/129_create_item_has_use_restrictions.rb +2 -4
  25. data/db/migrate/132_create_circulation_statuses.rb +1 -1
  26. data/db/migrate/20081030023518_create_user_group_has_checkout_types.rb +8 -10
  27. data/db/migrate/20081030023615_create_carrier_type_has_checkout_types.rb +3 -4
  28. data/db/migrate/20081212075554_create_checkout_stat_has_manifestations.rb +4 -4
  29. data/db/migrate/20081215094955_create_checkout_stat_has_users.rb +3 -5
  30. data/db/migrate/20081216190517_create_reserve_stat_has_manifestations.rb +3 -3
  31. data/db/migrate/20081220034117_create_reserve_stat_has_users.rb +2 -4
  32. data/db/migrate/20090831220301_create_lending_policies.rb +5 -5
  33. data/db/migrate/20120424103932_add_librarian_id_to_checked_item.rb +1 -1
  34. data/db/migrate/20130416054135_add_circulation_status_id_to_item.rb +2 -2
  35. data/db/migrate/20140810061942_add_user_id_to_user_checkout_stat.rb +4 -8
  36. data/db/migrate/20141014065831_add_shelf_id_to_checkout.rb +1 -2
  37. data/db/migrate/20141020120523_add_library_id_to_checkout.rb +1 -2
  38. data/db/migrate/20150106001709_create_demands.rb +3 -6
  39. data/lib/enju_circulation/version.rb +1 -1
  40. data/lib/generators/enju_circulation/setup/setup_generator.rb +3 -3
  41. data/spec/concerns/enju_accept_spec.rb +30 -0
  42. data/spec/controllers/checkins_controller_spec.rb +1 -1
  43. data/spec/controllers/checkouts_controller_spec.rb +2 -1
  44. data/spec/controllers/reserves_controller_spec.rb +14 -12
  45. data/spec/dummy/db/schema.rb +4 -2
  46. data/spec/factories/accept.rb +21 -0
  47. data/spec/factories/reserve.rb +1 -1
  48. data/spec/fixtures/reserve_transitions.yml +15 -0
  49. data/spec/helpers/items_helper_spec.rb +20 -0
  50. data/spec/models/reserve_spec.rb +28 -3
  51. data/spec/rails_helper.rb +1 -0
  52. data/spec/views/checked_items/new.html.erb_spec.rb +16 -0
  53. metadata +322 -300
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d1d84454c986115d3db9e73886c0abfca5f76df
4
- data.tar.gz: 3fbd2b6d37dabd55eee9c0e5c7ec2d48aceef3c7
3
+ metadata.gz: 70e88e19ea6e53056364cf7f3ded68df0ca1ff8a
4
+ data.tar.gz: bfb54de863b490dde5ab42e8d60d01047ef22158
5
5
  SHA512:
6
- metadata.gz: 4990f4b9e09874aa760dbfbee3315ab1899b1b10238d2e862e6d64b7185fa2d0eced8f381b1bccd3b2abfdedc54b6b65ad1fb43c315a05341280dc31a89d978c
7
- data.tar.gz: 6e467c07538e1332b66ac99b6ad846bd5e74cb9aa62618b7e02e0a90f550dc20afba6d6deb4daa19f196c55edab7094da42db44e81f37e2ebebc0bc35293fb82
6
+ metadata.gz: c4f05624b087d7e3b1822ada2f5333476013e4034bd7ccb43915502852eefbd2529c0863bacbab0a4ecf838eb4ecc543d9067875758b4de282493fdee072c64b
7
+ data.tar.gz: 79b6fb73a6e1004eb2e9cf3a764cbed4e7b3a50af0c1400ffe58d151a28862c1ec589680a6cf5166b4f44340bfecf043dbb6fd9949abbacfd8b920906e31bbd1
@@ -21,10 +21,12 @@ class CheckoutsController < ApplicationController
21
21
  end
22
22
  end
23
23
 
24
- if params[:format] == 'txt'
24
+ if ['txt', 'rss'].include?(params[:format].to_s.downcase)
25
25
  per_page = 500
26
+ page = 1
26
27
  else
27
28
  per_page = Checkout.default_per_page
29
+ page = params[:page] || 1
28
30
  end
29
31
 
30
32
  unless icalendar_user
@@ -86,10 +88,7 @@ class CheckoutsController < ApplicationController
86
88
  order_by :created_at, :desc
87
89
  facet :reserved
88
90
  end
89
- page = params[:page] || 1
90
- unless params[:format].to_s.downcase == 'txt'
91
- search.query.paginate(page.to_i, Checkout.default_per_page)
92
- end
91
+ search.query.paginate(page.to_i, per_page)
93
92
  @checkouts = search.execute!.results
94
93
  @checkouts_facet = search.facet(:reserved).rows
95
94
  end
@@ -34,12 +34,12 @@ class ReservesController < ApplicationController
34
34
  sort_column = :created_at
35
35
  order = :desc
36
36
  end
37
- if params[:format].to_s.downcase == 'txt'
37
+ if ['txt', 'rss'].include?(params[:format].to_s.downcase)
38
+ per_page = 500
38
39
  page = 1
39
- per_page = 65534
40
40
  else
41
- page ||= params[:page] || 1
42
- per_page ||= Reserve.default_per_page
41
+ per_page = Reserve.default_per_page
42
+ page = params[:page] || 1
43
43
  end
44
44
 
45
45
  if params[:mode] == 'hold' and current_user.has_role?('Librarian')
@@ -7,10 +7,10 @@ module ItemsHelper
7
7
  current = true if params[:circulation_status] == circulation_status.name
8
8
  if current
9
9
  content_tag :strong do
10
- link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.permit.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
10
+ link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
11
11
  end
12
12
  else
13
- link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.permit.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
13
+ link_to("#{circulation_status.display_name.localize} (" + facet.count.to_s + ")", url_for(params.merge(circulation_status: circulation_status.name, page: nil, view: nil, only_path: true)))
14
14
  end
15
15
  end
16
16
  end
@@ -11,6 +11,7 @@ module EnjuCirculation
11
11
  item.update_column(:circulation_status_id, circulation_status.id) if circulation_status
12
12
  use_restriction = UseRestriction.where(name: 'Limited Circulation, Normal Loan Period').first
13
13
  item.use_restriction = use_restriction if use_restriction
14
+ item.index
14
15
  end
15
16
  end
16
17
  end
@@ -100,20 +100,21 @@ module EnjuCirculation
100
100
  def retain(librarian)
101
101
  self.class.transaction do
102
102
  reservation = manifestation.next_reservation
103
- unless reservation.nil?
103
+ if reservation
104
104
  reservation.item = self
105
- reservation.transition_to!(:retained)
105
+ reservation.transition_to!(:retained) unless reservation.retained?
106
106
  reservation.send_message(librarian)
107
107
  end
108
108
  end
109
109
  end
110
110
 
111
111
  def retained?
112
- if manifestation.next_reservation.try(:current_state) == 'retained' and manifestation.next_reservation.item == self
113
- return true
114
- else
115
- false
112
+ manifestation.reserves.retained.each do |reserve|
113
+ if reserve.item == self
114
+ return true
115
+ end
116
116
  end
117
+ false
117
118
  end
118
119
 
119
120
  def lending_rule(user)
@@ -2,7 +2,7 @@ class Reserve < ActiveRecord::Base
2
2
  include Statesman::Adapters::ActiveRecordQueries
3
3
  scope :hold, -> { where('item_id IS NOT NULL') }
4
4
  scope :not_hold, -> { where(item_id: nil) }
5
- scope :waiting, -> {not_in_state(:completed, :expired).where('canceled_at IS NULL AND (expired_at > ? OR expired_at IS NULL)', Time.zone.now).order('reserves.id DESC')}
5
+ scope :waiting, -> {not_in_state(:completed, :expired, :retained).where('canceled_at IS NULL AND (expired_at > ? OR expired_at IS NULL)', Time.zone.now).order('reserves.id DESC')}
6
6
  scope :retained, -> {in_state(:retained).where('retained_at IS NOT NULL')}
7
7
  scope :completed, -> {in_state(:completed).where('checked_out_at IS NOT NULL')}
8
8
  scope :canceled, -> {in_state(:canceled).where('canceled_at IS NOT NULL')}
@@ -21,8 +21,10 @@ class ReserveStateMachine
21
21
  # TODO: 「取り置き中」の状態を正しく表す
22
22
  reserve.update_attributes({request_status_type: RequestStatusType.where(name: 'In Process').first, retained_at: Time.zone.now})
23
23
  Reserve.transaction do
24
- if reserve.item and reserve.next_reservation
25
- reserve.item.reserves.waiting.readonly(false).map{|r|
24
+ if reserve.item
25
+ other_reserves = reserve.item.reserves.waiting
26
+ other_reserves += reserve.item.reserves.in_state(:retained)
27
+ other_reserves.each{|r|
26
28
  if r != reserve
27
29
  r.transition_to!(:postponed)
28
30
  r.item = nil
@@ -12,7 +12,8 @@
12
12
 
13
13
  <div id="submenu" class="ui-corner-all ui-widget-content">
14
14
  <ul>
15
- <li><%= link_to @basket.user.username, @basket.user.profile -%></li>
15
+ <li><%= t('activerecord.attributes.user.username') %>: <%= link_to @basket.user.username, @basket.user.profile -%></li>
16
+ <li><%= t('activerecord.attributes.user.user_number') %>: <%= @basket.user.profile.user_number %></li>
16
17
  </ul>
17
18
  <ul>
18
19
  <%- @basket.user.profile.user_group.user_group_has_checkout_types.each do |available_checkout_type| -%>
@@ -21,11 +21,11 @@
21
21
  <ul>
22
22
  <li>
23
23
  <%= link_to 'RSS', checkouts_path(format: :rss) -%>
24
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: 'RSS', class: 'icon'), checkouts_path(format: :rss) -%>
24
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: 'RSS'), checkouts_path(format: :rss) -%>
25
25
  </li>
26
26
  <li>
27
27
  <%= link_to 'TSV', checkouts_path(format: :txt, locale: @locale.to_s) -%>
28
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), checkouts_path(format: :txt, locale: @locale.to_s) -%>
28
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), checkouts_path(format: :txt, locale: @locale.to_s) -%>
29
29
  </li>
30
30
  </ul>
31
31
  </div>
@@ -19,11 +19,11 @@
19
19
  <ul>
20
20
  <li>
21
21
  <%= link_to 'RSS', item_checkouts_path(item, format: :rss) -%>
22
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: 'RSS', class: 'icon'), item_checkouts_path(item, format: :rss) -%>
22
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: 'RSS'), item_checkouts_path(item, format: :rss) -%>
23
23
  </li>
24
24
  <li>
25
25
  <%= link_to 'TSV', item_checkouts_path(item, format: :txt, locale: @locale.to_s) -%>
26
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), item_checkouts_path(item, format: :txt, locale: @locale.to_s) -%>
26
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), item_checkouts_path(item, format: :txt, locale: @locale.to_s) -%>
27
27
  </li>
28
28
  </ul>
29
29
  </div>
@@ -28,11 +28,11 @@
28
28
  <ul>
29
29
  <li>
30
30
  <%= link_to 'RSS', checkouts_path(format: :rss, days_overdue: 1) -%>
31
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: 'RSS', class: 'icon'), checkouts_path(format: :rss, days_overdue: 1) -%>
31
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: 'RSS'), checkouts_path(format: :rss, days_overdue: 1) -%>
32
32
  </li>
33
33
  <li>
34
34
  <%= link_to 'TSV', checkouts_path(format: :txt, days_overdue: 1, locale: @locale.to_s) -%>
35
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), checkouts_path(format: :txt, days_overdue: 1, locale: @locale.to_s) -%>
35
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), checkouts_path(format: :txt, days_overdue: 1, locale: @locale.to_s) -%>
36
36
  </li>
37
37
  </ul>
38
38
  </div>
@@ -30,26 +30,26 @@
30
30
  <% if current_user.profile.checkout_icalendar_token? %>
31
31
  <li>
32
32
  <%= link_to 'iCalendar', checkouts_path(icalendar_token: user.profile.checkout_icalendar_token, format: :ics) -%>
33
- <%= link_to (image_tag 'icons/date.png', size: '16x16', alt: 'iCalendar', class: 'icon'), checkouts_path(user_id: user.username, format: :ics) -%>
33
+ <%= link_to image_tag('icons/date.png', size: '16x16', class: 'enju_icon', alt: 'iCalendar'), checkouts_path(user_id: user.username, format: :ics) -%>
34
34
  </li>
35
35
  <% end %>
36
36
  <%- if params[:days_overdue].present? -%>
37
37
  <li>
38
38
  <%= link_to 'RSS', checkouts_path(user_id: user.username, format: :rss, days_overdue: 1) -%>
39
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: 'RSS', class: 'icon'), checkouts_path(user_id: user.username, format: :rss, days_overdue: 1) -%>
39
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: 'RSS'), checkouts_path(user_id: user.username, format: :rss, days_overdue: 1) -%>
40
40
  </li>
41
41
  <li>
42
42
  <%= link_to 'TSV', checkouts_path(user_id: user.username, format: :txt, days_overdue: 1, locale: @locale.to_s) -%>
43
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), checkouts_path(user_id: user.username, format: :txt, days_overdue: 1, locale: @locale.to_s) -%>
43
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), checkouts_path(user_id: user.username, format: :txt, days_overdue: 1, locale: @locale.to_s) -%>
44
44
  </li>
45
45
  <%- else -%>
46
46
  <li>
47
47
  <%= link_to 'RSS', checkouts_path(user_id: user.username, format: :rss) -%>
48
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: 'RSS', class: 'icon'), checkouts_path(user_id: user.username, format: :rss) -%>
48
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: 'RSS'), checkouts_path(user_id: user.username, format: :rss) -%>
49
49
  </li>
50
50
  <li>
51
51
  <%= link_to 'TSV', checkouts_path(user_id: user.username, format: :txt, locale: @locale.to_s) -%>
52
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), checkouts_path(user_id: user.username, format: :txt, locale: @locale.to_s) -%>
52
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), checkouts_path(user_id: user.username, format: :txt, locale: @locale.to_s) -%>
53
53
  </li>
54
54
  <%- end -%>
55
55
  </ul>
@@ -1,4 +1,4 @@
1
- <%- if params[:days_overdue].present? -%><%= 'Overdue items' -%><%- else -%><%= 'Checkout items' -%><%- end -%> (created_at: <%= Time.now -%>)<%= "\n" -%>
1
+ username item_identifier title checked_out_at due_date <%- if params[:days_overdue].present? -%><%= 'Overdue items' -%><%- else -%><%= 'Checkout items' -%><%- end -%> (created_at: <%= Time.now -%>)<%= "\n" -%>
2
2
  <%- @checkouts.each do |checkout| -%>
3
3
  "<%=h checkout.user.try(:username) -%>" "<%=h checkout.item.item_identifier -%>" "<%=h checkout.item.manifestation.original_title -%>" "<%=h checkout.created_at -%>" "<%= checkout.due_date -%>"<%= "\n" -%>
4
4
  <%- end -%>
@@ -26,8 +26,8 @@
26
26
  <td><%= lending_policy.fine -%></td>
27
27
  <td>
28
28
  <%= link_to t('page.show'), lending_policy -%>
29
- <%= link_to t('page.edit'), edit_lending_policy_path(lending_policy) -%>
30
- <%= link_to t('page.destroy'), lending_policy, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
29
+ <%= link_to t('page.edit'), edit_lending_policy_path(lending_policy) if policy(lending_policy).update?-%>
30
+ <%= link_to t('page.destroy'), lending_policy, data: {confirm: t('page.are_you_sure')}, method: :delete if policy(lending_policy).destroy? -%>
31
31
  </td>
32
32
  </tr>
33
33
  <%- end -%>
@@ -1,8 +1,8 @@
1
1
  <h2>
2
2
  <%= t('activerecord.models.checkout') %>
3
- <%= link_to image_tag('icons/date.png', size: '16x16', alt: 'iCalendar', class: 'icon'), checkouts_path(icalendar_token: current_user.profile.checkout_icalendar_token, format: :ics) if current_user.profile.checkout_icalendar_token? %>
4
- <%= link_to image_tag('icons/feed.png', size: '16x16', alt: 'RSS', class: 'icon'), checkouts_path(user_id: current_user.username, format: :rss) %>
5
- <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), checkouts_path(user_id: current_user.username, format: :txt) %>
3
+ <%= link_to image_tag('icons/date.png', size: '16x16', class: 'enju_icon', alt: 'iCalendar'), checkouts_path(icalendar_token: current_user.profile.checkout_icalendar_token, format: :ics) if current_user.profile.checkout_icalendar_token? %>
4
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: 'RSS'), checkouts_path(user_id: current_user.username, format: :rss) %>
5
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), checkouts_path(user_id: current_user.username, format: :txt) %>
6
6
  </h2>
7
7
  <% if profile.user %>
8
8
  <%= render 'checkouts/list', checkouts: profile.user.checkouts.order('created_at DESC').page(params[:page]) %>
@@ -17,6 +17,6 @@
17
17
  <%- if reserve.manifestation.access_address? -%>
18
18
  <br />
19
19
  <%= link_to reserve.manifestation.access_address, reserve.manifestation.access_address -%>
20
- <%= link_to image_tag('icons/world_go.png', size: '16x16', alt: 'Web'), reserve.manifestation.access_address -%>
20
+ <%= link_to image_tag('icons/world_go.png', size: '16x16', class: 'enju_icon', alt: 'Web'), reserve.manifestation.access_address -%>
21
21
  <%- end -%>
22
22
  <% end %>
@@ -103,14 +103,14 @@
103
103
 
104
104
  <p>
105
105
  <%- if @user -%>
106
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: t('page.feed'), class: 'icon'), reserves_path(user_id: @user.username, format: :rss) -%>
106
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), reserves_path(user_id: @user.username, format: :rss) -%>
107
107
  (<%= link_to 'RSS', reserves_path(user_id: @user.username, format: :rss) -%>)
108
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), reserves_path(user_id: @user.username, format: :txt, locale: @locale.to_s) -%>
108
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), reserves_path(user_id: @user.username, format: :txt, locale: @locale.to_s) -%>
109
109
  (<%= link_to 'TSV', reserves_path(user_id: @user.username, format: :txt, locale: @locale.to_s) -%>)
110
110
  <%- else -%>
111
- <%= link_to (image_tag 'icons/feed.png', size: '16x16', alt: t('page.feed'), class: 'icon'), reserves_path(format: :rss) -%>
111
+ <%= link_to image_tag('icons/feed.png', size: '16x16', class: 'enju_icon', alt: t('page.feed')), reserves_path(format: :rss) -%>
112
112
  (<%= link_to 'RSS', reserves_path(format: :rss) -%>)
113
- <%= link_to (image_tag 'icons/page_white_excel.png', size: '16x16', alt: 'TSV', class: 'icon'), reserves_path(format: :txt, locale: @locale.to_s) -%>
113
+ <%= link_to image_tag('icons/page_white_excel.png', size: '16x16', class: 'enju_icon', alt: 'TSV'), reserves_path(format: :txt, locale: @locale.to_s) -%>
114
114
  (<%= link_to 'TSV', reserves_path(format: :txt, locale: @locale.to_s) -%>)
115
115
  <%- end -%>
116
116
  </p>
@@ -1,14 +1,11 @@
1
1
  class CreateCheckins < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :checkins do |t|
4
- t.integer :item_id, :null => false
5
- t.integer :librarian_id
6
- t.integer :basket_id
4
+ t.references :item, index: true, foreign_key: true, null: false
5
+ t.references :librarian, index: true
6
+ t.references :basket, index: true
7
7
  t.timestamps
8
8
  end
9
- add_index :checkins, :item_id
10
- add_index :checkins, :librarian_id
11
- add_index :checkins, :basket_id
12
9
  end
13
10
 
14
11
  def self.down
@@ -1,22 +1,17 @@
1
1
  class CreateCheckouts < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :checkouts do |t|
4
- t.integer :user_id
5
- t.integer :item_id, :null => false
6
- t.integer :checkin_id
7
- t.integer :librarian_id
8
- t.integer :basket_id
4
+ t.references :user, index: true, foreign_key: true
5
+ t.references :item, index: true, foreign_key: true, null: false
6
+ t.references :checkin, index: true, foreign_key: true
7
+ t.references :librarian, index: true
8
+ t.references :basket, index: true
9
9
  t.datetime :due_date
10
- t.integer :checkout_renewal_count, :default => 0, :null => false
11
- t.integer :lock_version, :default => 0, :null => false
10
+ t.integer :checkout_renewal_count, default: 0, null: false
11
+ t.integer :lock_version, default: 0, null: false
12
12
  t.timestamps
13
13
  end
14
- add_index :checkouts, :user_id
15
- add_index :checkouts, :item_id
16
- add_index :checkouts, :basket_id
17
- add_index :checkouts, [:item_id, :basket_id], :unique => true
18
- add_index :checkouts, :librarian_id
19
- add_index :checkouts, :checkin_id
14
+ add_index :checkouts, [:item_id, :basket_id], unique: true
20
15
  end
21
16
 
22
17
  def self.down
@@ -1,23 +1,18 @@
1
1
  class CreateReserves < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :reserves do |t|
4
- t.integer :user_id, :null => false
5
- t.integer :manifestation_id, :null => false
6
- t.integer :item_id
7
- t.integer :request_status_type_id, :null => false
4
+ t.references :user, index: true, foreign_key: true, null: false
5
+ t.references :manifestation, index: true, null: false
6
+ t.references :item, index: true
7
+ t.references :request_status_type, null: false
8
8
  t.datetime :checked_out_at
9
9
  t.timestamps
10
10
  t.datetime :canceled_at
11
11
  t.datetime :expired_at
12
12
  t.datetime :deleted_at
13
- t.boolean :expiration_notice_to_patron, :default => false
14
- t.boolean :expiration_notice_to_library, :default => false
13
+ t.boolean :expiration_notice_to_patron, default: false
14
+ t.boolean :expiration_notice_to_library, default: false
15
15
  end
16
-
17
- add_index :reserves, :user_id
18
- add_index :reserves, :manifestation_id
19
- add_index :reserves, :item_id
20
- add_index :reserves, :request_status_type_id
21
16
  end
22
17
 
23
18
  def self.down
@@ -1,14 +1,13 @@
1
1
  class CreateCheckedItems < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :checked_items do |t|
4
- t.integer :item_id, :null => false
5
- t.integer :basket_id, :null => false
6
- t.datetime :due_date, :null => false
4
+ t.references :item, index: true, foreign_key: true, null: false
5
+ t.references :basket, index: true, foreign_key: true, null: false
6
+ t.references :librarian, index: true
7
+ t.datetime :due_date, null: false
7
8
 
8
9
  t.timestamps
9
10
  end
10
- add_index :checked_items, :item_id
11
- add_index :checked_items, :basket_id
12
11
  end
13
12
 
14
13
  def self.down
@@ -1,7 +1,7 @@
1
1
  class CreateUseRestrictions < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :use_restrictions do |t|
4
- t.string :name, :null => false
4
+ t.string :name, null: false
5
5
  t.text :display_name
6
6
  t.text :note
7
7
  t.integer :position
@@ -1,13 +1,11 @@
1
1
  class CreateItemHasUseRestrictions < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :item_has_use_restrictions do |t|
4
- t.integer :item_id, :null => false
5
- t.integer :use_restriction_id, :null => false
4
+ t.references :item, index: true, foreign_key: true, null: false
5
+ t.references :use_restriction, index: true, foreign_key: true, null: false
6
6
 
7
7
  t.timestamps
8
8
  end
9
- add_index :item_has_use_restrictions, :item_id
10
- add_index :item_has_use_restrictions, :use_restriction_id
11
9
  end
12
10
 
13
11
  def self.down
@@ -1,7 +1,7 @@
1
1
  class CreateCirculationStatuses < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :circulation_statuses do |t|
4
- t.string :name, :null => false
4
+ t.string :name, null: false
5
5
  t.text :display_name
6
6
  t.text :note
7
7
  t.integer :position
@@ -1,22 +1,20 @@
1
1
  class CreateUserGroupHasCheckoutTypes < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :user_group_has_checkout_types do |t|
4
- t.integer :user_group_id, :null => false
5
- t.integer :checkout_type_id, :null => false
6
- t.integer :checkout_limit, :default => 0, :null => false
7
- t.integer :checkout_period, :default => 0, :null => false
8
- t.integer :checkout_renewal_limit, :default => 0, :null => false
9
- t.integer :reservation_limit, :default => 0, :null => false
10
- t.integer :reservation_expired_period, :default => 7, :null => false
11
- t.boolean :set_due_date_before_closing_day, :default => false, :null => false
4
+ t.references :user_group, index: true, foreign_key: true, null: false
5
+ t.references :checkout_type, index: true, foreign_key: true, null: false
6
+ t.integer :checkout_limit, default: 0, null: false
7
+ t.integer :checkout_period, default: 0, null: false
8
+ t.integer :checkout_renewal_limit, default: 0, null: false
9
+ t.integer :reservation_limit, default: 0, null: false
10
+ t.integer :reservation_expired_period, default: 7, null: false
11
+ t.boolean :set_due_date_before_closing_day, default: false, null: false
12
12
  t.datetime :fixed_due_date
13
13
  t.text :note
14
14
  t.integer :position
15
15
 
16
16
  t.timestamps
17
17
  end
18
- add_index :user_group_has_checkout_types, :user_group_id
19
- add_index :user_group_has_checkout_types, :checkout_type_id
20
18
  end
21
19
 
22
20
  def self.down