panda-cms 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -2
  3. data/Rakefile +2 -0
  4. data/app/components/panda/cms/admin/statistics_component.rb +1 -2
  5. data/app/components/panda/cms/admin/user_activity_component.html.erb +3 -1
  6. data/app/components/panda/cms/admin/user_activity_component.rb +3 -5
  7. data/app/components/panda/cms/admin/user_display_component.html.erb +1 -1
  8. data/app/components/panda/cms/admin/user_display_component.rb +2 -2
  9. data/app/components/panda/cms/code_component.rb +8 -4
  10. data/app/components/panda/cms/menu_component.rb +7 -6
  11. data/app/components/panda/cms/page_menu_component.rb +15 -17
  12. data/app/components/panda/cms/rich_text_component.rb +10 -11
  13. data/app/components/panda/cms/text_component.rb +6 -7
  14. data/app/controllers/panda/cms/admin/base_controller.rb +18 -0
  15. data/app/controllers/panda/cms/admin/block_contents_controller.rb +1 -2
  16. data/app/controllers/panda/cms/admin/dashboard_controller.rb +14 -9
  17. data/app/controllers/panda/cms/admin/files_controller.rb +1 -3
  18. data/app/controllers/panda/cms/admin/forms_controller.rb +3 -6
  19. data/app/controllers/panda/cms/admin/menus_controller.rb +2 -3
  20. data/app/controllers/panda/cms/admin/pages_controller.rb +9 -8
  21. data/app/controllers/panda/cms/admin/posts_controller.rb +9 -11
  22. data/app/controllers/panda/cms/admin/settings/bulk_editor_controller.rb +32 -25
  23. data/app/controllers/panda/cms/admin/settings_controller.rb +13 -10
  24. data/app/controllers/panda/cms/application_controller.rb +19 -6
  25. data/app/controllers/panda/cms/errors_controller.rb +5 -2
  26. data/app/controllers/panda/cms/form_submissions_controller.rb +2 -0
  27. data/app/controllers/panda/cms/pages_controller.rb +34 -31
  28. data/app/controllers/panda/cms/posts_controller.rb +2 -0
  29. data/app/helpers/panda/cms/admin/files_helper.rb +5 -1
  30. data/app/helpers/panda/cms/admin/pages_helper.rb +5 -1
  31. data/app/helpers/panda/cms/application_helper.rb +3 -3
  32. data/app/helpers/panda/cms/asset_helper.rb +195 -0
  33. data/app/helpers/panda/cms/pages_helper.rb +2 -0
  34. data/app/helpers/panda/cms/posts_helper.rb +2 -0
  35. data/app/helpers/panda/cms/theme_helper.rb +2 -0
  36. data/app/javascript/panda/cms/application_panda_cms.js +2 -34
  37. data/app/javascript/panda/cms/controllers/editor_form_controller.js +59 -6
  38. data/app/javascript/panda/cms/controllers/index.js +8 -24
  39. data/app/javascript/panda/cms/stimulus-loading.js +39 -0
  40. data/app/javascript/panda_cms/stimulus-loading.js +39 -0
  41. data/app/jobs/panda/cms/application_job.rb +2 -0
  42. data/app/jobs/panda/cms/record_visit_job.rb +2 -0
  43. data/app/mailers/panda/cms/application_mailer.rb +2 -0
  44. data/app/mailers/panda/cms/form_mailer.rb +3 -1
  45. data/app/models/panda/cms/application_record.rb +2 -0
  46. data/app/models/panda/cms/block.rb +4 -1
  47. data/app/models/panda/cms/block_content.rb +3 -1
  48. data/app/models/panda/cms/current.rb +5 -12
  49. data/app/models/panda/cms/form.rb +2 -0
  50. data/app/models/panda/cms/form_submission.rb +2 -0
  51. data/app/models/panda/cms/menu.rb +12 -9
  52. data/app/models/panda/cms/menu_item.rb +10 -6
  53. data/app/models/panda/cms/page.rb +14 -12
  54. data/app/models/panda/cms/post.rb +12 -8
  55. data/app/models/panda/cms/redirect.rb +6 -3
  56. data/app/models/panda/cms/template.rb +12 -7
  57. data/app/models/panda/cms/visit.rb +3 -1
  58. data/app/models/panda/social/instagram_post.rb +2 -0
  59. data/app/services/panda/social/instagram_feed_service.rb +3 -1
  60. data/app/views/layouts/different_page.html.erb +6 -0
  61. data/app/views/layouts/homepage.html.erb +37 -0
  62. data/app/views/layouts/page.html.erb +18 -0
  63. data/app/views/layouts/panda/cms/application.html.erb +2 -1
  64. data/app/views/panda/cms/admin/dashboard/show.html.erb +2 -2
  65. data/app/views/panda/cms/admin/files/index.html.erb +1 -1
  66. data/app/views/panda/cms/admin/forms/index.html.erb +4 -4
  67. data/app/views/panda/cms/admin/forms/new.html.erb +2 -2
  68. data/app/views/panda/cms/admin/forms/show.html.erb +1 -1
  69. data/app/views/panda/cms/admin/menus/index.html.erb +4 -4
  70. data/app/views/panda/cms/admin/pages/edit.html.erb +6 -6
  71. data/app/views/panda/cms/admin/pages/index.html.erb +5 -5
  72. data/app/views/panda/cms/admin/pages/new.html.erb +16 -10
  73. data/app/views/panda/cms/admin/posts/_form.html.erb +1 -1
  74. data/app/views/panda/cms/admin/posts/edit.html.erb +2 -2
  75. data/app/views/panda/cms/admin/posts/index.html.erb +5 -5
  76. data/app/views/panda/cms/admin/posts/new.html.erb +1 -1
  77. data/app/views/panda/cms/admin/settings/bulk_editor/new.html.erb +1 -1
  78. data/app/views/panda/cms/admin/settings/index.html.erb +4 -4
  79. data/app/views/panda/cms/admin/shared/_breadcrumbs.html.erb +3 -3
  80. data/app/views/panda/cms/admin/shared/_flash.html.erb +1 -1
  81. data/app/views/panda/cms/admin/shared/_sidebar.html.erb +8 -8
  82. data/app/views/panda/cms/shared/_header.html.erb +10 -2
  83. data/app/views/panda/cms/shared/_importmap.html.erb +1 -1
  84. data/app/views/shared/_footer.html.erb +3 -0
  85. data/app/views/shared/_header.html.erb +11 -0
  86. data/config/importmap.rb +2 -0
  87. data/config/initializers/inflections.rb +2 -0
  88. data/config/initializers/panda/cms/form_errors.rb +20 -21
  89. data/config/initializers/panda/cms/healthcheck_log_silencer.rb +2 -0
  90. data/config/initializers/panda/cms.rb +8 -3
  91. data/config/initializers/zeitwork.rb +2 -0
  92. data/config/puma/test.rb +3 -1
  93. data/config/routes.rb +11 -19
  94. data/db/migrate/20240205223709_create_panda_cms_pages.rb +2 -0
  95. data/db/migrate/20240219213327_create_panda_cms_page_versions.rb +2 -0
  96. data/db/migrate/20240303002805_create_panda_cms_templates.rb +4 -1
  97. data/db/migrate/20240303003434_create_panda_cms_template_versions.rb +2 -0
  98. data/db/migrate/20240303022441_create_panda_cms_blocks.rb +4 -1
  99. data/db/migrate/20240303024256_create_panda_cms_block_contents.rb +2 -0
  100. data/db/migrate/20240303024746_create_panda_cms_block_content_versions.rb +2 -0
  101. data/db/migrate/20240303233238_add_panda_cms_menu_table.rb +2 -0
  102. data/db/migrate/20240303234724_add_panda_cms_menu_item_table.rb +2 -0
  103. data/db/migrate/20240304134343_add_parent_id_to_panda_cms_pages.rb +2 -0
  104. data/db/migrate/20240315125411_add_status_to_panda_cms_pages.rb +7 -5
  105. data/db/migrate/20240315125421_add_nested_sets_to_panda_cms_pages.rb +2 -0
  106. data/db/migrate/20240316212822_add_kind_to_panda_cms_menus.rb +3 -1
  107. data/db/migrate/20240316221425_add_start_page_to_panda_cms_menus.rb +2 -0
  108. data/db/migrate/20240316230706_add_nested_to_panda_cms_menu_items.rb +2 -0
  109. data/db/migrate/20240317010532_create_panda_cms_users.rb +2 -0
  110. data/db/migrate/20240317161534_add_max_uses_to_panda_cms_template.rb +2 -0
  111. data/db/migrate/20240317163053_reset_counter_cache_on_panda_cms_template.rb +2 -0
  112. data/db/migrate/20240317214827_create_panda_cms_redirects.rb +2 -0
  113. data/db/migrate/20240317230622_create_panda_cms_visits.rb +2 -0
  114. data/db/migrate/20240324205703_create_active_storage_tables.active_storage.rb +5 -2
  115. data/db/migrate/20240408084718_default_panda_cms_users_admin_to_false.rb +2 -0
  116. data/db/migrate/20240701225422_add_service_name_to_active_storage_blobs.active_storage.rb +8 -6
  117. data/db/migrate/20240701225423_create_active_storage_variant_records.active_storage.rb +2 -0
  118. data/db/migrate/20240701225424_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb +2 -0
  119. data/db/migrate/20240804235210_create_panda_cms_forms.rb +2 -0
  120. data/db/migrate/20240805013612_create_panda_cms_form_submissions.rb +2 -0
  121. data/db/migrate/20240805121123_create_panda_cms_posts.rb +3 -1
  122. data/db/migrate/20240805123104_create_panda_cms_post_versions.rb +2 -0
  123. data/db/migrate/20240806112735_fix_panda_cms_visits_column_names.rb +2 -0
  124. data/db/migrate/20240806204412_add_completion_path_to_panda_cms_forms.rb +2 -0
  125. data/db/migrate/20240820081917_change_form_submissions_to_submission_count.rb +2 -0
  126. data/db/migrate/20240923234535_add_depth_to_panda_cms_menus.rb +6 -4
  127. data/db/migrate/20241031205109_add_cached_content_to_panda_cms_block_contents.rb +2 -0
  128. data/db/migrate/20241119214548_convert_post_content_to_editor_js.rb +2 -0
  129. data/db/migrate/20241120000419_remove_post_tag_references.rb +2 -0
  130. data/db/migrate/20241120110943_add_editor_js_to_posts.rb +2 -0
  131. data/db/migrate/20241120113859_add_cached_content_to_panda_cms_posts.rb +2 -0
  132. data/db/migrate/20241123234140_remove_post_tag_id_from_posts.rb +2 -0
  133. data/db/migrate/20250106223303_add_author_id_to_panda_cms_posts.rb +5 -1
  134. data/db/migrate/20250120235542_remove_paper_trail.rb +5 -4
  135. data/db/migrate/20250126234001_create_panda_social_instagram_posts.rb +4 -0
  136. data/db/migrate/20250809231125_migrate_users_to_panda_core.rb +111 -0
  137. data/db/migrate/20250811111000_make_post_user_references_nullable.rb +11 -0
  138. data/db/seeds.rb +2 -0
  139. data/lib/generators/panda/cms/install_generator.rb +2 -0
  140. data/lib/panda/cms/asset_loader.rb +390 -0
  141. data/lib/panda/cms/bulk_editor.rb +7 -3
  142. data/lib/panda/cms/demo_site_generator.rb +2 -0
  143. data/lib/panda/cms/engine.rb +57 -116
  144. data/lib/panda/cms/exceptions_app.rb +2 -0
  145. data/lib/panda/cms/railtie.rb +2 -0
  146. data/lib/panda/cms/slug.rb +3 -1
  147. data/lib/panda-cms/version.rb +3 -1
  148. data/lib/panda-cms.rb +54 -42
  149. data/lib/tasks/assets.rake +587 -0
  150. data/lib/tasks/panda/cms/install.rake +2 -0
  151. data/lib/tasks/panda/cms/migrations.rake +13 -0
  152. data/lib/tasks/panda/social/instagram.rake +2 -0
  153. data/lib/tasks/panda_cms.rake +3 -30
  154. data/public/panda-cms-assets/manifest.json +20 -0
  155. data/public/panda-cms-assets/panda-cms-0.7.4.css +26 -0
  156. data/public/panda-cms-assets/panda-cms-0.7.4.js +150 -0
  157. metadata +186 -49
  158. data/app/builders/panda/cms/form_builder.rb +0 -217
  159. data/app/components/panda/cms/admin/button_component.rb +0 -70
  160. data/app/components/panda/cms/admin/container_component.rb +0 -13
  161. data/app/components/panda/cms/admin/flash_message_component.rb +0 -47
  162. data/app/components/panda/cms/admin/heading_component.rb +0 -45
  163. data/app/components/panda/cms/admin/panel_component.rb +0 -13
  164. data/app/components/panda/cms/admin/table_component.rb +0 -46
  165. data/app/components/panda/cms/admin/tag_component.rb +0 -35
  166. data/app/constraints/panda/cms/admin_constraint.rb +0 -18
  167. data/app/controllers/panda/cms/admin/my_profile_controller.rb +0 -43
  168. data/app/controllers/panda/cms/admin/sessions_controller.rb +0 -94
  169. data/app/javascript/panda/cms/controllers/theme_form_controller.js +0 -9
  170. data/app/javascript/panda/cms/editor/css_extractor.js +0 -80
  171. data/app/javascript/panda/cms/editor/editor_js_config.js +0 -306
  172. data/app/javascript/panda/cms/editor/editor_js_initializer.js +0 -334
  173. data/app/javascript/panda/cms/editor/plain_text_editor.js +0 -110
  174. data/app/javascript/panda/cms/editor/resource_loader.js +0 -204
  175. data/app/javascript/panda/cms/editor/rich_text_editor.js +0 -162
  176. data/app/models/panda/cms/breadcrumb.rb +0 -12
  177. data/app/models/panda/cms/user.rb +0 -31
  178. data/app/services/panda/cms/html_to_editor_js_converter.rb +0 -193
  179. data/app/views/panda/cms/admin/my_profile/edit.html.erb +0 -35
  180. data/app/views/panda/cms/admin/sessions/new.html.erb +0 -17
  181. data/db/migrate/20250504221812_add_current_theme_to_panda_cms_users.rb +0 -5
  182. data/lib/panda/cms/editor_js/blocks/alert.rb +0 -34
  183. data/lib/panda/cms/editor_js/blocks/base.rb +0 -33
  184. data/lib/panda/cms/editor_js/blocks/header.rb +0 -15
  185. data/lib/panda/cms/editor_js/blocks/image.rb +0 -36
  186. data/lib/panda/cms/editor_js/blocks/list.rb +0 -32
  187. data/lib/panda/cms/editor_js/blocks/paragraph.rb +0 -15
  188. data/lib/panda/cms/editor_js/blocks/quote.rb +0 -41
  189. data/lib/panda/cms/editor_js/blocks/table.rb +0 -50
  190. data/lib/panda/cms/editor_js/renderer.rb +0 -124
  191. data/lib/panda/cms/editor_js.rb +0 -16
  192. data/lib/panda/cms/editor_js_content.rb +0 -55
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSPages < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_pages, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSPageVersions < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_page_versions, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSTemplates < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_templates, id: :uuid do |t|
@@ -6,6 +8,7 @@ class CreatePandaCMSTemplates < ActiveRecord::Migration[7.1]
6
8
  t.timestamps
7
9
  end
8
10
 
9
- add_reference :panda_cms_pages, :panda_cms_template, type: :uuid, foreign_key: {to_table: :panda_cms_templates}, null: false
11
+ add_reference :panda_cms_pages, :panda_cms_template, type: :uuid, foreign_key: {to_table: :panda_cms_templates},
12
+ null: false
10
13
  end
11
14
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSTemplateVersions < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_template_versions, id: :uuid do |t|
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSBlocks < ActiveRecord::Migration[7.1]
2
4
  def change
3
- create_enum :panda_cms_block_kind, ["plain_text", "rich_text", "image", "video", "audio", "file", "code", "iframe", "quote", "list", "table", "form"]
5
+ create_enum :panda_cms_block_kind,
6
+ %w[plain_text rich_text image video audio file code iframe quote list table form]
4
7
 
5
8
  create_table :panda_cms_blocks, id: :uuid do |t|
6
9
  t.enum :kind, enum_type: :panda_cms_block_kind, default: "plain_text", null: false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSBlockContents < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_block_contents, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSBlockContentVersions < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_block_content_versions, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddPandaCMSMenuTable < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_menus, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddPandaCMSMenuItemTable < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_menu_items, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddParentIdToPandaCMSPages < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  add_reference :panda_cms_pages, :parent, type: :uuid, foreign_key: {to_table: :panda_cms_pages}
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddStatusToPandaCMSPages < ActiveRecord::Migration[7.1]
2
4
  def change
3
- unless column_exists?(:panda_cms_pages, :status)
4
- create_enum :panda_cms_page_status, ["active", "draft", "hidden", "archived"]
5
- add_column :panda_cms_pages, :status, :panda_cms_page_status, default: "active", null: false
6
- add_index :panda_cms_pages, :status
7
- end
5
+ return if column_exists?(:panda_cms_pages, :status)
6
+
7
+ create_enum :panda_cms_page_status, %w[active draft hidden archived]
8
+ add_column :panda_cms_pages, :status, :panda_cms_page_status, default: "active", null: false
9
+ add_index :panda_cms_pages, :status
8
10
  end
9
11
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddNestedSetsToPandaCMSPages < ActiveRecord::Migration[7.1]
2
4
  def self.up
3
5
  Panda::CMS::Page.where(parent_id: 0).update_all(parent_id: nil)
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddKindToPandaCMSMenus < ActiveRecord::Migration[7.1]
2
4
  def change
3
- create_enum :panda_cms_menu_kind, ["static", "auto"]
5
+ create_enum :panda_cms_menu_kind, %w[static auto]
4
6
  add_column :panda_cms_menus, :kind, :enum, enum_type: :panda_cms_menu_kind, default: "static", null: false
5
7
  end
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddStartPageToPandaCMSMenus < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  add_reference :panda_cms_menus, :start_page, type: :uuid, foreign_key: {to_table: :panda_cms_pages}
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddNestedToPandaCMSMenuItems < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  add_column :panda_cms_menu_items, :parent_id, :uuid
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSUsers < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_users, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddMaxUsesToPandaCMSTemplate < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  add_column :panda_cms_templates, :max_uses, :integer, null: true, default: nil
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ResetCounterCacheOnPandaCMSTemplate < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  Panda::CMS::Template.find_each { |t| Panda::CMS::Template.reset_counters(t.id, :pages) }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSRedirects < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_redirects, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSVisits < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_visits, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This migration comes from active_storage (originally 20170806125915)
2
4
  class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
3
5
  def change
@@ -33,7 +35,8 @@ class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
33
35
  t.datetime :created_at, null: false
34
36
  end
35
37
 
36
- t.index [:record_type, :record_id, :name, :blob_id], name: :index_active_storage_attachments_uniqueness, unique: true
38
+ t.index %i[record_type record_id name blob_id], name: :index_active_storage_attachments_uniqueness,
39
+ unique: true
37
40
  t.foreign_key :active_storage_blobs, column: :blob_id
38
41
  end
39
42
 
@@ -41,7 +44,7 @@ class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
41
44
  t.belongs_to :blob, null: false, index: false, type: foreign_key_type
42
45
  t.string :variation_digest, null: false
43
46
 
44
- t.index [:blob_id, :variation_digest], name: :index_active_storage_variant_records_uniqueness, unique: true
47
+ t.index %i[blob_id variation_digest], name: :index_active_storage_variant_records_uniqueness, unique: true
45
48
  t.foreign_key :active_storage_blobs, column: :blob_id
46
49
  end
47
50
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class DefaultPandaCMSUsersAdminToFalse < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  change_column :panda_cms_users, :admin, :boolean, default: false
@@ -1,17 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This migration comes from active_storage (originally 20190112182829)
2
4
  class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
3
5
  def up
4
6
  return unless table_exists?(:active_storage_blobs)
5
7
 
6
- unless column_exists?(:active_storage_blobs, :service_name)
7
- add_column :active_storage_blobs, :service_name, :string
8
+ return if column_exists?(:active_storage_blobs, :service_name)
8
9
 
9
- if (configured_service = ActiveStorage::Blob.service.name)
10
- ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
11
- end
10
+ add_column :active_storage_blobs, :service_name, :string
12
11
 
13
- change_column :active_storage_blobs, :service_name, :string, null: false
12
+ if (configured_service = ActiveStorage::Blob.service.name)
13
+ ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
14
14
  end
15
+
16
+ change_column :active_storage_blobs, :service_name, :string, null: false
15
17
  end
16
18
 
17
19
  def down
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This migration comes from active_storage (originally 20191206030411)
2
4
  class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
3
5
  def change
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This migration comes from active_storage (originally 20211119233751)
2
4
  class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0]
3
5
  def change
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSForms < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_forms, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSFormSubmissions < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_form_submissions, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSPosts < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_post_tags, id: :uuid do |t|
@@ -20,7 +22,7 @@ class CreatePandaCMSPosts < ActiveRecord::Migration[7.1]
20
22
  t.index :slug, unique: true
21
23
  end
22
24
 
23
- create_enum :panda_cms_post_status, ["active", "draft", "hidden", "archived"]
25
+ create_enum :panda_cms_post_status, %w[active draft hidden archived]
24
26
  add_column :panda_cms_posts, :status, :panda_cms_post_status, default: "draft", null: false
25
27
  add_index :panda_cms_posts, :status
26
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaCMSPostVersions < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  create_table :panda_cms_post_versions, id: :uuid do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class FixPandaCMSVisitsColumnNames < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  change_table :panda_cms_visits do |t|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddCompletionPathToPandaCMSForms < ActiveRecord::Migration[7.1]
2
4
  def change
3
5
  add_column :panda_cms_forms, :completion_path, :string
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ChangeFormSubmissionsToSubmissionCount < ActiveRecord::Migration[7.2]
2
4
  def change
3
5
  rename_column :panda_cms_forms, :submissions, :submission_count
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddDepthToPandaCMSMenus < ActiveRecord::Migration[7.2]
2
4
  def change
3
5
  add_column :panda_cms_menus, :depth, :integer, null: true, default: nil
4
6
 
5
7
  homepage = Panda::CMS::Page.find_by(path: "/")
6
- if homepage
7
- main_menu = Panda::CMS::Menu.find_by(start_page_id: homepage.id, kind: :auto)
8
- main_menu&.update(depth: 2)
9
- end
8
+ return unless homepage
9
+
10
+ main_menu = Panda::CMS::Menu.find_by(start_page_id: homepage.id, kind: :auto)
11
+ main_menu&.update(depth: 2)
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddCachedContentToPandaCMSBlockContents < ActiveRecord::Migration[7.2]
2
4
  def change
3
5
  add_column :panda_cms_block_contents, :cached_content, :jsonb
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ConvertPostContentToEditorJs < ActiveRecord::Migration[7.1]
2
4
  def up
3
5
  Panda::CMS::Post.find_each do |post|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemovePostTagReferences < ActiveRecord::Migration[8.0]
2
4
  def up
3
5
  remove_reference :panda_cms_posts, :post_tag, foreign_key: {to_table: :panda_cms_post_tags}, type: :uuid
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddEditorJsToPosts < ActiveRecord::Migration[7.0]
2
4
  def up
3
5
  # First, add a temporary column
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddCachedContentToPandaCMSPosts < ActiveRecord::Migration[8.0]
2
4
  def change
3
5
  add_column :panda_cms_posts, :cached_content, :text
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemovePostTagIdFromPosts < ActiveRecord::Migration[8.0]
2
4
  def change
3
5
  remove_column :panda_cms_posts, :post_tag_id if column_exists?(:panda_cms_posts, :post_tag_id)
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddAuthorIdToPandaCMSPosts < ActiveRecord::Migration[8.0]
2
4
  def change
3
- add_reference :panda_cms_posts, :author, type: :uuid, foreign_key: {to_table: :panda_cms_users}
5
+ unless column_exists?(:panda_cms_posts, :author_id)
6
+ add_reference :panda_cms_posts, :author, type: :uuid, foreign_key: {to_table: :panda_core_users}
7
+ end
4
8
  end
5
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RemovePaperTrail < ActiveRecord::Migration[7.1]
2
4
  def up
3
5
  version_tables = %w[
@@ -11,9 +13,7 @@ class RemovePaperTrail < ActiveRecord::Migration[7.1]
11
13
  ]
12
14
 
13
15
  version_tables.each do |table|
14
- if table_exists?(table)
15
- drop_table table
16
- end
16
+ drop_table table if table_exists?(table)
17
17
  end
18
18
  end
19
19
 
@@ -36,7 +36,8 @@ class RemovePaperTrail < ActiveRecord::Migration[7.1]
36
36
  t.string :foreign_type
37
37
  end
38
38
  add_index :panda_cms_version_associations, [:version_id]
39
- add_index :panda_cms_version_associations, [:foreign_key_name, :foreign_key_id, :foreign_type], name: "index_version_associations_on_foreign_key"
39
+ add_index :panda_cms_version_associations, %i[foreign_key_name foreign_key_id foreign_type],
40
+ name: "index_version_associations_on_foreign_key"
40
41
 
41
42
  # Model-specific version tables
42
43
  %w[template page block_content post action_text_rich_text].each do |model|
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class CreatePandaSocialInstagramPosts < ActiveRecord::Migration[7.1]
2
4
  def change
5
+ return if table_exists?(:panda_social_instagram_posts)
6
+
3
7
  create_table :panda_social_instagram_posts, id: :uuid do |t|
4
8
  t.string :instagram_id, null: false
5
9
  t.text :caption
@@ -0,0 +1,111 @@
1
+ class MigrateUsersToPandaCore < ActiveRecord::Migration[8.0]
2
+ def up
3
+ # First ensure panda_core_users table exists (from Core engine)
4
+ # It should already exist from the Core migration
5
+
6
+ # Migrate data from panda_cms_users to panda_core_users if needed
7
+ if table_exists?(:panda_cms_users) && table_exists?(:panda_core_users)
8
+ # Check if there's any data to migrate
9
+ cms_user_count = ActiveRecord::Base.connection.select_value("SELECT COUNT(*) FROM panda_cms_users")
10
+ return if cms_user_count == 0
11
+ # Copy all user data
12
+ execute <<-SQL
13
+ INSERT INTO panda_core_users (
14
+ id, name, email, image_url, is_admin, created_at, updated_at
15
+ )
16
+ SELECT
17
+ id,
18
+ COALESCE(name, CONCAT(firstname, ' ', lastname), 'Unknown User'),
19
+ email,
20
+ image_url,
21
+ COALESCE(admin, false),
22
+ created_at,
23
+ updated_at
24
+ FROM panda_cms_users
25
+ WHERE NOT EXISTS (
26
+ SELECT 1 FROM panda_core_users WHERE panda_core_users.id = panda_cms_users.id
27
+ )
28
+ SQL
29
+
30
+ # Update foreign key references in other tables
31
+
32
+ # Posts author_id
33
+ if column_exists?(:panda_cms_posts, :author_id)
34
+ remove_foreign_key :panda_cms_posts, column: :author_id if foreign_key_exists?(:panda_cms_posts, :panda_cms_users, column: :author_id)
35
+ add_foreign_key :panda_cms_posts, :panda_core_users, column: :author_id, primary_key: :id
36
+ end
37
+
38
+ # Posts user_id (legacy column)
39
+ if column_exists?(:panda_cms_posts, :user_id)
40
+ remove_foreign_key :panda_cms_posts, column: :user_id if foreign_key_exists?(:panda_cms_posts, :panda_cms_users, column: :user_id)
41
+ add_foreign_key :panda_cms_posts, :panda_core_users, column: :user_id, primary_key: :id
42
+ end
43
+
44
+ # Visits user_id
45
+ if column_exists?(:panda_cms_visits, :user_id)
46
+ remove_foreign_key :panda_cms_visits, column: :user_id if foreign_key_exists?(:panda_cms_visits, :panda_cms_users, column: :user_id)
47
+ add_foreign_key :panda_cms_visits, :panda_core_users, column: :user_id, primary_key: :id
48
+ end
49
+
50
+ # Drop the old table
51
+ drop_table :panda_cms_users
52
+ end
53
+ end
54
+
55
+ def down
56
+ # Recreate panda_cms_users table
57
+ create_table :panda_cms_users, id: :uuid do |t|
58
+ t.string :name
59
+ t.string :firstname
60
+ t.string :lastname
61
+ t.string :email, null: false
62
+ t.string :image_url
63
+ t.boolean :admin, default: false
64
+ t.string :current_theme, default: "default"
65
+ t.timestamps
66
+ end
67
+
68
+ add_index :panda_cms_users, :email, unique: true
69
+
70
+ # Migrate data back
71
+ if table_exists?(:panda_core_users) && table_exists?(:panda_cms_users)
72
+ execute <<-SQL
73
+ INSERT INTO panda_cms_users (
74
+ id, firstname, lastname, name, email, image_url, admin, current_theme, created_at, updated_at
75
+ )
76
+ SELECT
77
+ id,
78
+ split_part(name, ' ', 1),
79
+ CASE
80
+ WHEN position(' ' IN name) > 0
81
+ THEN substring(name FROM position(' ' IN name) + 1)
82
+ ELSE ''
83
+ END,
84
+ name,
85
+ email,
86
+ image_url,
87
+ is_admin,
88
+ 'default',
89
+ created_at,
90
+ updated_at
91
+ FROM panda_core_users
92
+ SQL
93
+
94
+ # Restore foreign keys to panda_cms_users
95
+ if column_exists?(:panda_cms_posts, :author_id)
96
+ remove_foreign_key :panda_cms_posts, column: :author_id if foreign_key_exists?(:panda_cms_posts, column: :author_id)
97
+ add_foreign_key :panda_cms_posts, :panda_cms_users, column: :author_id, primary_key: :id
98
+ end
99
+
100
+ if column_exists?(:panda_cms_posts, :user_id)
101
+ remove_foreign_key :panda_cms_posts, column: :user_id if foreign_key_exists?(:panda_cms_posts, column: :user_id)
102
+ add_foreign_key :panda_cms_posts, :panda_cms_users, column: :user_id, primary_key: :id
103
+ end
104
+
105
+ if column_exists?(:panda_cms_visits, :user_id)
106
+ remove_foreign_key :panda_cms_visits, column: :user_id if foreign_key_exists?(:panda_cms_visits, column: :user_id)
107
+ add_foreign_key :panda_cms_visits, :panda_cms_users, column: :user_id, primary_key: :id
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MakePostUserReferencesNullable < ActiveRecord::Migration[8.0]
4
+ def change
5
+ # Make user_id and author_id nullable for posts
6
+ # This is needed because fixtures can't reference users from another gem
7
+ # Tests that need users will set them programmatically
8
+ change_column_null :panda_cms_posts, :user_id, true
9
+ change_column_null :panda_cms_posts, :author_id, true
10
+ end
11
+ end
data/db/seeds.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  generator = Panda::CMS::DemoSiteGenerator.new
2
4
  generator.create_templates
3
5
  generator.create_pages
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Generators
2
4
  module Panda
3
5
  module CMS