Advertisement
terraplane

Untitled

Oct 11th, 2023 (edited)
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.30 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. desc 'Create diagrams based on database current schema'
  4. namespace :db do # rubocop:disable Metrics/BlockLength
  5.   task diagrams: :environment do # rubocop:disable Metrics/BlockLength
  6.     current_version = ActiveRecord::Migrator.current_version
  7.     current_time = Time.zone.now.strftime '%d.%m.%Y %H:%m:%S'
  8.     path_to_diagrams = Rails.root.join('doc')
  9.  
  10.     FileUtils.mkdir_p(path_to_diagrams)
  11.  
  12.     options = %w[
  13.       filetype=png
  14.       orientation=horizontal
  15.     ]
  16.  
  17.     groups = {
  18.       orders: %w[
  19.         User
  20.         Order
  21.       ],
  22.       blog: %w[
  23.         Article
  24.         Post
  25.       ]
  26.     }
  27.  
  28.     # complete diagram
  29.     lines = [
  30.       'rake erd',
  31.       options.join(' '),
  32.       "filename='#{path_to_diagrams}/erd_complete'",
  33.       "title='#{current_time} - AppName complete diagram (v#{current_version})'"
  34.     ]
  35.     system(lines.join(' '))
  36.  
  37.     groups.each do |k, v|
  38.       lines = [
  39.         'rake erd',
  40.         options.join(' '),
  41.         "filename='#{path_to_diagrams}/erd_#{k}'",
  42.         "only=#{v.join(',')}",
  43.         "title='#{current_time} - AppName #{k.to_s.humanize} diagram (v#{current_version})'"
  44.       ]
  45.       system(lines.join(' '))
  46.     end
  47.  
  48.     system("railroady -lamM | neato -Tpng > #{path_to_diagrams}/models_complete.png")
  49.   end
  50. end
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement