Sha256: c9df0818a8ae11bea69e9a5001a483d392f6e5c0e8969c24f11779fd3ceaf4ed
Contents?: true
Size: 807 Bytes
Versions: 2
Compression:
Stored size: 807 Bytes
Contents
require "#{Dir.pwd}/config/environment.rb" db_config = YAML.load_file("#{Dir.pwd}/config/database.yml") ActiveRecord::Base.establish_connection db_config['development'] db_connection = ActiveRecord::Base.connection table_names = db_connection.tables table_names.shift # remove rails schema_migration table tables = table_names.map do |table_name| { name: table_name } end associations = table_names.flat_map do |table| table.classify.constantize.reflections.map do |reflection| { source: tables.index(name: table), target: tables.index(name: reflection[1].table_name), value: rand(1..5) } end end attrs = table_names.map do |table| { table: table, attrs: db_connection.columns(table).map(&:name) } end puts YAML.dump({nodes: tables, links: associations, attributes: attrs})
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
schemap-0.0.2 | lib/schemap.rb |
schemap-0.0.1 | lib/schemap.rb |