Sha256: 2a4a6c0f50481dc82aebea429f2a089376ea90ff5df8db2315dc3365aa77dba9

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require_relative 'base'

module DeclareSchema
  module SchemaChange
    class ColumnAdd < Base
      def initialize(table_name, column_name, column_type, **column_options)
        table_name.is_a?(String) || table_name.is_a?(Symbol) or raise ArgumentError, "must provide String|Symbol table_name; got #{table_name.inspect}"
        column_name.is_a?(String) || column_name.is_a?(Symbol) or raise ArgumentError, "must provide String|Symbol column_name; got #{column_name.inspect}"
        @table_name = table_name
        @column_name = column_name
        @column_type = column_type or raise ArgumentError, "must provide column_type"
        @column_options = column_options
      end

      def up_command
        "add_column #{[@table_name.to_sym.inspect,
                       @column_name.to_sym.inspect,
                       @column_type.to_sym.inspect,
                       *self.class.format_options(@column_options)].join(", ")}"
      end

      def down_command
        "remove_column #{@table_name.to_sym.inspect}, #{@column_name.to_sym.inspect}"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
declare_schema-2.3.0 lib/declare_schema/schema_change/column_add.rb
declare_schema-2.3.0.pre.is.0 lib/declare_schema/schema_change/column_add.rb
declare_schema-2.2.1 lib/declare_schema/schema_change/column_add.rb
declare_schema-2.2.0.colin.1 lib/declare_schema/schema_change/column_add.rb
declare_schema-2.2.0 lib/declare_schema/schema_change/column_add.rb
declare_schema-2.1.0 lib/declare_schema/schema_change/column_add.rb
declare_schema-2.1.0.pre.1 lib/declare_schema/schema_change/column_add.rb
declare_schema-1.4.0 lib/declare_schema/schema_change/column_add.rb
declare_schema-1.4.0.colin.11 lib/declare_schema/schema_change/column_add.rb
declare_schema-1.3.6 lib/declare_schema/schema_change/column_add.rb
declare_schema-1.3.6.colin.1 lib/declare_schema/schema_change/column_add.rb