diff --git a/config/application.rb b/config/application.rb index 4b44e13a..420458f6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,7 @@ module Sagittarius class Application < Rails::Application - config.load_defaults 7.2 + config.load_defaults 8.0 # Use SQL instead of Active Record's schema dumper when creating the database. # This is necessary if your schema can't be completely dumped by the schema dumper, diff --git a/config/initializers/rails_code_statistics.rb b/config/initializers/rails_code_statistics.rb new file mode 100644 index 00000000..2effa547 --- /dev/null +++ b/config/initializers/rails_code_statistics.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +return unless defined?(Rails::Command::StatsCommand) + +Rails::CodeStatistics.directories.clear +Rails::CodeStatistics.test_types.clear + +%w[Controllers Finders GraphQL GRPC Jobs Mailers Models Policies Services].each do |type| + Rails::CodeStatistics.register_directory(type, "app/#{type.downcase}") +end + +%w[Config DB Lib Tooling].each do |type| + Rails::CodeStatistics.register_directory(type, type.downcase) +end + +%w[Config Finders GraphQL GRPC Lib Models Policies Requests Services Tooling].each do |type| + Rails::CodeStatistics.register_directory("#{type} specs", "spec/#{type.downcase}", test_directory: true) +end + +%w[factories support].each do |type| + Rails::CodeStatistics.register_directory("Spec #{type}", "spec/#{type}", test_directory: true) +end diff --git a/lib/sagittarius/database/schema_migrations/migrations.rb b/lib/sagittarius/database/schema_migrations/migrations.rb index 98f60b66..3f940209 100644 --- a/lib/sagittarius/database/schema_migrations/migrations.rb +++ b/lib/sagittarius/database/schema_migrations/migrations.rb @@ -34,6 +34,7 @@ def touch_all def load_all return if version_filenames.empty? + return unless @context.connection.pool.schema_migration.table_exists? values = version_filenames.map { |vf| "('#{@context.connection.quote_string(vf)}')" } diff --git a/lib/tasks/statistics.rake b/lib/tasks/statistics.rake deleted file mode 100644 index 91248f24..00000000 --- a/lib/tasks/statistics.rake +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require 'rails/code_statistics' - -task stats: :code_stats - -task code_stats: :environment do - %w[Finders Graphql Grpc Policies Services].each_with_index do |type, i| - STATS_DIRECTORIES.insert i + 5, [type, "app/#{type.downcase}"] - end - - STATS_DIRECTORIES.insert 9, %w[Tooling tooling] -end diff --git a/spec/lib/sagittarius/database/schema_migrations/migrations_spec.rb b/spec/lib/sagittarius/database/schema_migrations/migrations_spec.rb index 770bf6f3..ab09e7f3 100644 --- a/spec/lib/sagittarius/database/schema_migrations/migrations_spec.rb +++ b/spec/lib/sagittarius/database/schema_migrations/migrations_spec.rb @@ -80,6 +80,7 @@ let(:filenames) { %w[123 456 789] } it 'inserts the missing versions into schema_migrations' do + allow(connection).to receive(:quote_string).with('schema_migrations').and_return('schema_migrations') filenames.each do |filename| allow(connection).to receive(:quote_string).with(filename).and_return(filename) end @@ -96,6 +97,18 @@ ON CONFLICT DO NOTHING SQL end + + it 'does nothing if schema_migrations table does not exist' do + allow(connection).to receive(:execute) + + schema_migration = connection.pool.schema_migration + allow(connection.pool).to receive(:schema_migration).and_return(schema_migration) + allow(schema_migration).to receive(:table_exists?).and_return(false) + + migrations.load_all + + expect(connection).not_to have_received(:execute) + end end end end