Module: EnumTable::SchemaDumper

Extended by:
ActiveSupport::Concern
Defined in:
lib/enum_table/schema_dumper.rb

Instance Method Summary collapse

Instance Method Details

#ignore_tables_with_enum_tableObject



24
25
26
# File 'lib/enum_table/schema_dumper.rb', line 24

def ignore_tables_with_enum_table
  ignore_tables_without_enum_table + @connection.enum_tables << 'enum_tables'
end

#tables_with_enum_table(stream) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/enum_table/schema_dumper.rb', line 10

def tables_with_enum_table(stream)
  tables_without_enum_table(stream)
  table_names = @connection.enum_tables
  table_names.each do |table_name|
    stream.puts "  create_enum_table #{table_name.inspect}, force: true do |t|"
    enum_table_column(stream, table_name, 'value', SchemaStatements::DEFAULT_VALUE_ATTRIBUTES)
    @connection.execute("SELECT id, value FROM #{@connection.quote_table_name table_name} ORDER BY id").each do |row|
      stream.puts "    t.add #{row[1].to_s.inspect}, #{row[0]}"
    end
    stream.puts "  end"
    stream.puts
  end
end