Sha256: 6c0e6981d79095f4e6bce46b139dbc6f25e18a35e65d29be36de51ec3bb2c7d3

Contents?: true

Size: 1.56 KB

Versions: 20

Compression:

Stored size: 1.56 KB

Contents

module TreasureData::Command

  def schema_show(op)
    db_name, table_name = op.cmd_parse

    client = get_client
    table = get_table(client, db_name, table_name)

    $stdout.puts "#{db_name}.#{table_name} ("
    table.schema.fields.each {|f|
      if f.sql_alias
        $stdout.puts "  #{f.name}:#{f.type}@#{f.sql_alias}"
      else
        $stdout.puts "  #{f.name}:#{f.type}"
      end
    }
    $stdout.puts ")"
  end

  def schema_set(op)
    db_name, table_name, *columns = op.cmd_parse

    client = get_client
    table = get_table(client, db_name, table_name)

    schema = TreasureData::Schema.parse(columns)
    client.update_schema(db_name, table_name, schema)

    $stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
  end

  def schema_add(op)
    db_name, table_name, *columns = op.cmd_parse

    client = get_client
    table = get_table(client, db_name, table_name)

    schema = table.schema.merge(TreasureData::Schema.parse(columns))
    client.update_schema(db_name, table_name, schema)

    $stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
  end

  def schema_remove(op)
    db_name, table_name, *columns = op.cmd_parse

    client = get_client
    table = get_table(client, db_name, table_name)

    schema = table.schema

    columns.each {|col|
      unless schema.fields.reject!{|f| f.name == col }
        $stderr.puts "Column name '#{col}' does not exist."
        exit 1
      end
    }

    client.update_schema(db_name, table_name, schema)

    $stderr.puts "Schema is updated on #{db_name}.#{table_name} table."
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
td-0.17.1 lib/td/command/schema.rb
td-0.17.0 lib/td/command/schema.rb
td-0.16.10 lib/td/command/schema.rb
td-0.16.9 lib/td/command/schema.rb
td-0.16.8 lib/td/command/schema.rb
td-0.16.7 lib/td/command/schema.rb
td-0.16.6 lib/td/command/schema.rb
td-0.16.5 lib/td/command/schema.rb
td-0.16.4 lib/td/command/schema.rb
td-0.16.3 lib/td/command/schema.rb
td-0.16.1 lib/td/command/schema.rb
td-0.16.0 lib/td/command/schema.rb
td-0.15.9 lib/td/command/schema.rb
td-0.15.8 lib/td/command/schema.rb
td-0.15.7 lib/td/command/schema.rb
td-0.15.6 lib/td/command/schema.rb
td-0.15.5 lib/td/command/schema.rb
td-0.15.4 lib/td/command/schema.rb
td-0.15.3 lib/td/command/schema.rb
td-0.15.2 lib/td/command/schema.rb