From 45935db5f3b601422b5b556fbf94eac779a44759 Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Fri, 25 Oct 2024 13:09:02 -0500 Subject: [PATCH 001/666] Remove dependency on stock exchange table (#1368) --- app/models/provider/marketstack.rb | 3 +- app/models/security.rb | 3 +- app/models/security/importer.rb | 33 ++++++++++--------- config/initializers/good_job.rb | 2 +- .../20241025174650_add_mic_to_securities.rb | 10 ++++++ db/schema.rb | 8 ++--- 6 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 db/migrate/20241025174650_add_mic_to_securities.rb diff --git a/app/models/provider/marketstack.rb b/app/models/provider/marketstack.rb index 5a1b8de9..10e2aa5d 100644 --- a/app/models/provider/marketstack.rb +++ b/app/models/provider/marketstack.rb @@ -40,7 +40,8 @@ class Provider::Marketstack { name: ticker["name"], symbol: ticker["symbol"], - exchange: exchange_mic || ticker.dig("stock_exchange", "mic"), + exchange_mic: exchange_mic || ticker.dig("stock_exchange", "mic"), + exchange_acronym: ticker.dig("stock_exchange", "acronym"), country_code: ticker.dig("stock_exchange", "country_code") } end diff --git a/app/models/security.rb b/app/models/security.rb index 784d0b68..196835ad 100644 --- a/app/models/security.rb +++ b/app/models/security.rb @@ -3,7 +3,8 @@ class Security < ApplicationRecord has_many :trades, dependent: :nullify, class_name: "Account::Trade" - validates :ticker, presence: true, uniqueness: { case_sensitive: false } + validates :ticker, presence: true + validates :ticker, uniqueness: { scope: :exchange_mic, case_sensitive: false } def current_price @current_price ||= Security::Price.find_price(ticker:, date: Date.current) diff --git a/app/models/security/importer.rb b/app/models/security/importer.rb index 4970170b..ed515067 100644 --- a/app/models/security/importer.rb +++ b/app/models/security/importer.rb @@ -7,21 +7,24 @@ class Security::Importer def import securities = @provider.fetch_tickers(exchange_mic: @stock_exchange)&.tickers - stock_exchanges = StockExchange.where(mic: securities.map { |s| s[:exchange] }).index_by(&:mic) - existing_securities = Security.where(ticker: securities.map { |s| s[:symbol] }, stock_exchange_id: stock_exchanges.values.map(&:id)).pluck(:ticker, :stock_exchange_id).to_set + # Deduplicate securities based on ticker and exchange_mic + securities_to_create = securities + .map do |security| + { + name: security[:name], + ticker: security[:symbol], + country_code: security[:country_code], + exchange_mic: security[:exchange_mic], + exchange_acronym: security[:exchange_acronym] + } + end + .compact + .uniq { |security| [ security[:ticker], security[:exchange_mic] ] } - securities_to_create = securities.map do |security| - stock_exchange_id = stock_exchanges[security[:exchange]]&.id - next if existing_securities.include?([ security[:symbol], stock_exchange_id ]) - - { - name: security[:name], - ticker: security[:symbol], - stock_exchange_id: stock_exchange_id, - country_code: security[:country_code] - } - end.compact - - Security.insert_all(securities_to_create) unless securities_to_create.empty? + Security.upsert_all( + securities_to_create, + unique_by: [ :ticker, :exchange_mic ], + update_only: [ :name, :country_code, :exchange_acronym ] + ) unless securities_to_create.empty? end end diff --git a/config/initializers/good_job.rb b/config/initializers/good_job.rb index c3794ad6..5d8aae25 100644 --- a/config/initializers/good_job.rb +++ b/config/initializers/good_job.rb @@ -14,7 +14,7 @@ Rails.application.configure do # Auth for jobs admin dashboard ActiveSupport.on_load(:good_job_application_controller) do before_action do - raise ActionController::RoutingError.new("Not Found") unless current_user&.super_admin? + raise ActionController::RoutingError.new("Not Found") unless current_user&.super_admin? || Rails.env.development? end def current_user diff --git a/db/migrate/20241025174650_add_mic_to_securities.rb b/db/migrate/20241025174650_add_mic_to_securities.rb new file mode 100644 index 00000000..1d907141 --- /dev/null +++ b/db/migrate/20241025174650_add_mic_to_securities.rb @@ -0,0 +1,10 @@ +class AddMicToSecurities < ActiveRecord::Migration[7.2] + def change + add_column :securities, :exchange_mic, :string + add_column :securities, :exchange_acronym, :string + + remove_column :securities, :stock_exchange_id, :uuid + + add_index :securities, [ :ticker, :exchange_mic ], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index f008ff6f..7445d127 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_10_24_142537) do +ActiveRecord::Schema[7.2].define(version: 2024_10_25_174650) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -479,9 +479,10 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_24_142537) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "country_code" - t.uuid "stock_exchange_id" + t.string "exchange_mic" + t.string "exchange_acronym" t.index ["country_code"], name: "index_securities_on_country_code" - t.index ["stock_exchange_id"], name: "index_securities_on_stock_exchange_id" + t.index ["ticker", "exchange_mic"], name: "index_securities_on_ticker_and_exchange_mic", unique: true end create_table "security_prices", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -603,7 +604,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_24_142537) do add_foreign_key "imports", "families" add_foreign_key "institutions", "families" add_foreign_key "merchants", "families" - add_foreign_key "securities", "stock_exchanges" add_foreign_key "sessions", "impersonation_sessions", column: "active_impersonator_session_id" add_foreign_key "sessions", "users" add_foreign_key "taggings", "tags" From 2adb54da99fc6af62fecc9f6c89cc4b772d9d521 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:55:50 -0400 Subject: [PATCH 002/666] Bump stripe from 13.0.1 to 13.0.2 (#1382) Bumps [stripe](https://github.com/stripe/stripe-ruby) from 13.0.1 to 13.0.2. - [Release notes](https://github.com/stripe/stripe-ruby/releases) - [Changelog](https://github.com/stripe/stripe-ruby/blob/master/CHANGELOG.md) - [Commits](https://github.com/stripe/stripe-ruby/compare/v13.0.1...v13.0.2) --- updated-dependencies: - dependency-name: stripe dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 27f6b877..ea133a42 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -417,7 +417,7 @@ GEM stimulus-rails (1.3.4) railties (>= 6.0.0) stringio (3.1.1) - stripe (13.0.1) + stripe (13.0.2) tailwindcss-rails (3.0.0) railties (>= 7.0.0) tailwindcss-ruby From d78f582af242850ed414404611a42f1dc66f0875 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:56:01 -0400 Subject: [PATCH 003/666] Bump ruby-lsp-rails from 0.3.20 to 0.3.21 (#1381) Bumps [ruby-lsp-rails](https://github.com/Shopify/ruby-lsp-rails) from 0.3.20 to 0.3.21. - [Release notes](https://github.com/Shopify/ruby-lsp-rails/releases) - [Commits](https://github.com/Shopify/ruby-lsp-rails/compare/v0.3.20...v0.3.21) --- updated-dependencies: - dependency-name: ruby-lsp-rails dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ea133a42..55d88361 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -381,7 +381,7 @@ GEM prism (>= 1.2, < 2.0) rbs (>= 3, < 4) sorbet-runtime (>= 0.5.10782) - ruby-lsp-rails (0.3.20) + ruby-lsp-rails (0.3.21) ruby-lsp (>= 0.20.0, < 0.21.0) ruby-progressbar (1.13.0) ruby-vips (2.2.2) @@ -412,7 +412,7 @@ GEM simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) smart_properties (1.17.0) - sorbet-runtime (0.5.11609) + sorbet-runtime (0.5.11618) stackprof (0.2.26) stimulus-rails (1.3.4) railties (>= 6.0.0) From 2141cbb041aeb2491a9bf43b694df99bf0339f59 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:56:25 -0400 Subject: [PATCH 004/666] Bump rails from 7.2.1.1 to 7.2.1.2 (#1380) Bumps [rails](https://github.com/rails/rails) from 7.2.1.1 to 7.2.1.2. - [Release notes](https://github.com/rails/rails/releases) - [Commits](https://github.com/rails/rails/compare/v7.2.1.1...v7.2.1.2) --- updated-dependencies: - dependency-name: rails dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 108 +++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 55d88361..9572090e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,29 +8,29 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.2.1.1) - actionpack (= 7.2.1.1) - activesupport (= 7.2.1.1) + actioncable (7.2.1.2) + actionpack (= 7.2.1.2) + activesupport (= 7.2.1.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.2.1.1) - actionpack (= 7.2.1.1) - activejob (= 7.2.1.1) - activerecord (= 7.2.1.1) - activestorage (= 7.2.1.1) - activesupport (= 7.2.1.1) + actionmailbox (7.2.1.2) + actionpack (= 7.2.1.2) + activejob (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) mail (>= 2.8.0) - actionmailer (7.2.1.1) - actionpack (= 7.2.1.1) - actionview (= 7.2.1.1) - activejob (= 7.2.1.1) - activesupport (= 7.2.1.1) + actionmailer (7.2.1.2) + actionpack (= 7.2.1.2) + actionview (= 7.2.1.2) + activejob (= 7.2.1.2) + activesupport (= 7.2.1.2) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.2.1.1) - actionview (= 7.2.1.1) - activesupport (= 7.2.1.1) + actionpack (7.2.1.2) + actionview (= 7.2.1.2) + activesupport (= 7.2.1.2) nokogiri (>= 1.8.5) racc rack (>= 2.2.4, < 3.2) @@ -39,35 +39,35 @@ GEM rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (7.2.1.1) - actionpack (= 7.2.1.1) - activerecord (= 7.2.1.1) - activestorage (= 7.2.1.1) - activesupport (= 7.2.1.1) + actiontext (7.2.1.2) + actionpack (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.2.1.1) - activesupport (= 7.2.1.1) + actionview (7.2.1.2) + activesupport (= 7.2.1.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.2.1.1) - activesupport (= 7.2.1.1) + activejob (7.2.1.2) + activesupport (= 7.2.1.2) globalid (>= 0.3.6) - activemodel (7.2.1.1) - activesupport (= 7.2.1.1) - activerecord (7.2.1.1) - activemodel (= 7.2.1.1) - activesupport (= 7.2.1.1) + activemodel (7.2.1.2) + activesupport (= 7.2.1.2) + activerecord (7.2.1.2) + activemodel (= 7.2.1.2) + activesupport (= 7.2.1.2) timeout (>= 0.4.0) - activestorage (7.2.1.1) - actionpack (= 7.2.1.1) - activejob (= 7.2.1.1) - activerecord (= 7.2.1.1) - activesupport (= 7.2.1.1) + activestorage (7.2.1.2) + actionpack (= 7.2.1.2) + activejob (= 7.2.1.2) + activerecord (= 7.2.1.2) + activesupport (= 7.2.1.2) marcel (~> 1.0) - activesupport (7.2.1.1) + activesupport (7.2.1.2) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) @@ -228,7 +228,7 @@ GEM rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) logger (1.6.1) - loofah (2.22.0) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -299,20 +299,20 @@ GEM rackup (2.1.0) rack (>= 3) webrick (~> 1.8) - rails (7.2.1.1) - actioncable (= 7.2.1.1) - actionmailbox (= 7.2.1.1) - actionmailer (= 7.2.1.1) - actionpack (= 7.2.1.1) - actiontext (= 7.2.1.1) - actionview (= 7.2.1.1) - activejob (= 7.2.1.1) - activemodel (= 7.2.1.1) - activerecord (= 7.2.1.1) - activestorage (= 7.2.1.1) - activesupport (= 7.2.1.1) + rails (7.2.1.2) + actioncable (= 7.2.1.2) + actionmailbox (= 7.2.1.2) + actionmailer (= 7.2.1.2) + actionpack (= 7.2.1.2) + actiontext (= 7.2.1.2) + actionview (= 7.2.1.2) + activejob (= 7.2.1.2) + activemodel (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) bundler (>= 1.15.0) - railties (= 7.2.1.1) + railties (= 7.2.1.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -326,9 +326,9 @@ GEM rails-settings-cached (2.9.5) activerecord (>= 5.0.0) railties (>= 5.0.0) - railties (7.2.1.1) - actionpack (= 7.2.1.1) - activesupport (= 7.2.1.1) + railties (7.2.1.2) + actionpack (= 7.2.1.2) + activesupport (= 7.2.1.2) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) From 439e50bb3ea0403bd268b21003e35cbf3a092eac Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:56:36 -0400 Subject: [PATCH 005/666] Bump pg from 1.5.8 to 1.5.9 (#1379) Bumps [pg](https://github.com/ged/ruby-pg) from 1.5.8 to 1.5.9. - [Changelog](https://github.com/ged/ruby-pg/blob/master/History.md) - [Commits](https://github.com/ged/ruby-pg/compare/v1.5.8...v1.5.9) --- updated-dependencies: - dependency-name: pg dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9572090e..35b39701 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -277,7 +277,7 @@ GEM parser (3.3.5.0) ast (~> 2.4.1) racc - pg (1.5.8) + pg (1.5.9) prism (1.2.0) propshaft (1.1.0) actionpack (>= 7.0.0) From 277fb3dc39a39bb753c1ea22f717a15cb03942de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Oct 2024 07:56:44 -0400 Subject: [PATCH 006/666] Bump mocha from 2.4.5 to 2.5.0 (#1378) Bumps [mocha](https://github.com/freerange/mocha) from 2.4.5 to 2.5.0. - [Changelog](https://github.com/freerange/mocha/blob/main/RELEASE.md) - [Commits](https://github.com/freerange/mocha/compare/v2.4.5...v2.5.0) --- updated-dependencies: - dependency-name: mocha dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 35b39701..dc2c8dee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,7 +241,7 @@ GEM mini_magick (4.13.2) mini_mime (1.1.5) minitest (5.25.1) - mocha (2.4.5) + mocha (2.5.0) ruby2_keywords (>= 0.0.5) msgpack (1.7.2) multipart-post (2.4.1) From 3cd364af0993b5ae08a28af542287093a3422c4e Mon Sep 17 00:00:00 2001 From: Guillem Arias Fauste Date: Mon, 28 Oct 2024 13:02:49 +0100 Subject: [PATCH 007/666] fix bulk action bar positioning (#1370) * fix bulk action bar positioning * remove extra space --- app/javascript/controllers/bulk_select_controller.js | 2 +- app/views/transactions/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/controllers/bulk_select_controller.js b/app/javascript/controllers/bulk_select_controller.js index e72704c7..104d2aa6 100644 --- a/app/javascript/controllers/bulk_select_controller.js +++ b/app/javascript/controllers/bulk_select_controller.js @@ -126,7 +126,7 @@ export default class extends Controller { _updateSelectionBar() { const count = this.selectedIdsValue.length; this.selectionBarTextTarget.innerText = `${count} ${this._pluralizedResourceName()} selected`; - this.selectionBarTarget.hidden = count === 0; + this.selectionBarTarget.classList.toggle("hidden", count === 0); this.selectionBarTarget.querySelector("input[type='checkbox']").checked = count > 0; } diff --git a/app/views/transactions/index.html.erb b/app/views/transactions/index.html.erb index 8626da49..1055496f 100644 --- a/app/views/transactions/index.html.erb +++ b/app/views/transactions/index.html.erb @@ -10,7 +10,7 @@ <%= render "transactions/searches/search" %> <% if @transaction_entries.present? %> -