diff --git a/Gemfile b/Gemfile index 49d750f2ed3..a4060f91c86 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem "bootsnap", require: false gem "clockwork", require: false gem "parallel" gem "puma", "~> 6.5" -gem "rails", "~> 7.1.5.1" +gem "rails", "~> 7.2" gem "redis" gem "sidekiq" gem "sidekiq-throttled", "1.4.0" # '1.5.0' was losing some jobs @@ -34,10 +34,10 @@ gem "discard", "~> 1.2" gem "kaminari-activerecord" gem "paper_trail" gem "pg" +gem "strong_migrations" gem "ransack" gem "scenic" gem "with_advisory_lock" -gem "strong_migrations" # Currencies, Countries, Timezones... gem "bigdecimal" diff --git a/Gemfile.lock b/Gemfile.lock index 22dc1edf0da..b19f4b39982 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,51 +38,46 @@ GEM specs: aasm (5.5.0) concurrent-ruby (~> 1.0) - actioncable (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) + actioncable (7.2.2) + actionpack (= 7.2.2) + activesupport (= 7.2.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.5.1) - actionpack (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.2) + actionpack (= 7.2.2) + activejob (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) + mail (>= 2.8.0) + actionmailer (7.2.2) + actionpack (= 7.2.2) + actionview (= 7.2.2) + activejob (= 7.2.2) + activesupport (= 7.2.2) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.5.1) - actionview (= 7.1.5.1) - activesupport (= 7.1.5.1) + actionpack (7.2.2) + actionview (= 7.2.2) + activesupport (= 7.2.2) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.5.1) - actionpack (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + useragent (~> 0.16) + actiontext (7.2.2) + actionpack (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.5.1) - activesupport (= 7.1.5.1) + actionview (7.2.2) + activesupport (= 7.2.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -93,8 +88,8 @@ GEM activestorage (>= 6.1.4) activesupport (>= 6.1.4) marcel (>= 1.0.3) - activejob (7.1.5.1) - activesupport (= 7.1.5.1) + activejob (7.2.2) + activesupport (= 7.2.2) globalid (>= 0.3.6) activejob-traceable (0.4.2) activejob @@ -102,23 +97,23 @@ GEM activejob-uniqueness (0.4.0) activejob (>= 4.2, < 8.1) redlock (>= 2.0, < 3) - activemodel (7.1.5.1) - activesupport (= 7.1.5.1) - activerecord (7.1.5.1) - activemodel (= 7.1.5.1) - activesupport (= 7.1.5.1) + activemodel (7.2.2) + activesupport (= 7.2.2) + activerecord (7.2.2) + activemodel (= 7.2.2) + activesupport (= 7.2.2) timeout (>= 0.4.0) - activestorage (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activesupport (= 7.1.5.1) + activestorage (7.2.2) + actionpack (= 7.2.2) + activejob (= 7.2.2) + activerecord (= 7.2.2) + activesupport (= 7.2.2) marcel (~> 1.0) - activesupport (7.1.5.1) + activesupport (7.2.2) base64 benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) @@ -126,7 +121,7 @@ GEM minitest (>= 5.1) mutex_m securerandom (>= 0.3) - tzinfo (~> 2.0) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) adyen-ruby-api-library (7.3.1) @@ -642,7 +637,7 @@ GEM opentelemetry-semantic_conventions (1.10.1) opentelemetry-api (~> 1.0) os (1.1.4) - paper_trail (15.1.0) + paper_trail (16.0.0) activerecord (>= 6.1) request_store (~> 1.4) parallel (1.26.3) @@ -654,36 +649,35 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - psych (5.1.2) + psych (5.2.0) stringio public_suffix (5.1.1) puma (6.5.0) nio4r (~> 2.0) racc (1.8.1) - rack (2.2.11) + rack (3.1.8) rack-cors (1.1.1) rack (>= 2.0.0) - rack-session (1.0.2) - rack (< 3) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.1) - rack (< 3) - webrick - rails (7.1.5.1) - actioncable (= 7.1.5.1) - actionmailbox (= 7.1.5.1) - actionmailer (= 7.1.5.1) - actionpack (= 7.1.5.1) - actiontext (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activemodel (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + rackup (2.2.1) + rack (>= 3) + rails (7.2.2) + actioncable (= 7.2.2) + actionmailbox (= 7.2.2) + actionmailer (= 7.2.2) + actionpack (= 7.2.2) + actiontext (= 7.2.2) + actionview (= 7.2.2) + activejob (= 7.2.2) + activemodel (= 7.2.2) + activerecord (= 7.2.2) + activestorage (= 7.2.2) + activesupport (= 7.2.2) bundler (>= 1.15.0) - railties (= 7.1.5.1) + railties (= 7.2.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -694,10 +688,10 @@ GEM rails-i18n (7.0.10) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) - railties (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) - irb + railties (7.2.2) + actionpack (= 7.2.2) + activesupport (= 7.2.2) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) @@ -706,7 +700,7 @@ GEM rake (13.2.1) rake-compiler (1.2.9) rake - ransack (4.1.1) + ransack (4.2.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -716,7 +710,7 @@ GEM rb_sys (0.9.108) rbs (3.6.1) logger - rdoc (6.7.0) + rdoc (6.8.1) psych (>= 4.0.0) redis (5.3.0) redis-client (>= 0.22.0) @@ -902,6 +896,7 @@ GEM unaccent (0.4.0) unicode-display_width (2.6.0) uniform_notifier (1.16.0) + useragent (0.16.10) valvat (2.0.1) rexml (>= 3.3.6, < 4.0.0) version_gem (1.1.4) @@ -913,7 +908,6 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.8.2) websocket-driver (0.7.7) base64 websocket-extensions (>= 0.1.0) @@ -921,7 +915,7 @@ GEM with_advisory_lock (5.1.0) activerecord (>= 6.1) zeitwerk (>= 2.6) - zeitwerk (2.6.18) + zeitwerk (2.7.1) PLATFORMS aarch64-linux @@ -992,7 +986,7 @@ DEPENDENCIES pg puma (~> 6.5) rack-cors - rails (~> 7.1.5.1) + rails (~> 7.2) ransack redis rspec-graphql_matchers diff --git a/app/models/charge.rb b/app/models/charge.rb index b524b4682bd..626ca603d25 100644 --- a/app/models/charge.rb +++ b/app/models/charge.rb @@ -32,6 +32,8 @@ class Charge < ApplicationRecord REGROUPING_PAID_FEES_OPTIONS = %i[invoice].freeze enum :charge_model, CHARGE_MODELS + + attribute :regroup_paid_fees, :integer enum :regroup_paid_fees, REGROUPING_PAID_FEES_OPTIONS validate :validate_amount, if: -> { standard? } diff --git a/bin/setup b/bin/setup index 3cd5a9d7801..7b64c295b0b 100755 --- a/bin/setup +++ b/bin/setup @@ -1,8 +1,8 @@ #!/usr/bin/env ruby require "fileutils" -# path to your application root. APP_ROOT = File.expand_path("..", __dir__) +APP_NAME = "lago-api" def system!(*args) system(*args, exception: true) diff --git a/config/application.rb b/config/application.rb index eb74e467247..ed0823c7bee 100644 --- a/config/application.rb +++ b/config/application.rb @@ -8,7 +8,10 @@ module LagoApi class Application < Rails::Application - config.load_defaults(7.1) + config.load_defaults 7.2 + + # Disable YJIT as we are not ready yet + config.yjit = false # TODO: Should be turned to false config.add_autoload_paths_to_load_path = true diff --git a/config/environments/development.rb b/config/environments/development.rb index f52a39f4351..301a47be61d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -25,11 +25,13 @@ config.cache_store = :redis_cache_store, {url: ENV["LAGO_REDIS_CACHE_URL"], db: 3} if Rails.root.join("tmp/caching-dev.txt").exist? + config.cache_store = :memory_store config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false + config.cache_store = :null_store end config.active_storage.service = if ENV["LAGO_USE_AWS_S3"].present? && ENV["LAGO_USE_AWS_S3"] == "true" @@ -47,11 +49,13 @@ config.active_support.disallowed_deprecation_warnings = [] config.active_record.migration_error = :page_load config.active_record.verbose_query_logs = true + config.active_job.verbose_enqueue_logs = true - logger = ActiveSupport::Logger.new($stdout) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + config.action_view.annotate_rendered_view_with_filenames = true config.action_controller.raise_on_missing_callback_actions = true config.hosts << "api.lago.dev" @@ -59,6 +63,7 @@ config.license_url = "http://license:3000" + config.action_mailer.perform_caching = false config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp diff --git a/config/environments/production.rb b/config/environments/production.rb index 8fdaa5d4c34..56d0e8fef71 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -24,29 +24,29 @@ :local end + config.assume_ssl = true + config.force_ssl = false + + if ENV["RAILS_LOG_TO_STDOUT"].present? && ENV["RAILS_LOG_TO_STDOUT"] == "true" + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + end + + config.log_tags = [:request_id] + config.log_level = if ENV["LAGO_LOG_LEVEL"].present? && ENV["LAGO_LOG_LEVEL"] != "" ENV["LAGO_LOG_LEVEL"].downcase.to_sym else :info end - config.assume_ssl = true - config.force_ssl = false - - config.log_tags = [:request_id] config.action_mailer.perform_caching = false config.i18n.fallbacks = true - config.active_support.report_deprecations = false - config.log_formatter = ::Logger::Formatter.new - if ENV["RAILS_LOG_TO_STDOUT"].present? && ENV["RAILS_LOG_TO_STDOUT"] == "true" - logger = ActiveSupport::Logger.new($stdout) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end - - # Do not dump schema after migrations. + config.active_support.report_deprecations = false config.active_record.dump_schema_after_migration = false + config.active_record.attributes_for_inspect = [:id] if ENV["LAGO_MEMCACHE_SERVERS"].present? config.cache_store = :mem_cache_store, ENV["LAGO_MEMCACHE_SERVERS"].split(",") diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 3a292efb155..6b143dacfaa 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "active_support/core_ext/integer/time" +require "opentelemetry/sdk" Rails.application.configure do # Used for GraphiQL @@ -36,9 +37,9 @@ config.log_formatter = ::Logger::Formatter.new if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new($stdout) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } end config.active_record.dump_schema_after_migration = false diff --git a/config/environments/test.rb b/config/environments/test.rb index 220d26c5a5c..d0eec55e0d7 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -20,29 +20,30 @@ config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :null_store config.action_dispatch.show_exceptions = :rescuable config.action_controller.allow_forgery_protection = false config.active_storage.service = :test config.action_mailer.perform_caching = false config.action_mailer.delivery_method = :test - - config.active_record.encryption.primary_key = "test" - config.active_record.encryption.deterministic_key = "test" - config.active_record.encryption.key_derivation_salt = "test" + config.action_mailer.default_url_options = {host: "www.example.com"} config.active_support.deprecation = :stderr - config.active_support.disallowed_deprecation = :raise config.active_support.disallowed_deprecation_warnings = [] + config.action_controller.raise_on_missing_callback_actions = true + + config.active_record.encryption.primary_key = "test" + config.active_record.encryption.deterministic_key = "test" + config.active_record.encryption.key_derivation_salt = "test" + config.active_job.queue_adapter = :test config.license_url = "http://license.lago" Dotenv.load - # Configure the redis cache store but always set the null_store by default - # Use `context '...', cache: :redis` to enable the redis cache store in specs if ENV["LAGO_REDIS_CACHE_URL"].present? redis_store_config = { url: ENV["LAGO_REDIS_CACHE_URL"], @@ -51,6 +52,4 @@ config.cache_store = :redis_cache_store, redis_store_config end config.cache_store = :null_store - - config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb index d2bbb019a7c..d730bd2b586 100644 --- a/config/initializers/cors.rb +++ b/config/initializers/cors.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# NOTE: Read more: https://github.com/cyu/rack-cors +# Read more: https://github.com/cyu/rack-cors Rails.application.config.middleware.insert_before(0, Rack::Cors) do allow do diff --git a/config/initializers/enable_yjit.rb b/config/initializers/enable_yjit.rb deleted file mode 100644 index 6e167da0e24..00000000000 --- a/config/initializers/enable_yjit.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -if ENV["LAGO_ENABLE_YJIT"] == "true" && defined? RubyVM::YJIT.enable - Rails.application.config.after_initialize do - # Enable YJIT for the entire application - RubyVM::YJIT.enable - end -end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index bae81d63b4f..aad15d5b0fd 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -2,9 +2,9 @@ # Be sure to restart your server when you modify this file. -# Configure parameters to be filtered from the log file. Use this to limit dissemination of -# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported -# notations and behaviors. +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :secret_key + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :secret_key ] diff --git a/config/puma.rb b/config/puma.rb index 14243eed353..1587b54c9b3 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,7 +6,7 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) min_threads_count = ENV.fetch("RAILS_MIN_THREADS", 0) threads min_threads_count, max_threads_count diff --git a/db/schema.rb b/db/schema.rb index 663b59c6e6d..499a5d28262 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.1].define(version: 2025_02_20_085848) do +ActiveRecord::Schema[7.2].define(version: 2025_02_20_085848) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql"