blue-shift 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrations/dummy_migration.rb +0 -0
- data/lib/blueshift.rb +1 -0
- data/lib/blueshift/migration.rb +12 -2
- data/lib/blueshift/version.rb +1 -1
- data/lib/sequel/extensions/redshift_schema_dumper.rb +1 -1
- data/lib/sequel/extensions/schema_dumper_ext.rb +10 -0
- data/lib/tasks/schema.rake +15 -7
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 491693564e9c51d5a965ea7136447851027d93bb
|
4
|
+
data.tar.gz: 5d9e331a804a4a52295690a3c97fc8173273da8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ba7a3d381c8dfb2d1108ee981b2b29c635a8f19d379db642ebe47ffb7c742dcd87c6febf9b1ca72c6c669fd7397cddbfca64e5b1ff1142b0b301923936e4f24
|
7
|
+
data.tar.gz: ee01aa14691d1ce4ab192131a2586dc42f64a23a088d021ca815543e634d94cc655b988d0fa11e350ccfd8f505e903685ae0cf16b197dc76da0c989ad6410feb
|
File without changes
|
data/lib/blueshift.rb
CHANGED
data/lib/blueshift/migration.rb
CHANGED
@@ -9,6 +9,8 @@ module Blueshift
|
|
9
9
|
class Migration
|
10
10
|
attr_reader :postgres_migration, :redshift_migration, :use_transactions
|
11
11
|
MIGRATION_DIR = File.join(Dir.pwd, 'db/migrations')
|
12
|
+
SCHEMA_COLUMN = :filename
|
13
|
+
SCHEMA_TABLE = :schema_migrations
|
12
14
|
|
13
15
|
def initialize(&block)
|
14
16
|
@postgres_migration = Sequel::SimpleMigration.new
|
@@ -44,13 +46,21 @@ module Blueshift
|
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
49
|
+
def self.insert_into_schema_migrations(db)
|
50
|
+
migration_files = Dir["#{MIGRATION_DIR}/*"]
|
51
|
+
migration_files.each do |path|
|
52
|
+
f = File.basename(path)
|
53
|
+
db.from(SCHEMA_TABLE).insert(SCHEMA_COLUMN=>f)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
47
57
|
class << self
|
48
58
|
def run_pg!
|
49
|
-
Sequel::Migrator.run(POSTGRES_DB, MIGRATION_DIR
|
59
|
+
Sequel::Migrator.run(POSTGRES_DB, MIGRATION_DIR)
|
50
60
|
end
|
51
61
|
|
52
62
|
def run_redshift!
|
53
|
-
Sequel::Migrator.run(REDSHIFT_DB, MIGRATION_DIR
|
63
|
+
Sequel::Migrator.run(REDSHIFT_DB, MIGRATION_DIR)
|
54
64
|
end
|
55
65
|
|
56
66
|
def run_both!
|
data/lib/blueshift/version.rb
CHANGED
@@ -9,7 +9,7 @@ module Sequel
|
|
9
9
|
gen = dump_table_generator(table, options)
|
10
10
|
commands = [gen.dump_columns, gen.dump_constraints, gen.dump_indexes].reject { |x| x == '' }.join("\n\n")
|
11
11
|
|
12
|
-
"create_table(#{table.inspect}#{table_options(table, gen, options)}) do\n#{commands.gsub(/^/o, ' ')}\nend"
|
12
|
+
"create_table!(#{table.inspect}#{table_options(table, gen, options)}) do\n#{commands.gsub(/^/o, ' ')}\nend"
|
13
13
|
end
|
14
14
|
|
15
15
|
def table_options(table, gen, options)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'sequel/extensions/schema_dumper'
|
2
|
+
module Sequel
|
3
|
+
module SchemaDumper
|
4
|
+
alias_method :dump_table_schema_without_force, :dump_table_schema
|
5
|
+
|
6
|
+
def dump_table_schema(table, opts=OPTS)
|
7
|
+
dump_table_schema_without_force(table, opts).gsub('create_table(', 'create_table!(')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/tasks/schema.rake
CHANGED
@@ -15,13 +15,16 @@ namespace :pg do
|
|
15
15
|
desc 'Dumps the Postgres schema to a file'
|
16
16
|
task :dump => :ensure_db_dir do
|
17
17
|
Blueshift::POSTGRES_DB.extension :schema_dumper
|
18
|
-
File.open(File.join(path, 'schema.rb'), 'w') { |f| f << Blueshift::POSTGRES_DB.dump_schema_migration(same_db:
|
18
|
+
File.open(File.join(path, 'schema.rb'), 'w') { |f| f << Blueshift::POSTGRES_DB.dump_schema_migration(same_db: false) }
|
19
19
|
end
|
20
20
|
|
21
21
|
desc 'Loads the Postgres schema from the file to the database'
|
22
22
|
task :load => :ensure_db_dir do
|
23
|
-
eval(File.read(File.join(path, 'schema.rb')))
|
23
|
+
migration = eval(File.read(File.join(path, 'schema.rb')))
|
24
|
+
migration.apply(Blueshift::POSTGRES_DB, :up)
|
24
25
|
puts 'loaded schema into Postgres'
|
26
|
+
Blueshift::Migration.insert_into_schema_migrations(Blueshift::POSTGRES_DB)
|
27
|
+
puts 'inserted schema migrations entries'
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
@@ -29,6 +32,7 @@ namespace :pg do
|
|
29
32
|
task :migrate do
|
30
33
|
Blueshift::POSTGRES_DB.logger = logger
|
31
34
|
Blueshift::Migration.run_pg!
|
35
|
+
rake 'pg:schema:dump'
|
32
36
|
end
|
33
37
|
end
|
34
38
|
|
@@ -43,8 +47,11 @@ namespace :redshift do
|
|
43
47
|
|
44
48
|
desc 'Loads the Postgres schema from the file to the database'
|
45
49
|
task :load => :ensure_db_dir do
|
46
|
-
eval(File.read(File.join(path, 'schema_redshift.rb')))
|
50
|
+
migration = eval(File.read(File.join(path, 'schema_redshift.rb')))
|
51
|
+
migration.apply(Blueshift::REDSHIFT_DB, :up)
|
47
52
|
puts 'loaded schema into Redshift'
|
53
|
+
Blueshift::Migration.insert_into_schema_migrations(Blueshift::REDSHIFT_DB)
|
54
|
+
puts 'inserted schema migrations entries'
|
48
55
|
end
|
49
56
|
end
|
50
57
|
|
@@ -52,16 +59,17 @@ namespace :redshift do
|
|
52
59
|
task :migrate do
|
53
60
|
Blueshift::REDSHIFT_DB.logger = logger
|
54
61
|
Blueshift::Migration.run_redshift!
|
62
|
+
rake 'redshift:schema:dump'
|
55
63
|
end
|
56
64
|
end
|
57
65
|
|
58
66
|
namespace :blueshift do
|
59
67
|
desc 'Runs migrations for both Postgres and Redshift'
|
60
|
-
task :migrate do
|
68
|
+
task :migrate => ['pg:migrate', 'redshift:migrate'] do
|
61
69
|
puts 'Running migrations for Postgres and Redshift...', ''
|
62
|
-
Blueshift::POSTGRES_DB.logger = logger
|
63
|
-
Blueshift::REDSHIFT_DB.logger = logger
|
64
|
-
Blueshift::Migration.run_both!
|
65
70
|
end
|
71
|
+
|
72
|
+
desc 'dummy'
|
73
|
+
task(:dummy) {}
|
66
74
|
end
|
67
75
|
|
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.
|
4
|
+
version: 0.1.2
|
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-03-
|
11
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- bin/console
|
115
115
|
- bin/setup
|
116
116
|
- blueshift.gemspec
|
117
|
+
- db/migrations/dummy_migration.rb
|
117
118
|
- lib/blueshift.rb
|
118
119
|
- lib/blueshift/migration.rb
|
119
120
|
- lib/blueshift/railtie.rb
|
@@ -122,6 +123,7 @@ files:
|
|
122
123
|
- lib/sequel/adapters/postgres_ext.rb
|
123
124
|
- lib/sequel/adapters/redshift.rb
|
124
125
|
- lib/sequel/extensions/redshift_schema_dumper.rb
|
126
|
+
- lib/sequel/extensions/schema_dumper_ext.rb
|
125
127
|
- lib/tasks/generate_migration.rake
|
126
128
|
- lib/tasks/schema.rake
|
127
129
|
homepage: https://github.com/influitive/blueshift
|
@@ -143,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
145
|
version: '0'
|
144
146
|
requirements: []
|
145
147
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.4.6
|
147
149
|
signing_key:
|
148
150
|
specification_version: 4
|
149
151
|
summary: Amazon Redshift adapter for Sequel
|