diff --git a/fx.gemspec b/fx.gemspec index b106f89..e50009b 100644 --- a/fx.gemspec +++ b/fx.gemspec @@ -27,5 +27,7 @@ Gem::Specification.new do |spec| spec.add_dependency "activerecord", ">= 7.0" spec.add_dependency "railties", ">= 7.0" + spec.add_development_dependency "sqlite3" + spec.required_ruby_version = ">= 3.0" end diff --git a/lib/fx.rb b/lib/fx.rb index c46508f..60de9f0 100644 --- a/lib/fx.rb +++ b/lib/fx.rb @@ -21,7 +21,7 @@ module Fx def self.load ActiveRecord::Migration::CommandRecorder.include(Fx::CommandRecorder) ActiveRecord::ConnectionAdapters::AbstractAdapter.include(Fx::Statements) - ActiveRecord::SchemaDumper.prepend(Fx::SchemaDumper) + ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper.prepend(Fx::SchemaDumper) true end diff --git a/spec/fx/schema_dumper_spec.rb b/spec/fx/schema_dumper_spec.rb index 0999ad1..3ac4990 100644 --- a/spec/fx/schema_dumper_spec.rb +++ b/spec/fx/schema_dumper_spec.rb @@ -113,6 +113,40 @@ expect(output).to include("EXECUTE FUNCTION uppercase_users_name()") end + context "with a sqlite adapter" do + let(:sqlite_connection) do + ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") + ActiveRecord::Base.connection + end + after :each do + sqlite_connection.disconnect! + end + + it "does not dump functions or triggers for SQLite connections" do + sql_definition = <<~EOS + CREATE OR REPLACE FUNCTION my_function() + RETURNS text AS $$ + BEGIN + RETURN 'test'; + END; + $$ LANGUAGE plpgsql; + EOS + connection.create_function :my_function, sql_definition: sql_definition + connection.create_table :my_table + postgres_stream = StringIO.new + sqlite_stream = StringIO.new + + dump(connection: connection, stream: postgres_stream) + dump(connection: sqlite_connection, stream: sqlite_stream) + + output = postgres_stream.string + + expect(output).to include("create_function :my_function") + expect(output).to include("RETURN 'test';") + expect(output).to include('create_table "my_table"') + end + end + def dump(connection:, stream:) if Rails.version >= "7.2" ActiveRecord::SchemaDumper.dump(connection.pool, stream)