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.
- checksums.yaml +4 -4
- data/README.md +37 -2
- data/Rakefile +2 -0
- data/app/components/panda/cms/admin/statistics_component.rb +1 -2
- data/app/components/panda/cms/admin/user_activity_component.html.erb +3 -1
- data/app/components/panda/cms/admin/user_activity_component.rb +3 -5
- data/app/components/panda/cms/admin/user_display_component.html.erb +1 -1
- data/app/components/panda/cms/admin/user_display_component.rb +2 -2
- data/app/components/panda/cms/code_component.rb +8 -4
- data/app/components/panda/cms/menu_component.rb +7 -6
- data/app/components/panda/cms/page_menu_component.rb +15 -17
- data/app/components/panda/cms/rich_text_component.rb +10 -11
- data/app/components/panda/cms/text_component.rb +6 -7
- data/app/controllers/panda/cms/admin/base_controller.rb +18 -0
- data/app/controllers/panda/cms/admin/block_contents_controller.rb +1 -2
- data/app/controllers/panda/cms/admin/dashboard_controller.rb +14 -9
- data/app/controllers/panda/cms/admin/files_controller.rb +1 -3
- data/app/controllers/panda/cms/admin/forms_controller.rb +3 -6
- data/app/controllers/panda/cms/admin/menus_controller.rb +2 -3
- data/app/controllers/panda/cms/admin/pages_controller.rb +9 -8
- data/app/controllers/panda/cms/admin/posts_controller.rb +9 -11
- data/app/controllers/panda/cms/admin/settings/bulk_editor_controller.rb +32 -25
- data/app/controllers/panda/cms/admin/settings_controller.rb +13 -10
- data/app/controllers/panda/cms/application_controller.rb +19 -6
- data/app/controllers/panda/cms/errors_controller.rb +5 -2
- data/app/controllers/panda/cms/form_submissions_controller.rb +2 -0
- data/app/controllers/panda/cms/pages_controller.rb +34 -31
- data/app/controllers/panda/cms/posts_controller.rb +2 -0
- data/app/helpers/panda/cms/admin/files_helper.rb +5 -1
- data/app/helpers/panda/cms/admin/pages_helper.rb +5 -1
- data/app/helpers/panda/cms/application_helper.rb +3 -3
- data/app/helpers/panda/cms/asset_helper.rb +195 -0
- data/app/helpers/panda/cms/pages_helper.rb +2 -0
- data/app/helpers/panda/cms/posts_helper.rb +2 -0
- data/app/helpers/panda/cms/theme_helper.rb +2 -0
- data/app/javascript/panda/cms/application_panda_cms.js +2 -34
- data/app/javascript/panda/cms/controllers/editor_form_controller.js +59 -6
- data/app/javascript/panda/cms/controllers/index.js +8 -24
- data/app/javascript/panda/cms/stimulus-loading.js +39 -0
- data/app/javascript/panda_cms/stimulus-loading.js +39 -0
- data/app/jobs/panda/cms/application_job.rb +2 -0
- data/app/jobs/panda/cms/record_visit_job.rb +2 -0
- data/app/mailers/panda/cms/application_mailer.rb +2 -0
- data/app/mailers/panda/cms/form_mailer.rb +3 -1
- data/app/models/panda/cms/application_record.rb +2 -0
- data/app/models/panda/cms/block.rb +4 -1
- data/app/models/panda/cms/block_content.rb +3 -1
- data/app/models/panda/cms/current.rb +5 -12
- data/app/models/panda/cms/form.rb +2 -0
- data/app/models/panda/cms/form_submission.rb +2 -0
- data/app/models/panda/cms/menu.rb +12 -9
- data/app/models/panda/cms/menu_item.rb +10 -6
- data/app/models/panda/cms/page.rb +14 -12
- data/app/models/panda/cms/post.rb +12 -8
- data/app/models/panda/cms/redirect.rb +6 -3
- data/app/models/panda/cms/template.rb +12 -7
- data/app/models/panda/cms/visit.rb +3 -1
- data/app/models/panda/social/instagram_post.rb +2 -0
- data/app/services/panda/social/instagram_feed_service.rb +3 -1
- data/app/views/layouts/different_page.html.erb +6 -0
- data/app/views/layouts/homepage.html.erb +37 -0
- data/app/views/layouts/page.html.erb +18 -0
- data/app/views/layouts/panda/cms/application.html.erb +2 -1
- data/app/views/panda/cms/admin/dashboard/show.html.erb +2 -2
- data/app/views/panda/cms/admin/files/index.html.erb +1 -1
- data/app/views/panda/cms/admin/forms/index.html.erb +4 -4
- data/app/views/panda/cms/admin/forms/new.html.erb +2 -2
- data/app/views/panda/cms/admin/forms/show.html.erb +1 -1
- data/app/views/panda/cms/admin/menus/index.html.erb +4 -4
- data/app/views/panda/cms/admin/pages/edit.html.erb +6 -6
- data/app/views/panda/cms/admin/pages/index.html.erb +5 -5
- data/app/views/panda/cms/admin/pages/new.html.erb +16 -10
- data/app/views/panda/cms/admin/posts/_form.html.erb +1 -1
- data/app/views/panda/cms/admin/posts/edit.html.erb +2 -2
- data/app/views/panda/cms/admin/posts/index.html.erb +5 -5
- data/app/views/panda/cms/admin/posts/new.html.erb +1 -1
- data/app/views/panda/cms/admin/settings/bulk_editor/new.html.erb +1 -1
- data/app/views/panda/cms/admin/settings/index.html.erb +4 -4
- data/app/views/panda/cms/admin/shared/_breadcrumbs.html.erb +3 -3
- data/app/views/panda/cms/admin/shared/_flash.html.erb +1 -1
- data/app/views/panda/cms/admin/shared/_sidebar.html.erb +8 -8
- data/app/views/panda/cms/shared/_header.html.erb +10 -2
- data/app/views/panda/cms/shared/_importmap.html.erb +1 -1
- data/app/views/shared/_footer.html.erb +3 -0
- data/app/views/shared/_header.html.erb +11 -0
- data/config/importmap.rb +2 -0
- data/config/initializers/inflections.rb +2 -0
- data/config/initializers/panda/cms/form_errors.rb +20 -21
- data/config/initializers/panda/cms/healthcheck_log_silencer.rb +2 -0
- data/config/initializers/panda/cms.rb +8 -3
- data/config/initializers/zeitwork.rb +2 -0
- data/config/puma/test.rb +3 -1
- data/config/routes.rb +11 -19
- data/db/migrate/20240205223709_create_panda_cms_pages.rb +2 -0
- data/db/migrate/20240219213327_create_panda_cms_page_versions.rb +2 -0
- data/db/migrate/20240303002805_create_panda_cms_templates.rb +4 -1
- data/db/migrate/20240303003434_create_panda_cms_template_versions.rb +2 -0
- data/db/migrate/20240303022441_create_panda_cms_blocks.rb +4 -1
- data/db/migrate/20240303024256_create_panda_cms_block_contents.rb +2 -0
- data/db/migrate/20240303024746_create_panda_cms_block_content_versions.rb +2 -0
- data/db/migrate/20240303233238_add_panda_cms_menu_table.rb +2 -0
- data/db/migrate/20240303234724_add_panda_cms_menu_item_table.rb +2 -0
- data/db/migrate/20240304134343_add_parent_id_to_panda_cms_pages.rb +2 -0
- data/db/migrate/20240315125411_add_status_to_panda_cms_pages.rb +7 -5
- data/db/migrate/20240315125421_add_nested_sets_to_panda_cms_pages.rb +2 -0
- data/db/migrate/20240316212822_add_kind_to_panda_cms_menus.rb +3 -1
- data/db/migrate/20240316221425_add_start_page_to_panda_cms_menus.rb +2 -0
- data/db/migrate/20240316230706_add_nested_to_panda_cms_menu_items.rb +2 -0
- data/db/migrate/20240317010532_create_panda_cms_users.rb +2 -0
- data/db/migrate/20240317161534_add_max_uses_to_panda_cms_template.rb +2 -0
- data/db/migrate/20240317163053_reset_counter_cache_on_panda_cms_template.rb +2 -0
- data/db/migrate/20240317214827_create_panda_cms_redirects.rb +2 -0
- data/db/migrate/20240317230622_create_panda_cms_visits.rb +2 -0
- data/db/migrate/20240324205703_create_active_storage_tables.active_storage.rb +5 -2
- data/db/migrate/20240408084718_default_panda_cms_users_admin_to_false.rb +2 -0
- data/db/migrate/20240701225422_add_service_name_to_active_storage_blobs.active_storage.rb +8 -6
- data/db/migrate/20240701225423_create_active_storage_variant_records.active_storage.rb +2 -0
- data/db/migrate/20240701225424_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb +2 -0
- data/db/migrate/20240804235210_create_panda_cms_forms.rb +2 -0
- data/db/migrate/20240805013612_create_panda_cms_form_submissions.rb +2 -0
- data/db/migrate/20240805121123_create_panda_cms_posts.rb +3 -1
- data/db/migrate/20240805123104_create_panda_cms_post_versions.rb +2 -0
- data/db/migrate/20240806112735_fix_panda_cms_visits_column_names.rb +2 -0
- data/db/migrate/20240806204412_add_completion_path_to_panda_cms_forms.rb +2 -0
- data/db/migrate/20240820081917_change_form_submissions_to_submission_count.rb +2 -0
- data/db/migrate/20240923234535_add_depth_to_panda_cms_menus.rb +6 -4
- data/db/migrate/20241031205109_add_cached_content_to_panda_cms_block_contents.rb +2 -0
- data/db/migrate/20241119214548_convert_post_content_to_editor_js.rb +2 -0
- data/db/migrate/20241120000419_remove_post_tag_references.rb +2 -0
- data/db/migrate/20241120110943_add_editor_js_to_posts.rb +2 -0
- data/db/migrate/20241120113859_add_cached_content_to_panda_cms_posts.rb +2 -0
- data/db/migrate/20241123234140_remove_post_tag_id_from_posts.rb +2 -0
- data/db/migrate/20250106223303_add_author_id_to_panda_cms_posts.rb +5 -1
- data/db/migrate/20250120235542_remove_paper_trail.rb +5 -4
- data/db/migrate/20250126234001_create_panda_social_instagram_posts.rb +4 -0
- data/db/migrate/20250809231125_migrate_users_to_panda_core.rb +111 -0
- data/db/migrate/20250811111000_make_post_user_references_nullable.rb +11 -0
- data/db/seeds.rb +2 -0
- data/lib/generators/panda/cms/install_generator.rb +2 -0
- data/lib/panda/cms/asset_loader.rb +390 -0
- data/lib/panda/cms/bulk_editor.rb +7 -3
- data/lib/panda/cms/demo_site_generator.rb +2 -0
- data/lib/panda/cms/engine.rb +57 -116
- data/lib/panda/cms/exceptions_app.rb +2 -0
- data/lib/panda/cms/railtie.rb +2 -0
- data/lib/panda/cms/slug.rb +3 -1
- data/lib/panda-cms/version.rb +3 -1
- data/lib/panda-cms.rb +54 -42
- data/lib/tasks/assets.rake +587 -0
- data/lib/tasks/panda/cms/install.rake +2 -0
- data/lib/tasks/panda/cms/migrations.rake +13 -0
- data/lib/tasks/panda/social/instagram.rake +2 -0
- data/lib/tasks/panda_cms.rake +3 -30
- data/public/panda-cms-assets/manifest.json +20 -0
- data/public/panda-cms-assets/panda-cms-0.7.4.css +26 -0
- data/public/panda-cms-assets/panda-cms-0.7.4.js +150 -0
- metadata +186 -49
- data/app/builders/panda/cms/form_builder.rb +0 -217
- data/app/components/panda/cms/admin/button_component.rb +0 -70
- data/app/components/panda/cms/admin/container_component.rb +0 -13
- data/app/components/panda/cms/admin/flash_message_component.rb +0 -47
- data/app/components/panda/cms/admin/heading_component.rb +0 -45
- data/app/components/panda/cms/admin/panel_component.rb +0 -13
- data/app/components/panda/cms/admin/table_component.rb +0 -46
- data/app/components/panda/cms/admin/tag_component.rb +0 -35
- data/app/constraints/panda/cms/admin_constraint.rb +0 -18
- data/app/controllers/panda/cms/admin/my_profile_controller.rb +0 -43
- data/app/controllers/panda/cms/admin/sessions_controller.rb +0 -94
- data/app/javascript/panda/cms/controllers/theme_form_controller.js +0 -9
- data/app/javascript/panda/cms/editor/css_extractor.js +0 -80
- data/app/javascript/panda/cms/editor/editor_js_config.js +0 -306
- data/app/javascript/panda/cms/editor/editor_js_initializer.js +0 -334
- data/app/javascript/panda/cms/editor/plain_text_editor.js +0 -110
- data/app/javascript/panda/cms/editor/resource_loader.js +0 -204
- data/app/javascript/panda/cms/editor/rich_text_editor.js +0 -162
- data/app/models/panda/cms/breadcrumb.rb +0 -12
- data/app/models/panda/cms/user.rb +0 -31
- data/app/services/panda/cms/html_to_editor_js_converter.rb +0 -193
- data/app/views/panda/cms/admin/my_profile/edit.html.erb +0 -35
- data/app/views/panda/cms/admin/sessions/new.html.erb +0 -17
- data/db/migrate/20250504221812_add_current_theme_to_panda_cms_users.rb +0 -5
- data/lib/panda/cms/editor_js/blocks/alert.rb +0 -34
- data/lib/panda/cms/editor_js/blocks/base.rb +0 -33
- data/lib/panda/cms/editor_js/blocks/header.rb +0 -15
- data/lib/panda/cms/editor_js/blocks/image.rb +0 -36
- data/lib/panda/cms/editor_js/blocks/list.rb +0 -32
- data/lib/panda/cms/editor_js/blocks/paragraph.rb +0 -15
- data/lib/panda/cms/editor_js/blocks/quote.rb +0 -41
- data/lib/panda/cms/editor_js/blocks/table.rb +0 -50
- data/lib/panda/cms/editor_js/renderer.rb +0 -124
- data/lib/panda/cms/editor_js.rb +0 -16
- data/lib/panda/cms/editor_js_content.rb +0 -55
@@ -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},
|
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,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,
|
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,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class AddStatusToPandaCMSPages < ActiveRecord::Migration[7.1]
|
2
4
|
def change
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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,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, [
|
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
|
# 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 [
|
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 [
|
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,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
|
-
|
7
|
-
add_column :active_storage_blobs, :service_name, :string
|
8
|
+
return if column_exists?(:active_storage_blobs, :service_name)
|
8
9
|
|
9
|
-
|
10
|
-
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
|
11
|
-
end
|
10
|
+
add_column :active_storage_blobs, :service_name, :string
|
12
11
|
|
13
|
-
|
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
|
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, [
|
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,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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class AddAuthorIdToPandaCMSPosts < ActiveRecord::Migration[8.0]
|
2
4
|
def change
|
3
|
-
|
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, [
|
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