Class: Flydata::Mysql::RedshiftTableAdapter

Inherits:
Object
  • Object
show all
Includes:
Redshift::Util
Defined in:
lib/flydata/command/sync.rb

Constant Summary

Constants included from Redshift::Util

Redshift::Util::MAX_TABLENAME_LENGTH, Redshift::Util::REDSHIFT_RESERVED_WORDS, Redshift::Util::REDSHIFT_RESERVED_WORDS_HASH, Redshift::Util::REDSHIFT_SYSTEM_COLUMNS, Redshift::Util::REDSHIFT_SYSTEM_COLUMNS_HASH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Redshift::Util

#convert_to_valid_name, #is_redshift_reserved_word?

Constructor Details

#initialize(mysql_table) ⇒ RedshiftTableAdapter

Returns a new instance of RedshiftTableAdapter.



751
752
753
754
755
# File 'lib/flydata/command/sync.rb', line 751

def initialize(mysql_table)
  @table_name = convert_to_valid_name(mysql_table.table_name)
  set_columns(mysql_table.columns)
  @primary_keys = mysql_table.primary_keys
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



757
758
759
# File 'lib/flydata/command/sync.rb', line 757

def columns
  @columns
end

#primary_keysObject (readonly)

Returns the value of attribute primary_keys.



757
758
759
# File 'lib/flydata/command/sync.rb', line 757

def primary_keys
  @primary_keys
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



757
758
759
# File 'lib/flydata/command/sync.rb', line 757

def table_name
  @table_name
end

Instance Method Details

#create_table_sqlObject



759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/flydata/command/sync.rb', line 759

def create_table_sql
  col_def = @columns.inject([]) { |list, (cn, column)|
    list << build_column_def(column)
    list
  }
  if @primary_keys.count > 0
    col_def << "primary key (#{@primary_keys.join(',')})"
  end
  <<EOT
CREATE TABLE #{@table_name} (#{col_def.join(',')});
EOT
end