Skip to content

Commit

Permalink
Prevent Rails 7.1 create_schema from being added to db/schema.rb (#276)
Browse files Browse the repository at this point in the history
* Prevent Rails 7.1 create_schema from being added to db/schema.rb as schemas are managed by Apartment not ActiveRecord like they would be in a vanilla Rails setup.

* Need to also require the abstract superclass

* Only suppress create_schema when use_schemas = true
  • Loading branch information
patbenatar authored Sep 27, 2024
1 parent 44ee01b commit 0c0faf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/apartment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
require_relative 'apartment/active_record/schema_migration'
require_relative 'apartment/active_record/internal_metadata'

if ActiveRecord.version.release >= Gem::Version.new('7.1')
require_relative 'apartment/active_record/postgres/schema_dumper'
end

# Apartment main definitions
module Apartment
class << self
Expand Down
12 changes: 12 additions & 0 deletions lib/apartment/active_record/postgres/schema_dumper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This patch prevents `create_schema` from being added to db/schema.rb as schemas are managed by Apartment
# not ActiveRecord like they would be in a vanilla Rails setup.

require "active_record/connection_adapters/abstract/schema_dumper"
require "active_record/connection_adapters/postgresql/schema_dumper"

class ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper
alias_method :_original_schemas, :schemas
def schemas(stream)
_original_schemas(stream) unless Apartment.use_schemas
end
end

0 comments on commit 0c0faf1

Please sign in to comment.