From 11e02dec70751521fed6f0c9a17a9d32ab31b5ad Mon Sep 17 00:00:00 2001 From: Bram Jetten Date: Wed, 31 Jul 2024 20:11:09 +0100 Subject: [PATCH] Add support for MySQL and SQLite --- app/controllers/spina/admin/page_select_options_controller.rb | 4 ++-- .../spina/admin/resource_select_options_controller.rb | 2 +- app/models/concerns/spina/attachable.rb | 4 ++-- app/models/spina/resource.rb | 2 +- db/migrate/13_add_json_attributes_to_spina_accounts.rb | 2 +- db/migrate/14_add_json_attributes_to_spina_pages.rb | 2 +- db/migrate/15_add_slug_to_spina_resources.rb | 2 +- db/migrate/7_create_spina_settings.rb | 2 +- docs/v2/advanced/1_create_custom_parts.md | 2 +- spina.gemspec | 2 +- test/dummy/.ruby-version | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/spina/admin/page_select_options_controller.rb b/app/controllers/spina/admin/page_select_options_controller.rb index f63e1d65f..b335f86b2 100644 --- a/app/controllers/spina/admin/page_select_options_controller.rb +++ b/app/controllers/spina/admin/page_select_options_controller.rb @@ -15,10 +15,10 @@ def search end @pages ||= Page.all - @pages = @pages.joins(:translations).where("spina_page_translations.title ILIKE :query OR materialized_path ILIKE :query", query: "%#{params[:search]}%").order(created_at: :desc).distinct.page(params[:page]).per(20) + @pages = @pages.joins(:translations).where("LOWER(spina_page_translations.title) LIKE LOWER(:query) OR LOWER(materialized_path) LIKE LOWER(:query)", query: "%#{params[:search]}%").order(created_at: :desc).distinct.page(params[:page]).per(20) render :index end end end -end \ No newline at end of file +end diff --git a/app/controllers/spina/admin/resource_select_options_controller.rb b/app/controllers/spina/admin/resource_select_options_controller.rb index 708108599..fd35ee0f9 100644 --- a/app/controllers/spina/admin/resource_select_options_controller.rb +++ b/app/controllers/spina/admin/resource_select_options_controller.rb @@ -11,7 +11,7 @@ def index def search @resources ||= Resource.all - @resources = @resources.where("name ILIKE :query OR label ILIKE :query", query: "%#{params[:search]}%").order(created_at: :desc).distinct.page(params[:page]).per(20) + @resources = @resources.where("LOWER(name) LIKE LOWER(:query) OR LOWER(label) LIKE LOWER(:query)", query: "%#{params[:search]}%").order(created_at: :desc).distinct.page(params[:page]).per(20) render :index end diff --git a/app/models/concerns/spina/attachable.rb b/app/models/concerns/spina/attachable.rb index c7adb916d..d1b367b59 100644 --- a/app/models/concerns/spina/attachable.rb +++ b/app/models/concerns/spina/attachable.rb @@ -7,7 +7,7 @@ module Attachable scope :with_filename, ->(query) do joins(:file_blob).where( - "active_storage_blobs.filename ILIKE ?", + "LOWER(active_storage_blobs.filename) LIKE LOWER(?)", "%" + Image.sanitize_sql_like(query) + "%" ) end @@ -18,4 +18,4 @@ def name end end -end \ No newline at end of file +end diff --git a/app/models/spina/resource.rb b/app/models/spina/resource.rb index 35325ef1c..009b847ee 100644 --- a/app/models/spina/resource.rb +++ b/app/models/spina/resource.rb @@ -6,7 +6,7 @@ class Resource < ApplicationRecord after_commit :update_resource_pages, on: [:update] - translates :slug, backend: :jsonb + translates :slug, backend: :json def pages case order_by diff --git a/db/migrate/13_add_json_attributes_to_spina_accounts.rb b/db/migrate/13_add_json_attributes_to_spina_accounts.rb index f1f3c3087..515b30b89 100644 --- a/db/migrate/13_add_json_attributes_to_spina_accounts.rb +++ b/db/migrate/13_add_json_attributes_to_spina_accounts.rb @@ -1,5 +1,5 @@ class AddJsonAttributesToSpinaAccounts < ActiveRecord::Migration[5.2] def change - add_column :spina_accounts, :json_attributes, :jsonb + add_column :spina_accounts, :json_attributes, :json end end diff --git a/db/migrate/14_add_json_attributes_to_spina_pages.rb b/db/migrate/14_add_json_attributes_to_spina_pages.rb index c7b82935d..41ca4a132 100644 --- a/db/migrate/14_add_json_attributes_to_spina_pages.rb +++ b/db/migrate/14_add_json_attributes_to_spina_pages.rb @@ -1,5 +1,5 @@ class AddJsonAttributesToSpinaPages < ActiveRecord::Migration[5.2] def change - add_column :spina_pages, :json_attributes, :jsonb + add_column :spina_pages, :json_attributes, :json end end diff --git a/db/migrate/15_add_slug_to_spina_resources.rb b/db/migrate/15_add_slug_to_spina_resources.rb index 910e8bcc9..3341f1a64 100644 --- a/db/migrate/15_add_slug_to_spina_resources.rb +++ b/db/migrate/15_add_slug_to_spina_resources.rb @@ -1,5 +1,5 @@ class AddSlugToSpinaResources < ActiveRecord::Migration[5.2] def change - add_column :spina_resources, :slug, :jsonb + add_column :spina_resources, :slug, :json end end diff --git a/db/migrate/7_create_spina_settings.rb b/db/migrate/7_create_spina_settings.rb index f4ee57c9f..e68a490ad 100644 --- a/db/migrate/7_create_spina_settings.rb +++ b/db/migrate/7_create_spina_settings.rb @@ -2,7 +2,7 @@ class CreateSpinaSettings < ActiveRecord::Migration[5.0] def change create_table :spina_settings do |t| t.string :plugin - t.jsonb :preferences, default: {} + t.json :preferences, default: {} t.timestamps end diff --git a/docs/v2/advanced/1_create_custom_parts.md b/docs/v2/advanced/1_create_custom_parts.md index 5f556912b..e98a58ea0 100644 --- a/docs/v2/advanced/1_create_custom_parts.md +++ b/docs/v2/advanced/1_create_custom_parts.md @@ -1,6 +1,6 @@ # Custom parts -All page content is stored in a single JSONB-column in the database. Spina uses the `attr_json` gem to work with these nested json objects. All default parts are `AttrJson::Model` objects. Follow the steps below to create your own custom part. +All page content is stored in a single JSON-column in the database. Spina uses the `attr_json` gem to work with these nested json objects. All default parts are `AttrJson::Model` objects. Follow the steps below to create your own custom part. ## Step 1. Create a part Let's imagine our app contains a movie database. We'd like to add a part to select one of the movies in our collection. First we need to create the object that can be stored as page content. diff --git a/spina.gemspec b/spina.gemspec index d9b1c43e8..c35c800ec 100644 --- a/spina.gemspec +++ b/spina.gemspec @@ -35,7 +35,7 @@ Gem::Specification.new do |gem| gem.add_dependency "rails", ">= 6.0" gem.add_dependency "sprockets-rails" - gem.add_dependency "pg" + # gem.add_dependency "pg" gem.add_dependency "bcrypt" gem.add_dependency "image_processing" gem.add_dependency "ancestry" diff --git a/test/dummy/.ruby-version b/test/dummy/.ruby-version index be94e6f53..bea438e9a 100644 --- a/test/dummy/.ruby-version +++ b/test/dummy/.ruby-version @@ -1 +1 @@ -3.2.2 +3.3.1