blue-shift 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/blueshift.rb +1 -0
- data/lib/blueshift/version.rb +1 -1
- data/lib/sequel/adapters/redshift.rb +17 -0
- data/lib/sequel/extensions/redshift_schema_dumper.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f0cdc1858c2e2f39ce26325ccca7fe95e656038
|
4
|
+
data.tar.gz: 1c7fe3e6aac9b6e32959e381ae03c06de172c4b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff1293408c000baa3b5a34f0e717fa6842d614970615e49c15019e89f31387c00884542a7c87dd8e4422b56aea96105e64625970fb2b72c52c19f4dae80919d2
|
7
|
+
data.tar.gz: 2d4665a820d82718069b3aad88d57fb8db136555663965ba628ebbb16d7a49af33ff9dea86d72cc4fff35e36e70dc8ddee67eaa237f0cc441a93ef992323f9de
|
data/lib/blueshift.rb
CHANGED
data/lib/blueshift/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|