blue-shift 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ba2efeff34013ecda9d1470847300d4c4672fef
4
- data.tar.gz: 1084eda477b23e024194b0786ee5a52014d72ee6
3
+ metadata.gz: 4f0cdc1858c2e2f39ce26325ccca7fe95e656038
4
+ data.tar.gz: 1c7fe3e6aac9b6e32959e381ae03c06de172c4b4
5
5
  SHA512:
6
- metadata.gz: 6fa65136a66fb3283351223c052fcc84cb58cccdd5687af8d5b9e0f2bc6b2e264342f78251e64d7f2ef5893e342ee89ce827e2ab8671c8829bd641cd7a8a8d35
7
- data.tar.gz: ed64339075b3032198be0e039c576f5bee471add340a7f122d46159cc72f7c824ad89f4087c686633de81096750afa880fcf271bd9e776210c78e3bf2e19cc89
6
+ metadata.gz: ff1293408c000baa3b5a34f0e717fa6842d614970615e49c15019e89f31387c00884542a7c87dd8e4422b56aea96105e64625970fb2b72c52c19f4dae80919d2
7
+ data.tar.gz: 2d4665a820d82718069b3aad88d57fb8db136555663965ba628ebbb16d7a49af33ff9dea86d72cc4fff35e36e70dc8ddee67eaa237f0cc441a93ef992323f9de
data/lib/blueshift.rb CHANGED
@@ -4,6 +4,7 @@ require 'blueshift/migration'
4
4
  require 'sequel'
5
5
  require 'sequel/adapters/redshift'
6
6
  require 'sequel/extensions/schema_dumper_ext'
7
+ require 'sequel/extensions/redshift_schema_dumper'
7
8
 
8
9
  module Blueshift
9
10
  def self.migration(&block)
@@ -1,3 +1,3 @@
1
1
  module Blueshift
2
- VERSION = '0.1.6'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -9,6 +9,23 @@ module Sequel
9
9
  SORTSTYLES = [:compound, :interleaved].freeze
10
10
  DISTSTYLES = [:even, :key, :all].freeze
11
11
 
12
+ def optimize_table(table, create_options)
13
+ extension :redshift_schema_dumper
14
+ transaction do
15
+ gen = dump_table_generator(table)
16
+
17
+ rename_table table, :"old_#{table}"
18
+ create_table(:"new_#{table}", create_options) do
19
+ instance_eval(gen.dump_columns, __FILE__, __LINE__)
20
+ instance_eval(gen.dump_constraints, __FILE__, __LINE__)
21
+ instance_eval(gen.dump_indexes, __FILE__, __LINE__)
22
+ end
23
+ run %Q{INSERT INTO "new_#{table}" (SELECT * FROM "old_#{table}")}
24
+ rename_table :"new_#{table}", table
25
+ drop_table :"old_#{table}"
26
+ end
27
+ end
28
+
12
29
  def serial_primary_key_options
13
30
  # redshift doesn't support serial type
14
31
  super.merge(serial: false)
@@ -4,6 +4,7 @@ module Sequel
4
4
  module Redshift
5
5
  module SchemaDumper
6
6
  include Sequel::SchemaDumper
7
+ DISTSTYLE = { 0 => :even, 1 => :key, 8 => :all }.freeze
7
8
 
8
9
  def dump_table_schema(table, options=OPTS)
9
10
  gen = dump_table_generator(table, options)
@@ -14,6 +15,7 @@ module Sequel
14
15
 
15
16
  def table_options(table, gen, options)
16
17
  s = {distkey: table_distkey(table),
18
+ diststyle: table_diststyle(table),
17
19
  sortkeys: table_sortkeys(table),
18
20
  sortstyle: table_sortstyle(table),
19
21
  ignore_index_errors: (!options[:same_db] && options[:indexes] != false && !gen.indexes.empty?)
@@ -24,6 +26,10 @@ module Sequel
24
26
 
25
27
  private
26
28
 
29
+ def table_diststyle(table)
30
+ self[:pg_class].where(relname: table).map(:reldiststyle).first
31
+ end
32
+
27
33
  def table_distkey(table)
28
34
  key = pg_table_def(table).filter(distkey: true).map(:column).first
29
35
  key.to_sym if key
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blue-shift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Mansour
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-11 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel