blue-shift 0.0.5 → 0.0.6

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: d452ee90d0421cc0b881ae27feb0977f41f5d6a0
4
- data.tar.gz: 89540a62ff3516e4e5b2e7bd6394a864787b4d20
3
+ metadata.gz: 19697e1d921df9d562455830560b22cd26b60ca5
4
+ data.tar.gz: 09c7d7afd5636a1f31a53bbef71286d440781570
5
5
  SHA512:
6
- metadata.gz: a472c137b4bd7f644516b8f262a54c052b4867fb2cdc9aa02de9f137e8c57dc92897d1756c88363febdedc1d5ee4396081d131b476834dabdb74b79ad0b18396
7
- data.tar.gz: d7091e6553a4d9097e6751f2fb48c95aa395c3e7272962868239d65f1907e3469f4395166e080478d26f29615a7e1b507f73fb87af6e4185857f7768c65d0a88
6
+ metadata.gz: 42fe1da2f23eaf7fcd23633d799524e91d0e4b3e1ca15e126dd3f334262729bf7faa7c1a156a8042832d2a4b0ab7b3b1a15266dfcfa13cf52251eab7ce502055
7
+ data.tar.gz: b8709eb657c350cb54f7a02816e3facb4cc1f60603eec03786b5af4f4ee4add1c7c2318aacbc165724a0dc165852c546cab9037479f92e2d9c98592a80c95be2
@@ -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
- def self.run!
47
- Sequel::Migrator.run(POSTGRES_DB, MIGRATION_DIR, column: :postgres_version)
48
- Sequel::Migrator.run(REDSHIFT_DB, MIGRATION_DIR, column: :redshift_version)
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
@@ -1,3 +1,3 @@
1
1
  module Blueshift
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -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::POSTGRES_DB.logger = logger
55
- Blueshift::REDSHIFT_DB.logger = logger
56
- Blueshift::Migration.run!
63
+ Blueshift::Migration.run_both!
57
64
  end
58
65
  end
59
66
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blue-shift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Mansour