spina-admin-conferences-fork 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (210) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +100 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/config/spina_admin_conferences_manifest.js +3 -0
  6. data/app/assets/javascripts/controllers/spina/admin/conferences/conference_events_form_controller.js +174 -0
  7. data/app/assets/javascripts/controllers/spina/admin/conferences/presentation_attachments_form_controller.js +174 -0
  8. data/app/assets/javascripts/controllers/spina/admin/conferences/select_options_controller.js +215 -0
  9. data/app/assets/javascripts/importmap.json.erb +6 -0
  10. data/app/assets/javascripts/spina/admin/conferences/application.js +4 -0
  11. data/app/assets/stylesheets/spina/admin/conferences/application.sass +3 -0
  12. data/app/controllers/spina/admin/conferences/application_controller.rb +23 -0
  13. data/app/controllers/spina/admin/conferences/conferences_controller.rb +139 -0
  14. data/app/controllers/spina/admin/conferences/delegates_controller.rb +114 -0
  15. data/app/controllers/spina/admin/conferences/dietary_requirements_controller.rb +106 -0
  16. data/app/controllers/spina/admin/conferences/events_controller.rb +24 -0
  17. data/app/controllers/spina/admin/conferences/institutions_controller.rb +106 -0
  18. data/app/controllers/spina/admin/conferences/presentation_attachment_types_controller.rb +104 -0
  19. data/app/controllers/spina/admin/conferences/presentation_attachments_controller.rb +24 -0
  20. data/app/controllers/spina/admin/conferences/presentation_types_controller.rb +109 -0
  21. data/app/controllers/spina/admin/conferences/presentations_controller.rb +123 -0
  22. data/app/controllers/spina/admin/conferences/rooms_controller.rb +109 -0
  23. data/app/controllers/spina/admin/conferences/sessions_controller.rb +118 -0
  24. data/app/jobs/spina/admin/conferences/application_job.rb +11 -0
  25. data/app/jobs/spina/admin/conferences/delegate_import_job.rb +37 -0
  26. data/app/jobs/spina/admin/conferences/import_job.rb +26 -0
  27. data/app/jobs/spina/admin/conferences/presentation_import_job.rb +37 -0
  28. data/app/mailers/spina/admin/conferences/application_mailer.rb +13 -0
  29. data/app/models/spina/admin/conferences/application_record.rb +14 -0
  30. data/app/models/spina/admin/conferences/conference.rb +269 -0
  31. data/app/models/spina/admin/conferences/delegate.rb +89 -0
  32. data/app/models/spina/admin/conferences/dietary_requirement.rb +33 -0
  33. data/app/models/spina/admin/conferences/event.rb +85 -0
  34. data/app/models/spina/admin/conferences/institution.rb +46 -0
  35. data/app/models/spina/admin/conferences/presentation.rb +134 -0
  36. data/app/models/spina/admin/conferences/presentation_attachment.rb +27 -0
  37. data/app/models/spina/admin/conferences/presentation_attachment_type.rb +35 -0
  38. data/app/models/spina/admin/conferences/presentation_type.rb +60 -0
  39. data/app/models/spina/admin/conferences/room.rb +52 -0
  40. data/app/models/spina/admin/conferences/session.rb +56 -0
  41. data/app/models/spina/admin/conferences.rb +11 -0
  42. data/app/models/spina/parts/admin/conferences/date.rb +14 -0
  43. data/app/models/spina/parts/admin/conferences/email_address.rb +20 -0
  44. data/app/models/spina/parts/admin/conferences/time.rb +14 -0
  45. data/app/models/spina/parts/admin/conferences/url.rb +20 -0
  46. data/app/validators/spina/admin/conferences/conference_date_validator.rb +20 -0
  47. data/app/validators/spina/admin/conferences/email_address_validator.rb +28 -0
  48. data/app/validators/spina/admin/conferences/finish_date_validator.rb +20 -0
  49. data/app/validators/spina/admin/conferences/finish_time_validator.rb +20 -0
  50. data/app/validators/spina/admin/conferences/http_url_validator.rb +28 -0
  51. data/app/views/layouts/spina/admin/conferences/application.html.haml +6 -0
  52. data/app/views/layouts/spina/admin/conferences/conferences.html.haml +17 -0
  53. data/app/views/layouts/spina/admin/conferences/delegates.html.haml +8 -0
  54. data/app/views/layouts/spina/admin/conferences/dietary_requirements.html.haml +8 -0
  55. data/app/views/layouts/spina/admin/conferences/institutions.html.haml +15 -0
  56. data/app/views/layouts/spina/admin/conferences/presentation_attachment_types.html.haml +8 -0
  57. data/app/views/layouts/spina/admin/conferences/presentations.html.haml +8 -0
  58. data/app/views/spina/admin/conferences/application/_conferences.html.haml +12 -0
  59. data/app/views/spina/admin/conferences/application/_delegates.html.haml +11 -0
  60. data/app/views/spina/admin/conferences/application/_dietary_requirements.html.haml +9 -0
  61. data/app/views/spina/admin/conferences/application/_empty_list.html.haml +3 -0
  62. data/app/views/spina/admin/conferences/application/_errors.html.haml +11 -0
  63. data/app/views/spina/admin/conferences/application/_errors.turbo_stream.haml +1 -0
  64. data/app/views/spina/admin/conferences/application/_institutions.html.haml +10 -0
  65. data/app/views/spina/admin/conferences/application/_presentation_attachment_types.html.haml +10 -0
  66. data/app/views/spina/admin/conferences/application/_presentation_types.html.haml +11 -0
  67. data/app/views/spina/admin/conferences/application/_presentations.html.haml +11 -0
  68. data/app/views/spina/admin/conferences/application/_rooms.html.haml +11 -0
  69. data/app/views/spina/admin/conferences/application/_sessions.html.haml +11 -0
  70. data/app/views/spina/admin/conferences/conferences/_conference.html.haml +9 -0
  71. data/app/views/spina/admin/conferences/conferences/_event_fields.html.haml +31 -0
  72. data/app/views/spina/admin/conferences/conferences/_event_row.html.haml +5 -0
  73. data/app/views/spina/admin/conferences/conferences/_form.html.haml +27 -0
  74. data/app/views/spina/admin/conferences/conferences/_form_conference_details.html.haml +27 -0
  75. data/app/views/spina/admin/conferences/conferences/_form_parts.html.haml +8 -0
  76. data/app/views/spina/admin/conferences/conferences/_form_structure.html.haml +19 -0
  77. data/app/views/spina/admin/conferences/conferences/_form_structure_item.html.haml +13 -0
  78. data/app/views/spina/admin/conferences/conferences/edit.html.haml +1 -0
  79. data/app/views/spina/admin/conferences/conferences/index.html.haml +7 -0
  80. data/app/views/spina/admin/conferences/conferences/new.html.haml +1 -0
  81. data/app/views/spina/admin/conferences/delegates/_delegate.html.haml +13 -0
  82. data/app/views/spina/admin/conferences/delegates/_form.html.haml +24 -0
  83. data/app/views/spina/admin/conferences/delegates/_form_delegate_details.html.haml +53 -0
  84. data/app/views/spina/admin/conferences/delegates/edit.html.haml +1 -0
  85. data/app/views/spina/admin/conferences/delegates/index.html.haml +13 -0
  86. data/app/views/spina/admin/conferences/delegates/new.html.haml +1 -0
  87. data/app/views/spina/admin/conferences/dietary_requirements/_dietary_requirement.html.haml +6 -0
  88. data/app/views/spina/admin/conferences/dietary_requirements/_form.html.haml +23 -0
  89. data/app/views/spina/admin/conferences/dietary_requirements/_form_dietary_requirement_details.html.haml +8 -0
  90. data/app/views/spina/admin/conferences/dietary_requirements/edit.html.haml +1 -0
  91. data/app/views/spina/admin/conferences/dietary_requirements/index.html.haml +7 -0
  92. data/app/views/spina/admin/conferences/dietary_requirements/new.html.haml +1 -0
  93. data/app/views/spina/admin/conferences/events/new.js.erb +21 -0
  94. data/app/views/spina/admin/conferences/institutions/_form.html.haml +24 -0
  95. data/app/views/spina/admin/conferences/institutions/_form_institution_details.html.haml +29 -0
  96. data/app/views/spina/admin/conferences/institutions/_institution.html.haml +7 -0
  97. data/app/views/spina/admin/conferences/institutions/edit.html.haml +1 -0
  98. data/app/views/spina/admin/conferences/institutions/index.html.haml +7 -0
  99. data/app/views/spina/admin/conferences/institutions/new.html.haml +1 -0
  100. data/app/views/spina/admin/conferences/presentation_attachment_types/_form.html.haml +23 -0
  101. data/app/views/spina/admin/conferences/presentation_attachment_types/_presentation_attachment_type.html.haml +6 -0
  102. data/app/views/spina/admin/conferences/presentation_attachment_types/edit.html.haml +1 -0
  103. data/app/views/spina/admin/conferences/presentation_attachment_types/index.html.haml +7 -0
  104. data/app/views/spina/admin/conferences/presentation_attachment_types/new.html.haml +1 -0
  105. data/app/views/spina/admin/conferences/presentation_attachments/new.js.erb +21 -0
  106. data/app/views/spina/admin/conferences/presentation_types/_form.html.haml +24 -0
  107. data/app/views/spina/admin/conferences/presentation_types/_form_presentation_type_details.html.haml +16 -0
  108. data/app/views/spina/admin/conferences/presentation_types/_presentation_type.html.haml +8 -0
  109. data/app/views/spina/admin/conferences/presentation_types/edit.html.haml +1 -0
  110. data/app/views/spina/admin/conferences/presentation_types/index.html.haml +7 -0
  111. data/app/views/spina/admin/conferences/presentation_types/new.html.haml +1 -0
  112. data/app/views/spina/admin/conferences/presentations/_attachment_fields.html.haml +18 -0
  113. data/app/views/spina/admin/conferences/presentations/_attachment_row.html.haml +2 -0
  114. data/app/views/spina/admin/conferences/presentations/_form.html.haml +23 -0
  115. data/app/views/spina/admin/conferences/presentations/_form_presentation_details.html.haml +55 -0
  116. data/app/views/spina/admin/conferences/presentations/_presentation.html.haml +11 -0
  117. data/app/views/spina/admin/conferences/presentations/edit.html.haml +1 -0
  118. data/app/views/spina/admin/conferences/presentations/index.html.haml +13 -0
  119. data/app/views/spina/admin/conferences/presentations/new.html.haml +1 -0
  120. data/app/views/spina/admin/conferences/rooms/_form.html.haml +23 -0
  121. data/app/views/spina/admin/conferences/rooms/_form_room_details.html.haml +16 -0
  122. data/app/views/spina/admin/conferences/rooms/_room.html.haml +8 -0
  123. data/app/views/spina/admin/conferences/rooms/edit.html.haml +1 -0
  124. data/app/views/spina/admin/conferences/rooms/index.html.haml +7 -0
  125. data/app/views/spina/admin/conferences/rooms/new.html.haml +1 -0
  126. data/app/views/spina/admin/conferences/sessions/_form.html.haml +23 -0
  127. data/app/views/spina/admin/conferences/sessions/_form_session_details.html.haml +21 -0
  128. data/app/views/spina/admin/conferences/sessions/_session.html.haml +8 -0
  129. data/app/views/spina/admin/conferences/sessions/edit.html.haml +1 -0
  130. data/app/views/spina/admin/conferences/sessions/index.html.haml +7 -0
  131. data/app/views/spina/admin/conferences/sessions/new.html.haml +1 -0
  132. data/app/views/spina/admin/hooks/conferences/_head.html.haml +7 -0
  133. data/app/views/spina/admin/hooks/conferences/_primary_navigation.html.haml +21 -0
  134. data/app/views/spina/admin/hooks/conferences/_settings_secondary_navigation.html.haml +6 -0
  135. data/app/views/spina/admin/parts/admin/conferences/dates/_form.html.haml +2 -0
  136. data/app/views/spina/admin/parts/admin/conferences/email_addresses/_form.html.haml +2 -0
  137. data/app/views/spina/admin/parts/admin/conferences/times/_form.html.haml +2 -0
  138. data/app/views/spina/admin/parts/admin/conferences/urls/_form.html.haml +2 -0
  139. data/config/initializers/assets.rb +13 -0
  140. data/config/locales/en.yml +351 -0
  141. data/config/routes.rb +27 -0
  142. data/db/migrate/20180907141228_create_spina_dates.rb +11 -0
  143. data/db/migrate/20180907141229_create_spina_email_addresses.rb +11 -0
  144. data/db/migrate/20180907141230_create_spina_urls.rb +11 -0
  145. data/db/migrate/20180907141231_create_spina_conferences_institutions.rb +12 -0
  146. data/db/migrate/20180907141232_create_spina_conferences_delegates.rb +15 -0
  147. data/db/migrate/20180907141234_create_spina_conferences_dietary_requirements.rb +11 -0
  148. data/db/migrate/20180907141235_create_spina_conferences_conferences.rb +12 -0
  149. data/db/migrate/20180907141236_create_spina_conferences_presentation_types.rb +13 -0
  150. data/db/migrate/20180907141238_create_join_table_spina_conferences_conference_delegate.rb +7 -0
  151. data/db/migrate/20180907141239_create_join_table_spina_conferences_delegate_presentation.rb +7 -0
  152. data/db/migrate/20180907141240_create_join_table_spina_conferences_delegate_dietary_requirement.rb +7 -0
  153. data/db/migrate/20180907141242_add_type_to_spina_pages.rb +7 -0
  154. data/db/migrate/20180907141243_create_spina_conferences_conference_page_parts.rb +14 -0
  155. data/db/migrate/20180914121905_add_logo_ref_to_spina_conferences_institutions.rb +7 -0
  156. data/db/migrate/20180916135431_create_spina_conferences_rooms.rb +13 -0
  157. data/db/migrate/20180916135432_create_spina_conferences_room_possessions.rb +10 -0
  158. data/db/migrate/20180916135433_create_spina_conferences_room_uses.rb +10 -0
  159. data/db/migrate/20180916135434_create_spina_conferences_presentations.rb +15 -0
  160. data/db/migrate/20181009122503_create_spina_times.rb +11 -0
  161. data/db/migrate/20181009130631_rename_spina_page_parts.rb +10 -0
  162. data/db/migrate/20181012190811_rename_spina_conferences_page_parts.rb +10 -0
  163. data/db/migrate/20181012213049_change_start_time_in_spina_conferences_conferences.rb +15 -0
  164. data/db/migrate/20181012214813_rename_start_time_in_spina_conferences_conferences.rb +7 -0
  165. data/db/migrate/20181017155705_add_dependent_option_to_foreign_keys.rb +36 -0
  166. data/db/migrate/20190408131354_change_spina_resources.rb +56 -0
  167. data/db/migrate/20190622131423_create_spina_conferences_parts.rb +12 -0
  168. data/db/migrate/20190701174807_remove_spina_conference_pages.rb +199 -0
  169. data/db/migrate/20190704135524_add_constraints_to_columns.rb +24 -0
  170. data/db/migrate/20200126034441_create_spina_conferences_presentation_attachment_types.rb +11 -0
  171. data/db/migrate/20200126213718_create_spina_conferences_presentation_attachments.rb +19 -0
  172. data/db/migrate/20200420104603_create_spina_conferences_dietary_requirement_name_translations.rb +19 -0
  173. data/db/migrate/20200420104740_create_spina_conferences_institution_name_and_city_translations.rb +20 -0
  174. data/db/migrate/20200420105057_create_spina_conferences_presentation_title_and_abstract_translations.rb +20 -0
  175. data/db/migrate/20200420105144_create_spina_conferences_presentation_attachment_type_name_translations.rb +20 -0
  176. data/db/migrate/20200420105201_create_spina_conferences_presentation_type_name_translations.rb +19 -0
  177. data/db/migrate/20200420105458_create_spina_conferences_room_building_and_number_translations.rb +20 -0
  178. data/db/migrate/20200420110407_move_attributes_to_translation_tables.rb +161 -0
  179. data/db/migrate/20200420120706_remove_name_from_spina_conferences_dietary_requirements.rb +7 -0
  180. data/db/migrate/20200420120759_remove_name_and_city_from_spina_conferences_institutions.rb +8 -0
  181. data/db/migrate/20200420120946_remove_title_and_abstract_from_spina_conferences_presentations.rb +8 -0
  182. data/db/migrate/20200420121310_remove_name_from_spina_conferences_presentation_attachment_types.rb +7 -0
  183. data/db/migrate/20200420121321_remove_name_from_spina_conferences_presentation_types.rb +7 -0
  184. data/db/migrate/20200420121443_remove_building_and_number_from_spina_conferences_rooms.rb +8 -0
  185. data/db/migrate/20200502133408_create_spina_conferences_conference_name_translations.rb +19 -0
  186. data/db/migrate/20200502183409_set_name_for_spina_conferences_conferences.rb +47 -0
  187. data/db/migrate/20200502183410_remove_institution_from_spina_conferences_conferences.rb +8 -0
  188. data/db/migrate/20200502183719_remove_spina_conferences_room_possessions.rb +60 -0
  189. data/db/migrate/20200503230732_rename_spina_conferences_room_uses.rb +8 -0
  190. data/db/migrate/20200510125131_create_spina_conferences_session_name_translations.rb +19 -0
  191. data/db/migrate/20200802165242_create_spina_conferences_events.rb +13 -0
  192. data/db/migrate/20200802184921_create_spina_conferences_event_name_description_and_location_translations.rb +21 -0
  193. data/db/migrate/20200911161632_update_spina_conferences_parts.rb +23 -0
  194. data/db/migrate/20200911161651_update_spina_parts.rb +37 -0
  195. data/db/migrate/20200911161726_move_presentation_parts.rb +101 -0
  196. data/db/migrate/20200911161739_move_conference_parts.rb +221 -0
  197. data/db/migrate/20201002122517_remove_spina_conferences_conference_page_parts.rb +14 -0
  198. data/db/migrate/20201007125625_add_timestamps_to_spina_conferences_parts.rb +10 -0
  199. data/db/migrate/20210315164409_add_json_attributes_to_spina_conferences_presentations.rb +7 -0
  200. data/db/migrate/20210315164410_add_json_attributes_to_spina_conferences_conferences.rb +7 -0
  201. data/db/migrate/20210315164411_convert_partables_to_json.rb +407 -0
  202. data/db/migrate/20210417102513_add_locale_to_action_text_rich_texts.rb +11 -0
  203. data/db/migrate/20210417102514_move_texts_to_action_text_rich_texts.rb +82 -0
  204. data/lib/spina/admin/conferences/engine.rb +31 -0
  205. data/lib/spina/admin/conferences/migration/renaming.rb +79 -0
  206. data/lib/spina/admin/conferences/railtie.rb +34 -0
  207. data/lib/spina/admin/conferences/version.rb +10 -0
  208. data/lib/spina/admin/conferences.rb +23 -0
  209. data/lib/tasks/spina/admin/conferences_tasks.rake +14 -0
  210. metadata +603 -0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveNameFromSpinaConferencesDietaryRequirements < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_column :spina_conferences_dietary_requirements, :name, :string
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveNameAndCityFromSpinaConferencesInstitutions < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_column :spina_conferences_institutions, :name, :string
6
+ remove_column :spina_conferences_institutions, :city, :string
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveTitleAndAbstractFromSpinaConferencesPresentations < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_column :spina_conferences_presentations, :title, :string
6
+ remove_column :spina_conferences_presentations, :abstract, :text
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveNameFromSpinaConferencesPresentationAttachmentTypes < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_column :spina_conferences_presentation_attachment_types, :name, :string
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveNameFromSpinaConferencesPresentationTypes < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_column :spina_conferences_presentation_types, :name, :string
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveBuildingAndNumberFromSpinaConferencesRooms < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_column :spina_conferences_rooms, :building, :string
6
+ remove_column :spina_conferences_rooms, :number, :string
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSpinaConferencesConferenceNameTranslations < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ create_table :spina_conferences_conference_translations do |t|
6
+ # Translated attribute(s)
7
+ t.string :name
8
+
9
+ t.string :locale, null: false
10
+ t.references :spina_conferences_conference, null: false, foreign_key: true, index: false
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_index :spina_conferences_conference_translations, :locale, name: :index_b1ed8f417185e6e49c50c1f2119c86824e3e3a22
16
+ add_index :spina_conferences_conference_translations, %i[spina_conferences_conference_id locale],
17
+ name: :index_0022b227e0816c00e61de831f2d638f1b305868e, unique: true
18
+ end
19
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SetNameForSpinaConferencesConferences < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def up
5
+ add_translations
6
+ end
7
+
8
+ def down
9
+ set_institution_from_room
10
+ delete_translations
11
+ end
12
+
13
+ private
14
+
15
+ def set_institution_from_room
16
+ update <<-SQL.squish, 'Set institution from room'
17
+ UPDATE spina_conferences_conferences SET (institution_id) = (
18
+ SELECT spina_conferences_rooms.institution_id
19
+ FROM spina_conferences_presentation_types
20
+ INNER JOIN spina_conferences_room_uses ON spina_conferences_presentation_types.id = presentation_type_id
21
+ INNER JOIN spina_conferences_room_possessions ON spina_conferences_room_possessions.id = room_possession_id
22
+ INNER JOIN spina_conferences_rooms ON spina_conferences_rooms.id = room_id
23
+ WHERE spina_conferences_conferences.id = spina_conferences_presentation_types.conference_id
24
+ ORDER BY room_id
25
+ LIMIT 1
26
+ )
27
+ SQL
28
+ end
29
+
30
+ def delete_translations
31
+ delete <<-SQL.squish, 'Delete translations'
32
+ DELETE FROM spina_conferences_conference_translations
33
+ SQL
34
+ end
35
+
36
+ def add_translations
37
+ binds = [ActiveRecord::Relation::QueryAttribute.new('locale', I18n.default_locale, ActiveRecord::Type::String.new)]
38
+ insert <<-SQL.squish, 'Add translations', nil, nil, nil, binds
39
+ INSERT INTO spina_conferences_conference_translations (locale, spina_conferences_conference_id, name, created_at, updated_at)
40
+ SELECT $1, spina_conferences_conferences.id,
41
+ concat_ws(' ', spina_conferences_institution_translations.name, date_part('year', lower(dates))),
42
+ spina_conferences_conferences.created_at, spina_conferences_conferences.updated_at
43
+ FROM spina_conferences_conferences
44
+ INNER JOIN spina_conferences_institution_translations ON spina_conferences_institution_id = institution_id AND locale = $1
45
+ SQL
46
+ end
47
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveInstitutionFromSpinaConferencesConferences < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ remove_reference :spina_conferences_conferences, :institution,
6
+ foreign_key: { to_table: :spina_conferences_institutions }
7
+ end
8
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveSpinaConferencesRoomPossessions < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def up
5
+ add_reference :spina_conferences_room_uses, :room, foreign_key: { to_table: :spina_conferences_rooms }
6
+ add_timestamps :spina_conferences_room_uses, null: true
7
+ update_room_uses_with_room_id
8
+ remove_reference :spina_conferences_room_uses, :room_possession
9
+ drop_table :spina_conferences_room_possessions
10
+ change_column_null :spina_conferences_room_uses, :created_at, false
11
+ change_column_null :spina_conferences_room_uses, :updated_at, false
12
+ end
13
+
14
+ def down
15
+ remove_timestamps :spina_conferences_room_uses
16
+ create_room_possessions_table
17
+ add_reference :spina_conferences_room_uses, :room_possession, foreign_key: { to_table: :spina_conferences_room_possessions }
18
+ insert_room_possessions
19
+ update_room_uses_with_room_possession_id
20
+ remove_reference :spina_conferences_room_uses, :room
21
+ end
22
+
23
+ private
24
+
25
+ def create_room_possessions_table
26
+ create_table 'spina_conferences_room_possessions' do |t| # rubocop:disable Rails/CreateTableWithTimestamps
27
+ t.references :room, foreign_key: { to_table: :spina_conferences_rooms }
28
+ t.references :conference, foreign_key: { to_table: :spina_conferences_conferences }
29
+ end
30
+ end
31
+
32
+ def update_room_uses_with_room_id
33
+ update <<-SQL.squish, 'Update room uses'
34
+ UPDATE spina_conferences_room_uses
35
+ SET (room_id, created_at, updated_at) = (spina_conferences_room_possessions.room_id, current_timestamp, current_timestamp)
36
+ FROM spina_conferences_room_possessions
37
+ WHERE spina_conferences_room_possessions.id = spina_conferences_room_uses.room_possession_id
38
+ SQL
39
+ end
40
+
41
+ def insert_room_possessions
42
+ insert <<-SQL.squish, 'Add room possessions'
43
+ INSERT INTO spina_conferences_room_possessions (room_id, conference_id)
44
+ SELECT DISTINCT spina_conferences_room_uses.room_id, spina_conferences_presentation_types.conference_id
45
+ FROM spina_conferences_room_uses
46
+ INNER JOIN spina_conferences_presentation_types
47
+ ON spina_conferences_presentation_types.id = spina_conferences_room_uses.presentation_type_id
48
+ SQL
49
+ end
50
+
51
+ def update_room_uses_with_room_possession_id
52
+ update <<-SQL.squish, 'Add references to room uses'
53
+ UPDATE spina_conferences_room_uses SET room_possession_id = spina_conferences_room_possessions.id
54
+ FROM spina_conferences_room_possessions
55
+ INNER JOIN spina_conferences_presentation_types USING (conference_id)
56
+ WHERE spina_conferences_room_possessions.room_id = spina_conferences_room_uses.room_id
57
+ AND spina_conferences_room_possessions.conference_id = spina_conferences_presentation_types.conference_id
58
+ SQL
59
+ end
60
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameSpinaConferencesRoomUses < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ rename_table :spina_conferences_room_uses, :spina_conferences_sessions
6
+ rename_column :spina_conferences_presentations, :room_use_id, :session_id
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSpinaConferencesSessionNameTranslations < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ create_table :spina_conferences_session_translations do |t|
6
+ # Translated attribute(s)
7
+ t.string :name
8
+
9
+ t.string :locale, null: false
10
+ t.references :spina_conferences_session, null: false, foreign_key: true, index: false
11
+
12
+ t.timestamps null: false
13
+ end
14
+
15
+ add_index :spina_conferences_session_translations, :locale, name: :index_spina_conferences_session_translations_on_locale
16
+ add_index :spina_conferences_session_translations, %i[spina_conferences_session_id locale],
17
+ name: :index_7843e68c4bf93df06700ea7f68c4765ef004169a, unique: true
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSpinaConferencesEvents < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def change
5
+ create_table :spina_conferences_events do |t|
6
+ t.datetime :start_datetime
7
+ t.datetime :finish_datetime
8
+ t.references :conference, foreign_key: { to_table: :spina_conferences_conferences, on_delete: :cascade }
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateSpinaConferencesEventNameDescriptionAndLocationTranslations < ActiveRecord::Migration[6.0] # rubocop:disable Style/Documentation
4
+ def change # rubocop:disable Metrics/MethodLength
5
+ create_table :spina_conferences_event_translations do |t|
6
+ # Translated attribute(s)
7
+ t.string :name
8
+ t.text :description
9
+ t.string :location
10
+
11
+ t.string :locale, null: false
12
+ t.references :spina_conferences_event, null: false, foreign_key: true, index: false
13
+
14
+ t.timestamps null: false
15
+ end
16
+
17
+ add_index :spina_conferences_event_translations, :locale, name: :index_spina_conferences_event_translations_on_locale
18
+ add_index :spina_conferences_event_translations, %i[spina_conferences_event_id locale],
19
+ name: :index_a26428290c005036f14c7c9cab5f5a91289e46e0, unique: true
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UpdateSpinaConferencesParts < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def up
5
+ update <<-SQL.squish, 'Add namespacing to class names'
6
+ UPDATE spina_conferences_parts
7
+ SET
8
+ partable_type = replace(partable_type, 'Spina::Conferences', 'Spina::Admin::Conferences'),
9
+ pageable_type = replace(pageable_type, 'Spina::Conferences', 'Spina::Admin::Conferences')
10
+ WHERE starts_with(partable_type, 'Spina::Conferences') OR starts_with(pageable_type, 'Spina::Conferences')
11
+ SQL
12
+ end
13
+
14
+ def down
15
+ update <<-SQL.squish, 'Remove namespacing from class names'
16
+ UPDATE spina_conferences_parts
17
+ SET
18
+ partable_type = replace(partable_type, 'Spina::Admin::Conferences', 'Spina::Conferences'),
19
+ pageable_type = replace(pageable_type, 'Spina::Admin::Conferences', 'Spina::Conferences')
20
+ WHERE starts_with(partable_type, 'Spina::Admin::Conferences') OR starts_with(pageable_type, 'Spina::Admin::Conferences')
21
+ SQL
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UpdateSpinaParts < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def up
5
+ update <<-SQL.squish, 'Add namespacing to class names for page parts'
6
+ UPDATE spina_page_parts SET page_partable_type = replace(page_partable_type, 'Spina::Conferences', 'Spina::Admin::Conferences')
7
+ WHERE starts_with(page_partable_type, 'Spina::Conferences')
8
+ SQL
9
+ update <<-SQL.squish, 'Add namespacing to class names for structure parts'
10
+ UPDATE spina_structure_parts
11
+ SET structure_partable_type = replace(structure_partable_type, 'Spina::Conferences', 'Spina::Admin::Conferences')
12
+ WHERE starts_with(structure_partable_type, 'Spina::Conferences')
13
+ SQL
14
+ update <<-SQL.squish, 'Add namespacing to class names for layout parts'
15
+ UPDATE spina_layout_parts
16
+ SET layout_partable_type = replace(layout_partable_type, 'Spina::Conferences', 'Spina::Admin::Conferences')
17
+ WHERE starts_with(layout_partable_type, 'Spina::Conferences')
18
+ SQL
19
+ end
20
+
21
+ def down
22
+ update <<-SQL.squish, 'Remove namespacing from class names for page parts'
23
+ UPDATE spina_page_parts SET page_partable_type = replace(page_partable_type, 'Spina::Admin::Conferences', 'Spina::Conferences')
24
+ WHERE starts_with(page_partable_type, 'Spina::Admin::Conferences')
25
+ SQL
26
+ update <<-SQL.squish, 'Remove namespacing from class names for structure parts'
27
+ UPDATE spina_structure_parts
28
+ SET structure_partable_type = replace(structure_partable_type, 'Spina::Admin::Conferences', 'Spina::Conferences')
29
+ WHERE starts_with(structure_partable_type, 'Spina::Admin::Conferences')
30
+ SQL
31
+ update <<-SQL.squish, 'Remove namespacing from class names for layout parts'
32
+ UPDATE spina_layout_parts
33
+ SET layout_partable_type = replace(layout_partable_type, 'Spina::Admin::Conferences', 'Spina::Conferences')
34
+ WHERE starts_with(layout_partable_type, 'Spina::Admin::Conferences')
35
+ SQL
36
+ end
37
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MovePresentationParts < ActiveRecord::Migration[6.0] # :nodoc:
4
+ def up
5
+ create_presentation_attachment_types
6
+ create_presentation_attachments
7
+ delete_presentation_parts
8
+ end
9
+
10
+ def down
11
+ create_parts
12
+ delete_presentation_attachments
13
+ delete_presentation_attachment_type_translations
14
+ delete_presentation_attachment_types
15
+ end
16
+
17
+ private
18
+
19
+ def create_presentation_attachment_types
20
+ binds = [ActiveRecord::Relation::QueryAttribute.new('locale', I18n.default_locale, ActiveRecord::Type::String.new)]
21
+ insert <<-SQL.squish, 'Create presentation attachment types', nil, nil, nil, binds
22
+ WITH attachment_type_names AS (
23
+ SELECT DISTINCT ON (title) title, id
24
+ FROM spina_conferences_parts
25
+ WHERE pageable_type = 'Spina::Admin::Conferences::Presentation' AND partable_type = 'Spina::Attachment'
26
+ ORDER BY title
27
+ ), attachment_types AS (
28
+ INSERT INTO spina_conferences_presentation_attachment_types (created_at, updated_at)
29
+ SELECT current_timestamp, current_timestamp FROM attachment_type_names
30
+ RETURNING id
31
+ )
32
+ INSERT INTO spina_conferences_presentation_attachment_type_translations
33
+ (name, locale, spina_conferences_presentation_attachment_type_id, created_at, updated_at)
34
+ SELECT title, $1, id, current_timestamp, current_timestamp
35
+ FROM (
36
+ SELECT title, row_number() over (ORDER BY id) AS index FROM attachment_type_names
37
+ ) AS attachment_type_names_with_indices
38
+ INNER JOIN (
39
+ SELECT id, row_number() over (ORDER BY id) AS index FROM attachment_types
40
+ ) AS attachment_types_with_indices USING (index)
41
+ SQL
42
+ end
43
+
44
+ def create_presentation_attachments
45
+ binds = [ActiveRecord::Relation::QueryAttribute.new('locale', I18n.default_locale, ActiveRecord::Type::String.new)]
46
+ insert <<-SQL.squish, 'Create presentation attachments', nil, nil, nil, binds
47
+ INSERT INTO spina_conferences_presentation_attachments (presentation_id, attachment_type_id, attachment_id, created_at, updated_at)
48
+ SELECT pageable_id, spina_conferences_presentation_attachment_type_id, partable_id, current_timestamp, current_timestamp
49
+ FROM spina_conferences_parts
50
+ INNER JOIN spina_conferences_presentation_attachment_type_translations
51
+ ON spina_conferences_parts.name = replace(lower(spina_conferences_presentation_attachment_type_translations.name),'\W', '_')
52
+ AND locale = $1
53
+ WHERE pageable_type = 'Spina::Admin::Conferences::Presentation'
54
+ AND partable_type = 'Spina::Attachment'
55
+ SQL
56
+ end
57
+
58
+ def delete_presentation_parts
59
+ delete <<-SQL.squish, 'Delete presentation parts'
60
+ DELETE FROM spina_conferences_parts
61
+ WHERE pageable_type = 'Spina::Admin::Conferences::Presentation' AND partable_type = 'Spina::Attachment'
62
+ SQL
63
+ end
64
+
65
+ def create_parts
66
+ insert <<-SQL.squish, 'Create parts'
67
+ INSERT INTO spina_conferences_parts (title, name, partable_type, partable_id, pageable_type, pageable_id)
68
+ SELECT name, replace(lower(name),'\W', '_'), 'Spina::Admin::Conferences::Presentation', presentation_id, 'Spina::Attachment',
69
+ attachment_id
70
+ FROM spina_conferences_presentation_attachments
71
+ INNER JOIN spina_conferences_presentation_attachment_type_translations
72
+ ON attachment_type_id = spina_conferences_presentation_attachment_type_id
73
+ SQL
74
+ end
75
+
76
+ def delete_presentation_attachments
77
+ delete <<-SQL.squish, 'Delete presentation attachments'
78
+ DELETE FROM spina_conferences_presentation_attachments
79
+ USING spina_conferences_parts
80
+ WHERE title = name AND pageable_id = presentation_id
81
+ SQL
82
+ end
83
+
84
+ def delete_presentation_attachment_type_translations
85
+ delete <<-SQL.squish, 'Delete presentation attachment type translations'
86
+ DELETE FROM spina_conferences_presentation_attachment_type_translations
87
+ USING spina_conferences_presentation_attachments, spina_conferences_parts
88
+ WHERE attachment_type_id != spina_conferences_presentation_attachment_type_id
89
+ AND spina_conferences_presentation_attachment_type_translations.name = title
90
+ SQL
91
+ end
92
+
93
+ def delete_presentation_attachment_types
94
+ delete <<-SQL.squish, 'Delete presentation attachment types'
95
+ DELETE FROM spina_conferences_presentation_attachment_types
96
+ USING spina_conferences_presentation_attachments, spina_conferences_presentation_attachment_type_translations
97
+ WHERE attachment_type_id != spina_conferences_presentation_attachments.id
98
+ AND spina_conferences_presentation_attachment_type_id != spina_conferences_presentation_attachments.id
99
+ SQL
100
+ end
101
+ end
@@ -0,0 +1,221 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MoveConferenceParts < ActiveRecord::Migration[6.0] # rubocop:disable Metrics/ClassLength, Style/Documentation
4
+ def up
5
+ insert <<-SQL.squish, 'Create events', nil, nil, nil
6
+ WITH event_structure_items_with_parts AS (
7
+ SELECT DISTINCT
8
+ spina_structure_items.id AS structure_item_id,
9
+ pageable_id AS conference_id,
10
+ structure_id,
11
+ start_times.content AS start_time,
12
+ names.content AS title,
13
+ locations.content AS location,
14
+ descriptions.content AS description,
15
+ names.locale AS locale,
16
+ start_times.id AS start_time_id,
17
+ names.translation_id AS title_translation_id,
18
+ locations.translation_id AS location_translation_id,
19
+ descriptions.translation_id AS description_translation_id
20
+ FROM spina_conferences_parts
21
+ INNER JOIN spina_structure_items ON partable_id = structure_id AND partable_type = 'Spina::Structure'
22
+ LEFT JOIN (
23
+ SELECT spina_conferences_time_parts.id AS id, spina_conferences_time_parts.content AS content, structure_item_id
24
+ FROM spina_structure_parts
25
+ INNER JOIN spina_conferences_time_parts
26
+ ON structure_partable_id = spina_conferences_time_parts.id
27
+ AND structure_partable_type = 'Spina::Admin::Conferences::TimePart'
28
+ AND spina_structure_parts.name = 'start_time'
29
+ ) AS start_times ON start_times.structure_item_id = spina_structure_items.id
30
+ LEFT JOIN (
31
+ SELECT
32
+ spina_line_translations.id AS translation_id, content, locale, structure_item_id
33
+ FROM spina_structure_parts
34
+ INNER JOIN spina_lines
35
+ ON structure_partable_id = spina_lines.id
36
+ AND structure_partable_type = 'Spina::Line'
37
+ AND spina_structure_parts.name = 'name'
38
+ INNER JOIN spina_line_translations
39
+ ON spina_line_id = spina_lines.id
40
+ WHERE content IS NOT NULL
41
+ ) AS names ON names.structure_item_id = spina_structure_items.id
42
+ LEFT JOIN (
43
+ SELECT spina_line_translations.id AS translation_id, content, locale, structure_item_id
44
+ FROM spina_structure_parts
45
+ INNER JOIN spina_lines
46
+ ON structure_partable_id = spina_lines.id
47
+ AND structure_partable_type = 'Spina::Line'
48
+ AND spina_structure_parts.name = 'location'
49
+ INNER JOIN spina_line_translations
50
+ ON spina_line_id = spina_lines.id
51
+ WHERE content IS NOT NULL
52
+ ) AS locations ON locations.structure_item_id = spina_structure_items.id
53
+ LEFT JOIN (
54
+ SELECT spina_text_translations.id AS translation_id, content, locale, structure_item_id
55
+ FROM spina_structure_parts
56
+ INNER JOIN spina_texts
57
+ ON structure_partable_id = spina_texts.id
58
+ AND structure_partable_type = 'Spina::Text'
59
+ AND spina_structure_parts.name = 'description'
60
+ INNER JOIN spina_text_translations
61
+ ON spina_text_id = spina_texts.id
62
+ WHERE content IS NOT NULL
63
+ ) AS descriptions ON descriptions.structure_item_id = spina_structure_items.id
64
+ WHERE pageable_type = 'Spina::Admin::Conferences::Conference'
65
+ AND spina_conferences_parts.name IN ('meetings', 'socials')
66
+ AND names.locale = locations.locale
67
+ AND locations.locale = descriptions.locale
68
+ ), untranslated_event_structure_items_with_parts AS (
69
+ SELECT DISTINCT ON (structure_item_id) structure_item_id, start_time, conference_id
70
+ FROM event_structure_items_with_parts
71
+ ), events AS (
72
+ INSERT INTO spina_conferences_events (start_datetime, finish_datetime, conference_id, created_at, updated_at)
73
+ SELECT start_time, start_time + interval '1 hour', conference_id, current_timestamp, current_timestamp
74
+ FROM untranslated_event_structure_items_with_parts
75
+ RETURNING id
76
+ ), event_translations AS (
77
+ INSERT INTO spina_conferences_event_translations
78
+ (name, description, location, locale, spina_conferences_event_id, created_at, updated_at)
79
+ SELECT DISTINCT ON (event_structure_items_with_parts_and_indices.structure_item_id, locale)
80
+ title, description, location, locale, structure_item_events.id, current_timestamp, current_timestamp
81
+ FROM (
82
+ SELECT structure_item_id, row_number() OVER (ORDER BY structure_item_id) AS index
83
+ FROM untranslated_event_structure_items_with_parts
84
+ ) AS event_structure_items_with_parts_and_indices
85
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM events) AS structure_item_events
86
+ ON structure_item_events.index = event_structure_items_with_parts_and_indices.index
87
+ INNER JOIN event_structure_items_with_parts
88
+ ON event_structure_items_with_parts.structure_item_id = event_structure_items_with_parts_and_indices.structure_item_id
89
+ ), line_translations AS (
90
+ DELETE FROM spina_line_translations
91
+ USING event_structure_items_with_parts
92
+ WHERE id IN (title_translation_id, location_translation_id)
93
+ RETURNING spina_line_id
94
+ ), lines AS (
95
+ DELETE FROM spina_lines USING line_translations WHERE spina_line_id = id RETURNING id
96
+ ), text_translations AS (
97
+ DELETE FROM spina_text_translations
98
+ USING event_structure_items_with_parts
99
+ WHERE id = description_translation_id
100
+ RETURNING spina_text_id
101
+ ), texts AS (
102
+ DELETE FROM spina_texts USING text_translations WHERE spina_text_id = id RETURNING id
103
+ ), times AS (
104
+ DELETE FROM spina_conferences_time_parts USING event_structure_items_with_parts WHERE id = start_time_id RETURNING id
105
+ ), structure_parts AS (
106
+ DELETE FROM spina_structure_parts
107
+ USING lines, texts, times
108
+ WHERE
109
+ (structure_partable_id = lines.id AND structure_partable_type = 'Spina::Line')
110
+ OR (structure_partable_id = texts.id AND structure_partable_type = 'Spina::Text')
111
+ OR (structure_partable_id = times.id AND structure_partable_type = 'Spina::Admin::Conferences::TimePart')
112
+ RETURNING structure_item_id
113
+ ), structure_items AS (
114
+ DELETE FROM spina_structure_items USING structure_parts WHERE structure_item_id = spina_structure_items.id RETURNING structure_id
115
+ ), structures AS (
116
+ DELETE FROM spina_structures USING structure_items WHERE structure_id = spina_structures.id
117
+ )
118
+ DELETE FROM spina_conferences_parts
119
+ USING event_structure_items_with_parts WHERE partable_id = structure_id AND partable_type = 'Spina::Structure'
120
+ SQL
121
+ end
122
+
123
+ def down
124
+ binds = [ActiveRecord::Relation::QueryAttribute.new('locale', I18n.default_locale, ActiveRecord::Type::String.new)]
125
+ delete <<-SQL.squish, 'Create events', binds
126
+ WITH
127
+ conferences AS (SELECT DISTINCT ON (conference_id) conference_id AS id FROM spina_conferences_events),
128
+ structures AS (
129
+ INSERT INTO spina_structures (created_at, updated_at) SELECT current_timestamp, current_timestamp FROM conferences RETURNING id
130
+ ), parts AS (
131
+ INSERT INTO spina_conferences_parts (title, name, partable_type, partable_id, pageable_type, pageable_id)
132
+ SELECT
133
+ 'Events', 'events', 'Spina::Structure', structures_with_indices.id, 'Spina::Admin::Conferences::Conference',
134
+ conferences_with_indices.id
135
+ FROM (SELECT id, row_number() OVER (ORDER BY id) AS index FROM structures) AS structures_with_indices
136
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM conferences) AS conferences_with_indices USING (index)
137
+ ), events AS (
138
+ SELECT spina_conferences_events.id AS id, name, description, location, locale, start_datetime, conference_id
139
+ FROM spina_conferences_events
140
+ INNER JOIN spina_conferences_event_translations ON spina_conferences_event_id = spina_conferences_events.id AND locale = $1
141
+ ), structure_items AS (
142
+ INSERT INTO spina_structure_items (structure_id, position, created_at, updated_at)
143
+ SELECT structures_with_indices.id, events_with_indices.index, current_timestamp, current_timestamp
144
+ FROM (SELECT conference_id, row_number() over (ORDER BY id) AS index FROM events) AS events_with_indices
145
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM conferences) AS conferences_with_indices
146
+ ON conference_id = conferences_with_indices.id
147
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM structures) AS structures_with_indices
148
+ ON conferences_with_indices.index = structures_with_indices.index
149
+ RETURNING id
150
+ ), line_parts AS (
151
+ SELECT id AS event_id, name AS content, 'Spina::Line' AS type, 'Title' AS title FROM events
152
+ UNION ALL SELECT id, location, 'Spina::Line', 'Location' FROM events
153
+ ORDER BY event_id, title
154
+ ), text_parts AS (
155
+ SELECT id AS event_id, name AS content, 'Spina::Text' AS type, 'Description' AS title FROM events ORDER BY event_id, title
156
+ ), datetime_parts AS (
157
+ SELECT id AS event_id, start_datetime AS content, 'Spina::Admin::Conferences::TimePart' AS type, 'Start time' AS title
158
+ FROM events
159
+ ORDER BY event_id, title
160
+ ), lines AS (
161
+ INSERT INTO spina_lines (created_at, updated_at) SELECT current_timestamp, current_timestamp FROM line_parts RETURNING id
162
+ ), line_translations AS (
163
+ INSERT INTO spina_line_translations (spina_line_id, locale, content, created_at, updated_at)
164
+ SELECT lines_with_indices.id, $1, content, current_timestamp, current_timestamp
165
+ FROM (SELECT content, type, row_number() OVER (ORDER BY event_id, title) AS index FROM line_parts) AS line_parts_with_indices
166
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM lines) AS lines_with_indices USING (index)
167
+ RETURNING id
168
+ ), texts AS (
169
+ INSERT INTO spina_texts (created_at, updated_at)
170
+ SELECT current_timestamp, current_timestamp FROM text_parts ORDER BY event_id, title
171
+ RETURNING id
172
+ ), text_translations AS (
173
+ INSERT INTO spina_text_translations (spina_text_id, locale, content, created_at, updated_at)
174
+ SELECT texts_with_indices.id, $1, content, current_timestamp, current_timestamp
175
+ FROM (SELECT content, type, row_number() OVER (ORDER BY event_id, title) AS index FROM text_parts) AS text_parts_with_indices
176
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM lines) AS texts_with_indices USING (index)
177
+ RETURNING id
178
+ ), times AS (
179
+ INSERT INTO spina_conferences_time_parts (content, created_at, updated_at)
180
+ SELECT content, current_timestamp, current_timestamp FROM datetime_parts
181
+ RETURNING id
182
+ ), structure_parts_to_insert AS (
183
+ SELECT partable_id, type, title, event_id
184
+ FROM (SELECT id as partable_id, row_number() OVER (ORDER BY id) AS index FROM lines) AS lines_with_indices
185
+ INNER JOIN (
186
+ SELECT type, title, event_id, row_number() OVER (ORDER BY event_id, title) AS index FROM line_parts WHERE type = 'Spina::Line'
187
+ ) AS line_parts_with_indices USING (index)
188
+ UNION ALL
189
+ SELECT partable_id, type, title, event_id
190
+ FROM (SELECT id as partable_id, row_number() OVER (ORDER BY id) AS index FROM texts) AS texts_with_indices
191
+ INNER JOIN (
192
+ SELECT type, title, event_id, row_number() OVER (ORDER BY event_id, title) AS index
193
+ FROM text_parts
194
+ WHERE type = 'Spina::Text'
195
+ ) AS text_parts_with_indices USING (index)
196
+ UNION ALL
197
+ SELECT partable_id, type, title, event_id
198
+ FROM (SELECT id as partable_id, row_number() OVER (ORDER BY id) AS index FROM times) AS times_with_indices
199
+ INNER JOIN (
200
+ SELECT type, title, event_id, row_number() OVER (ORDER BY event_id, title) AS index
201
+ FROM datetime_parts
202
+ WHERE type = 'Spina::Text'
203
+ ) AS time_parts_with_indices USING (index)
204
+ ), structure_parts AS (
205
+ INSERT INTO spina_structure_parts
206
+ (structure_item_id, structure_partable_id, structure_partable_type, name, title, created_at, updated_at)
207
+ SELECT
208
+ structure_items_with_indices.id, partable_id, type, replace(lower(title), '\W', '_'), title, current_timestamp,
209
+ current_timestamp
210
+ FROM structure_parts_to_insert
211
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM events) AS events_with_indices
212
+ ON event_id = events_with_indices.id
213
+ INNER JOIN (SELECT id, row_number() OVER (ORDER BY id) AS index FROM structure_items) AS structure_items_with_indices
214
+ USING (index)
215
+ ), deleted_events AS (
216
+ DELETE FROM spina_conferences_events RETURNING id
217
+ )
218
+ DELETE FROM spina_conferences_event_translations USING deleted_events WHERE spina_conferences_event_id = deleted_events.id
219
+ SQL
220
+ end
221
+ end