blue-shift 0.0.5 → 0.0.6
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/migration.rb +15 -4
- data/lib/blueshift/version.rb +1 -1
- data/lib/tasks/schema.rake +14 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19697e1d921df9d562455830560b22cd26b60ca5
|
4
|
+
data.tar.gz: 09c7d7afd5636a1f31a53bbef71286d440781570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42fe1da2f23eaf7fcd23633d799524e91d0e4b3e1ca15e126dd3f334262729bf7faa7c1a156a8042832d2a4b0ab7b3b1a15266dfcfa13cf52251eab7ce502055
|
7
|
+
data.tar.gz: b8709eb657c350cb54f7a02816e3facb4cc1f60603eec03786b5af4f4ee4add1c7c2318aacbc165724a0dc165852c546cab9037479f92e2d9c98592a80c95be2
|
data/lib/blueshift/migration.rb
CHANGED
@@ -7,12 +7,13 @@ module Blueshift
|
|
7
7
|
POSTGRES_DB = Sequel.connect(ENV.fetch('DATABASE_URL'), logger: Logger.new('postgres.log'))
|
8
8
|
|
9
9
|
class Migration
|
10
|
-
attr_reader :postgres_migration, :redshift_migration
|
10
|
+
attr_reader :postgres_migration, :redshift_migration, :use_transactions
|
11
11
|
MIGRATION_DIR = File.join(Dir.pwd, 'db/migrations')
|
12
12
|
|
13
13
|
def initialize(&block)
|
14
14
|
@postgres_migration = Sequel::SimpleMigration.new
|
15
15
|
@redshift_migration = Sequel::SimpleMigration.new
|
16
|
+
@use_transactions = true
|
16
17
|
|
17
18
|
Sequel::Migration.descendants << self
|
18
19
|
instance_eval(&block)
|
@@ -43,9 +44,19 @@ module Blueshift
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
class << self
|
48
|
+
def run_pg!
|
49
|
+
Sequel::Migrator.run(POSTGRES_DB, MIGRATION_DIR, column: :postgres_version)
|
50
|
+
end
|
51
|
+
|
52
|
+
def run_redshift!
|
53
|
+
Sequel::Migrator.run(REDSHIFT_DB, MIGRATION_DIR, column: :redshift_version)
|
54
|
+
end
|
55
|
+
|
56
|
+
def run_both!
|
57
|
+
run_pg!
|
58
|
+
run_redshift!
|
59
|
+
end
|
49
60
|
end
|
50
61
|
|
51
62
|
private
|
data/lib/blueshift/version.rb
CHANGED
data/lib/tasks/schema.rake
CHANGED
@@ -6,6 +6,9 @@ require 'blueshift'
|
|
6
6
|
path = File.join(Dir.pwd, 'db')
|
7
7
|
logger = Logger.new(STDOUT)
|
8
8
|
|
9
|
+
Blueshift::POSTGRES_DB.logger = logger
|
10
|
+
Blueshift::REDSHIFT_DB.logger = logger
|
11
|
+
|
9
12
|
task :ensure_db_dir do
|
10
13
|
FileUtils.mkdir_p(path)
|
11
14
|
end
|
@@ -14,18 +17,21 @@ namespace :pg do
|
|
14
17
|
namespace :schema do
|
15
18
|
desc 'Dumps the Postgres schema to a file'
|
16
19
|
task :dump => :ensure_db_dir do
|
17
|
-
Blueshift::POSTGRES_DB.logger = logger
|
18
20
|
Blueshift::POSTGRES_DB.extension :redshift_schema_dumper
|
19
21
|
File.open(File.join(path, 'schema.rb'), 'w') { |f| f << Blueshift::POSTGRES_DB.dump_schema_migration(same_db: true) }
|
20
22
|
end
|
21
23
|
|
22
24
|
desc 'Loads the Postgres schema from the file to the database'
|
23
25
|
task :load => :ensure_db_dir do
|
24
|
-
Blueshift::POSTGRES_DB.logger = logger
|
25
26
|
eval(File.read(File.join(path, 'schema.rb'))).apply(Blueshift::POSTGRES_DB, :up)
|
26
27
|
puts 'loaded schema into Postgres'
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
desc 'Runs migrations for Postgres'
|
32
|
+
task :migrate do
|
33
|
+
Blueshift::Migration.run_pg!
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
|
@@ -33,27 +39,28 @@ namespace :redshift do
|
|
33
39
|
namespace :schema do
|
34
40
|
desc 'Dumps the Postgres schema to a file'
|
35
41
|
task :dump => :ensure_db_dir do
|
36
|
-
Blueshift::REDSHIFT_DB.logger = logger
|
37
42
|
Blueshift::REDSHIFT_DB.extension :redshift_schema_dumper
|
38
43
|
File.open(File.join(path, 'schema_redshift.rb'), 'w') { |f| f << Blueshift::REDSHIFT_DB.dump_schema_migration(same_db: true) }
|
39
44
|
end
|
40
45
|
|
41
46
|
desc 'Loads the Postgres schema from the file to the database'
|
42
47
|
task :load => :ensure_db_dir do
|
43
|
-
Blueshift::REDSHIFT_DB.logger = logger
|
44
48
|
eval(File.read(File.join(path, 'schema_redshift.rb'))).apply(Blueshift::REDSHIFT_DB, :up)
|
45
49
|
puts 'loaded schema into Redshift'
|
46
50
|
end
|
47
51
|
end
|
52
|
+
|
53
|
+
desc 'Runs migrations for Redshift'
|
54
|
+
task :migrate do
|
55
|
+
Blueshift::Migration.run_redshift!
|
56
|
+
end
|
48
57
|
end
|
49
58
|
|
50
59
|
namespace :blueshift do
|
51
60
|
desc 'Runs migrations for both Postgres and Redshift'
|
52
61
|
task :migrate do
|
53
62
|
puts 'Running migrations for Postgres and Redshift...', ''
|
54
|
-
Blueshift::
|
55
|
-
Blueshift::REDSHIFT_DB.logger = logger
|
56
|
-
Blueshift::Migration.run!
|
63
|
+
Blueshift::Migration.run_both!
|
57
64
|
end
|
58
65
|
end
|
59
66
|
|