<commit_before>module Deployinator
  module Stacks
    module Smart
      def smart_git_repo_url
        "<EMAIL>:xfactoradvertising/smart.git"
      end

      def smart_user
        'www-data'
      end

      def smart_stage_ip
        '192.168.127.12'
      end

      def checkout_root
        "/tmp"
      end

      def site_root
        '/var/www/sites'
      end

      def site_path
        "#{site_root}/#{stack}"
      end

      def smart_git_checkout_path
        "#{checkout_root}/#{stack}"
      end

      def smart_dev_version
        %x{cat #{smart_git_checkout_path}/version.txt}
      end

      def smart_dev_build
        Version.get_build(smart_dev_version)
      end

      def smart_stage_version
        %x{ssh #{smart_user}@#{smart_stage_ip} 'cat #{site_path}/version.txt'}
      end

      def smart_stage_build
        Version.get_build(smart_stage_version)
      end

      def smart_head_build
        %x{git ls-remote #{smart_git_repo_url} HEAD | cut -c1-7}.chomp
      end

      def smart_dev(options={})
        old_build = Version.get_build(smart_dev_version)

        git_cmd = old_build ? :git_freshen_clone : :github_clone
        send(git_cmd, stack, 'sh -c')

        git_bump_version stack, ''

        build = smart_head_build

        begin
          # take application offline (maintenance mode)
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan --env=dev down || true} # return true so command is non-fatal

          # sync site files to final destination
          run_cmd %Q{rsync -av --delete --force --exclude='app/storage/' --exclude='public/assets/audio/' --exclude='public/assets/files/' --exclude='app/files/*' --exclude='/vendor/' --exclude='.git/' --exclude='.gitignore' --filter "protect .env.dev.php" #{smart_git_checkout_path}/ #{site_path}}

          # additionally sync top-level storage dirs (but not their contents)
          run_cmd %Q{rsync -lptgoDv --dirs --delete --force --exclude='.gitignore' --filter "protect .env.dev.php" #{smart_git_checkout_path}/app/storage/ #{site_path}/app/storage}

          # ensure storage is writable (shouldn't have to do this but running webserver as different user)
          run_cmd %Q{chmod 777 #{site_path}/app/storage/*}

          # smart-specific chmods
          run_cmd %Q{chmod 777 #{site_path}/app/storage/}
          run_cmd %Q{chmod 777 #{site_path}/public/assets/audio}
          run_cmd %Q{chmod 777 #{site_path}/public/assets/files}
          run_cmd %Q{chmod 777 #{site_path}/app/files}

          # install dependencies (vendor dir was probably completely removed via above)
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer install --no-dev}

          # run db migrations
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan migrate --env=dev}

          # put application back online
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan up --env=dev}

          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :send_email => false) # TODO make email true

      end

      def smart_stage(options={})
        old_build = Version.get_build(smart_stage_version)
        build = smart_dev_build

        begin
          # take application offline (maintenance mode)
          # return true so command is non-fatal (artisan doesn't exist the first time)
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan down || true"}

          # sync new app contents
          run_cmd %Q{rsync -ave ssh --delete --force --exclude='public/assets/audio/' --exclude='public/assets/files/' --exclude='app/files/*' --exclude='app/storage/*' #{site_path} --filter "protect .env.php" --filter "protect .env.stage.php" --filter "protect down" #{smart_user}@#{smart_stage_ip}:#{site_root}}

          # run database migrations
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan migrate --env=stage"}

          # generate optimized autoload files
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/local/bin/composer dump-autoload -o"}

          # take application online
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan up --env=stage"}

          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :env => 'STAGE', :send_email => false) # TODO make email true
      end

      def smart_environments
        [
          {
            :name => 'dev',
            :method => 'smart_dev',
            :current_version => smart_dev_version,
            :current_build => smart_dev_build,
            :next_build => smart_head_build
          },
          {
            :name => 'stage',
            :method => 'smart_stage',
            :current_version => smart_stage_version,
            :current_build => smart_stage_build,
            :next_build => smart_dev_build
          }        
        ]
      end
    end
  end
end
<commit_msg>ensure dump-autoload runs before migrations<commit_after>module Deployinator
  module Stacks
    module Smart
      def smart_git_repo_url
        "<EMAIL>@github.<EMAIL>:xfactoradvertising/smart.git"
      end

      def smart_user
        'www-data'
      end

      def smart_stage_ip
        '192.168.127.12'
      end

      def checkout_root
        "/tmp"
      end

      def site_root
        '/var/www/sites'
      end

      def site_path
        "#{site_root}/#{stack}"
      end

      def smart_git_checkout_path
        "#{checkout_root}/#{stack}"
      end

      def smart_dev_version
        %x{cat #{smart_git_checkout_path}/version.txt}
      end

      def smart_dev_build
        Version.get_build(smart_dev_version)
      end

      def smart_stage_version
        %x{ssh #{smart_user}@#{smart_stage_ip} 'cat #{site_path}/version.txt'}
      end

      def smart_stage_build
        Version.get_build(smart_stage_version)
      end

      def smart_head_build
        %x{git ls-remote #{smart_git_repo_url} HEAD | cut -c1-7}.chomp
      end

      def smart_dev(options={})
        old_build = Version.get_build(smart_dev_version)

        git_cmd = old_build ? :git_freshen_clone : :github_clone
        send(git_cmd, stack, 'sh -c')

        git_bump_version stack, ''

        build = smart_head_build

        begin
          # take application offline (maintenance mode)
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan --env=dev down || true} # return true so command is non-fatal

          # sync site files to final destination
          run_cmd %Q{rsync -av --delete --force --exclude='app/storage/' --exclude='public/assets/audio/' --exclude='public/assets/files/' --exclude='app/files/*' --exclude='/vendor/' --exclude='.git/' --exclude='.gitignore' --filter "protect .env.dev.php" #{smart_git_checkout_path}/ #{site_path}}

          # additionally sync top-level storage dirs (but not their contents)
          run_cmd %Q{rsync -lptgoDv --dirs --delete --force --exclude='.gitignore' --filter "protect .env.dev.php" #{smart_git_checkout_path}/app/storage/ #{site_path}/app/storage}

          # ensure storage is writable (shouldn't have to do this but running webserver as different user)
          run_cmd %Q{chmod 777 #{site_path}/app/storage/*}

          # smart-specific chmods
          run_cmd %Q{chmod 777 #{site_path}/app/storage/}
          run_cmd %Q{chmod 777 #{site_path}/public/assets/audio}
          run_cmd %Q{chmod 777 #{site_path}/public/assets/files}
          run_cmd %Q{chmod 777 #{site_path}/app/files}

          # install dependencies (vendor dir was probably completely removed via above)
          run_cmd %Q{cd #{site_path} && /usr/local/bin/composer install --no-dev}

          # generate optimized autoload files
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan dump-autoload --env=dev}

          # run db migrations
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan migrate --env=dev}

          # put application back online
          run_cmd %Q{cd #{site_path} && /usr/bin/php artisan up --env=dev}

          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :send_email => false) # TODO make email true

      end

      def smart_stage(options={})
        old_build = Version.get_build(smart_stage_version)
        build = smart_dev_build

        begin
          # take application offline (maintenance mode)
          # return true so command is non-fatal (artisan doesn't exist the first time)
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan down || true"}

          # sync new app contents
          run_cmd %Q{rsync -ave ssh --delete --force --exclude='public/assets/audio/' --exclude='public/assets/files/' --exclude='app/files/*' --exclude='app/storage/*' #{site_path} --filter "protect .env.php" --filter "protect .env.stage.php" --filter "protect down" #{smart_user}@#{smart_stage_ip}:#{site_root}}

          # generate optimized autoload files
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan dump-autoload --env=stage"}

          # run database migrations
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan migrate --env=stage"}

          # take application online
          run_cmd %Q{ssh #{smart_user}@#{smart_stage_ip} "cd #{site_path} && /usr/bin/php artisan up --env=stage"}

          log_and_stream "Done!<br>"
        rescue
          log_and_stream "Failed!<br>"
        end

        log_and_shout(:old_build => old_build, :build => build, :env => 'STAGE', :send_email => false) # TODO make email true
      end

      def smart_environments
        [
          {
            :name => 'dev',
            :method => 'smart_dev',
            :current_version => smart_dev_version,
            :current_build => smart_dev_build,
            :next_build => smart_head_build
          },
          {
            :name => 'stage',
            :method => 'smart_stage',
            :current_version => smart_stage_version,
            :current_build => smart_stage_build,
            :next_build => smart_dev_build
          }        
        ]
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12255367661029831, 'fraction_numerical': 0.005320159604788144, 'mean_word_length': 2.287632729544035, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '58936', 'n_tokens_mistral': 3403, 'n_tokens_neox': 3246, 'n_words': 762}