From bb28f301e91ff81e6f7cc8ddf6ee2080babed958 Mon Sep 17 00:00:00 2001 From: rhymes Date: Fri, 8 Nov 2019 19:27:44 +0100 Subject: [PATCH] Add site config and remove sail (#4729) * Add SiteConfig model based on rails-settings-cached * Remove sail --- Gemfile | 2 +- Gemfile.lock | 16 ++++----------- app/models/site_config.rb | 10 ++++++++++ .../20191106095242_create_site_configs.rb | 15 ++++++++++++++ .../20191106102826_drop_sail_settings.rb | 16 +++++++++++++++ db/schema.rb | 20 +++++++++---------- 6 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 app/models/site_config.rb create mode 100644 db/migrate/20191106095242_create_site_configs.rb create mode 100644 db/migrate/20191106102826_drop_sail_settings.rb diff --git a/Gemfile b/Gemfile index 247203634..0f9612f7e 100644 --- a/Gemfile +++ b/Gemfile @@ -73,6 +73,7 @@ gem "rack-timeout", "~> 0.5" # Rack middleware which aborts requests that have b gem "rails", "~> 5.2", ">= 5.2.3" # Ruby on Rails gem "rails-assets-airbrake-js-client", "~> 1.6", source: "https://rails-assets.org" # Airbrake JavaScript Notifier gem "rails-observers", "~> 0.1" # Rails observer (removed from core in Rails 4.0) +gem "rails-settings-cached", ">= 2.1.1" # Settings plugin for Rails that makes managing a table of global key, value pairs easy. gem "recaptcha", "~> 5.2", require: "recaptcha/rails" # Helpers for the reCAPTCHA API gem "redcarpet", "~> 3.5" # A fast, safe and extensible Markdown to (X)HTML parser gem "redis", "~> 4.1.3" # Redis ruby client @@ -81,7 +82,6 @@ gem "rolify", "~> 5.2" # Very simple Roles library gem "rouge", "~> 3.12" # A pure-ruby code highlighter gem "rubyzip", "~> 1.2", ">= 1.3.0" # Rubyzip is a ruby library for reading and writing zip files gem "s3_direct_upload", "~> 0.1" # Direct Upload to Amazon S3 -gem "sail", "~> 1.5" # Sail is a lightweight Rails engine that brings an admin panel for managing configuration settings on a live Rails app gem "sass-rails", "~> 6.0" # Sass adapter for the Rails asset pipeline gem "scout_apm", "~> 2.6" # Monitors Ruby apps and reports detailed metrics on performance to Scout gem "serviceworker-rails", "~> 0.6" # Integrates ServiceWorker into the Rails asset pipeline diff --git a/Gemfile.lock b/Gemfile.lock index 14117c03c..172cfda8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -308,8 +308,6 @@ GEM smart_properties errbase (0.1.1) erubi (1.9.0) - et-orbi (1.1.6) - tzinfo eventmachine (1.2.5) excon (0.65.0) execjs (2.7.0) @@ -358,9 +356,6 @@ GEM nokogiri (>= 1.5.11, < 2.0.0) formatador (0.2.5) front_matter_parser (0.2.1) - fugit (1.1.6) - et-orbi (~> 1.1, >= 1.1.6) - raabro (~> 1.1) gemoji (3.0.1) get_process_mem (0.2.4) ffi (~> 1.0) @@ -570,7 +565,6 @@ GEM jwt (~> 2.1, >= 2.1.0) rest-client (~> 2.0, >= 2.0.2) pusher-signature (0.1.8) - raabro (1.1.6) rack (2.0.7) rack-host-redirect (1.3.0) rack @@ -602,6 +596,9 @@ GEM loofah (~> 2.3) rails-observers (0.1.5) activemodel (>= 4.0) + rails-settings-cached (2.1.1) + rails (>= 4.2.0) + request_store railties (5.2.3) actionpack (= 5.2.3) activesupport (= 5.2.3) @@ -691,11 +688,6 @@ GEM safe_yaml (1.0.5) safely_block (0.2.1) errbase - sail (1.5.1) - fugit - jquery-rails - rails - sass-rails sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -955,6 +947,7 @@ DEPENDENCIES rails (~> 5.2, >= 5.2.3) rails-assets-airbrake-js-client (~> 1.6)! rails-observers (~> 0.1) + rails-settings-cached (>= 2.1.1) recaptcha (~> 5.2) redcarpet (~> 3.5) redis (~> 4.1.3) @@ -970,7 +963,6 @@ DEPENDENCIES ruby-prof (~> 1.0) rubyzip (~> 1.2, >= 1.3.0) s3_direct_upload (~> 0.1) - sail (~> 1.5) sass-rails (~> 6.0) scout_apm (~> 2.6) sdoc (~> 1.0) diff --git a/app/models/site_config.rb b/app/models/site_config.rb new file mode 100644 index 000000000..b8d2a43b1 --- /dev/null +++ b/app/models/site_config.rb @@ -0,0 +1,10 @@ +# Site configuration based on RailsSettings models, +# see for further info + +class SiteConfig < RailsSettings::Base + self.table_name = "site_configs" + + # the site configuration is cached, change this if you want to force update + # the cache, or call SiteConfig.clear_cache + cache_prefix { "v1" } +end diff --git a/db/migrate/20191106095242_create_site_configs.rb b/db/migrate/20191106095242_create_site_configs.rb new file mode 100644 index 000000000..722e9fcc0 --- /dev/null +++ b/db/migrate/20191106095242_create_site_configs.rb @@ -0,0 +1,15 @@ +class CreateSiteConfigs < ActiveRecord::Migration[5.2] + def self.up + create_table :site_configs do |t| + t.string :var, null: false + t.text :value, null: true + t.timestamps + end + + add_index :site_configs, %i(var), unique: true + end + + def self.down + drop_table :site_configs + end +end diff --git a/db/migrate/20191106102826_drop_sail_settings.rb b/db/migrate/20191106102826_drop_sail_settings.rb new file mode 100644 index 000000000..45d715696 --- /dev/null +++ b/db/migrate/20191106102826_drop_sail_settings.rb @@ -0,0 +1,16 @@ +class DropSailSettings < ActiveRecord::Migration[5.2] + def up + drop_table :sail_settings + end + + def down + create_table :sail_settings do |t| + t.string :name, null: false + t.text :description + t.string :value, null: false + t.integer :cast_type, null: false, limit: 1 + t.timestamps + t.index ["name"], name: "index_settings_on_name", unique: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2f603e43a..aa881d36e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,7 +12,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_10_31_131016) do +ActiveRecord::Schema.define(version: 2019_11_06_102826) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -880,16 +880,6 @@ ActiveRecord::Schema.define(version: 2019_10_31_131016) do t.index ["name"], name: "index_roles_on_name" end - create_table "sail_settings", force: :cascade do |t| - t.integer "cast_type", limit: 2, null: false - t.datetime "created_at", null: false - t.text "description" - t.string "name", null: false - t.datetime "updated_at", null: false - t.string "value", null: false - t.index ["name"], name: "index_settings_on_name", unique: true - end - create_table "search_keywords", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "google_checked_at" @@ -902,6 +892,14 @@ ActiveRecord::Schema.define(version: 2019_10_31_131016) do t.index ["google_result_path"], name: "index_search_keywords_on_google_result_path" end + create_table "site_configs", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "value" + t.string "var", null: false + t.index ["var"], name: "index_site_configs_on_var", unique: true + end + create_table "sponsorships", force: :cascade do |t| t.text "blurb_html" t.datetime "created_at", null: false