Skip to content

Commit

Permalink
Add support for MySQL and SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramjetten committed Jul 31, 2024
1 parent e010015 commit 11e02de
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/controllers/spina/admin/page_select_options_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/models/concerns/spina/attachable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,4 +18,4 @@ def name
end

end
end
end
2 changes: 1 addition & 1 deletion app/models/spina/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/13_add_json_attributes_to_spina_accounts.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/migrate/14_add_json_attributes_to_spina_pages.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/migrate/15_add_slug_to_spina_resources.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/migrate/7_create_spina_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/v2/advanced/1_create_custom_parts.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion spina.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.1

0 comments on commit 11e02de

Please sign in to comment.