Module: PgRls::ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper

Defined in:
lib/pg_rls/active_record/connection_adapters/postgre_sql/schema_dumper.rb

Overview

This module is responsible for changing the ‘create_table` method to `create_rls_table` when the table is a RLS table.

Instance Method Summary collapse

Instance Method Details

#table(table_name, stream) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pg_rls/active_record/connection_adapters/postgre_sql/schema_dumper.rb', line 23

def table(table_name, stream)
  original_table_method = method(:table).super_method
  stream_content = dump_table_to_string(original_table_method, table_name)

  if rls_tenant_table?(table_name)
    @rls_tenant_table = stream_content.gsub!("create_table", "create_rls_tenant_table").to_s
    return
  elsif rls_table?(table_name)
    stream_content.gsub!("create_table", "create_rls_table")
  end

  stream.print stream_content
end

#tables(stream) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pg_rls/active_record/connection_adapters/postgre_sql/schema_dumper.rb', line 10

def tables(stream)
  tmp_stream = StringIO.new
  super(tmp_stream)

  stream_content = tmp_stream.string

  return stream.puts stream_content if @rls_tenant_table.nil?

  stream.puts @rls_tenant_table
  stream.puts unless stream_content.nil?
  stream.puts stream_content.chomp
end