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