Sha256: 4214e35ff7ef710230fdeac1ee7f3ba1d0712a90a7da2822d8df9c87726c3f66

Contents?: true

Size: 1.89 KB

Versions: 42

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require_relative "../github/base"

module Neetob
  class CLI
    module Code
      class Audit < Github::Base
        attr_accessor :sandbox, :apps

        def initialize(apps, sandbox = false)
          super()
          @apps = apps
          @sandbox = sandbox
        end

        def run
          matching_apps = find_all_matching_apps_or_repos(apps, :github, sandbox)
          ui.info("\nListing apps and their tables that doesn't have uuid as primary key type:-")
          has_found_tables_without_uuid = false
          matching_apps.each do |app|
            begin
              db_schema = Base64.decode64(client.contents(app, path: "./db/schema.rb").content)
              tables_without_uuid = find_tables_without_uuid_as_primary_key(db_schema).compact
              if !tables_without_uuid.nil?
                has_found_tables_without_uuid = true
                print_app_and_tables(app, tables_without_uuid)
              end
            rescue Octokit::NotFound
              ui.error("There is no \"db/schema.rb\" file in the \"#{app}\" app.")
            rescue StandardError => e
              ExceptionHandler.new(e).process
            end
          end
          ui.info("No apps found to have tables without uuid as primary key type") if !has_found_tables_without_uuid
        end

        private

          def find_tables_without_uuid_as_primary_key(db_schema)
            create_table_regex = /create_table.*?,\s*force:\s*:cascade\s*do\s*\|t\|/
            db_schema.scan(create_table_regex).map do |create_table_line|
              !create_table_line.include?("id: :uuid") ? create_table_line.scan(/"([^"]+)"/).flatten.first : nil
            end
          end

          def print_app_and_tables(app, tables)
            ui.info("\n#{app}:-")
            tables.each do |table|
              ui.say(" ↳#{table}")
            end
          end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
neetob-0.5.4 lib/neetob/cli/code/audit.rb
neetob-0.5.3 lib/neetob/cli/code/audit.rb
neetob-0.5.2 lib/neetob/cli/code/audit.rb
neetob-0.5.1 lib/neetob/cli/code/audit.rb
neetob-0.5.0 lib/neetob/cli/code/audit.rb
neetob-0.4.37 lib/neetob/cli/code/audit.rb
neetob-0.4.36 lib/neetob/cli/code/audit.rb
neetob-0.4.35 lib/neetob/cli/code/audit.rb
neetob-0.4.34 lib/neetob/cli/code/audit.rb
neetob-0.4.33 lib/neetob/cli/code/audit.rb
neetob-0.4.32 lib/neetob/cli/code/audit.rb
neetob-0.4.31 lib/neetob/cli/code/audit.rb
neetob-0.4.30 lib/neetob/cli/code/audit.rb
neetob-0.4.28 lib/neetob/cli/code/audit.rb
neetob-0.4.27 lib/neetob/cli/code/audit.rb
neetob-0.4.26 lib/neetob/cli/code/audit.rb
neetob-0.4.24 lib/neetob/cli/code/audit.rb
neetob-0.4.23 lib/neetob/cli/code/audit.rb
neetob-0.4.22 lib/neetob/cli/code/audit.rb
neetob-0.4.21 lib/neetob/cli/code/audit.rb