Sha256: abf98f834ce120cba0118314c8864bba1f2deb8724e97405d51c523e334a1529

Contents?: true

Size: 1.33 KB

Versions: 12

Compression:

Stored size: 1.33 KB

Contents

require 'generators/sequel'

module Sequel
  module Generators

    class MigrationGenerator < Base

      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
      class_option :id, :type => :numeric, :desc => "The id to be used in this migration"

      def create_migration_file
        set_local_assigns!
        migration_template "migration.rb", "db/migrate/#{file_name}.rb"
      end

      attr_reader :migration_action, :table_action, :column_action, :use_change

      protected
      def set_local_assigns!
        if file_name =~ /^(create|drop)_(.*)$/
          @table_action   = $1
          @table_name     = $2.pluralize
          @column_action  = 'add'
          @use_change     = @table_action == 'create' ? true : false
        elsif file_name =~ /^(add|drop|remove)_.*_(?:to|from)_(.*)/
          @table_action   = 'alter'
          @table_name     = $2.pluralize
          @column_action  = $1 == 'add' ? 'add' : 'drop'
          @use_change     = @column_action == 'add' ? true : false
        else
          @table_action   = 'alter'
          if file_name =~ /^(alter)_(.*)/
            @table_name   = $2.pluralize
          else
            @table_name   = file_name.pluralize
          end
          @use_change     = false
          @column_action  = 'add'
        end
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
vizzuality-sequel-rails-0.3.7 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.10 lib/generators/sequel/migration/migration_generator.rb
vizzuality-sequel-rails-0.3.6 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.9 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.8 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.7 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.6 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.5 lib/generators/sequel/migration/migration_generator.rb
vizzuality-sequel-rails-0.3.5 lib/generators/sequel/migration/migration_generator.rb
vizzuality-sequel-rails-0.3.4 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.4 lib/generators/sequel/migration/migration_generator.rb
talentbox-sequel-rails-0.3.3 lib/generators/sequel/migration/migration_generator.rb