Sha256: fe2cbc4bd85b621b0ac56962d7c688b3ee58a1263fb2f2f1c1d1ff69d152968b
Contents?: true
Size: 1.99 KB
Versions: 34
Compression:
Stored size: 1.99 KB
Contents
require 'rails/generators/base' module TestTrack module Generators class MigrationGenerator < Rails::Generators::Base desc "Creates a test track migration file." argument :raw_split_name, required: true def create_test_track_migration_file create_migration_file end private def create_migration_file create_file full_file_path, <<-FILE.strip_heredoc class #{split_class_name} < #{migration_class} def change TestTrack.update_config do |c| #{split_command_line} end end end FILE end def migration_class if ActiveRecord::VERSION::MAJOR >= 5 ActiveRecord::Migration[5.0] else ActiveRecord::Migration end end def split_command_line "#{split_command} :#{split_name}#{split_variants}" end def split_command @split_command ||= split_type == :drop ? 'c.drop_split' : 'c.split' end def split_variants case split_type when :drop '' when :gate ', true: 0, false: 100' else ', control: 50, treatment: 50' end end def split_type if split_file_name.start_with? 'drop' :drop elsif split_file_name.end_with? 'enabled', 'feature_flag' :gate elsif split_file_name.end_with? 'experiment' :experiment else :default end end def full_file_path "db/migrate/#{formatted_time_stamp}_#{split_file_name}.rb" end def formatted_time_stamp Time.zone.now.strftime('%Y%m%d%H%M%S') end def split_class_name split_file_name.camelize end def split_name noise_words = /^create_|^update_|^drop_|^add_/ split_file_name.gsub(noise_words, '') end def split_file_name raw_split_name.underscore end end end end
Version data entries
34 entries across 34 versions & 1 rubygems