blue-shift 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blueshift/migration.rb +21 -12
- data/lib/blueshift/version.rb +1 -1
- data/lib/sequel/adapters/redshift.rb +7 -1
- 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: 2ba2efeff34013ecda9d1470847300d4c4672fef
|
4
|
+
data.tar.gz: 1084eda477b23e024194b0786ee5a52014d72ee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa65136a66fb3283351223c052fcc84cb58cccdd5687af8d5b9e0f2bc6b2e264342f78251e64d7f2ef5893e342ee89ce827e2ab8671c8829bd641cd7a8a8d35
|
7
|
+
data.tar.gz: ed64339075b3032198be0e039c576f5bee471add340a7f122d46159cc72f7c824ad89f4087c686633de81096750afa880fcf271bd9e776210c78e3bf2e19cc89
|
data/lib/blueshift/migration.rb
CHANGED
@@ -3,14 +3,14 @@ require 'sequel/extensions/migration'
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
5
|
module Blueshift
|
6
|
-
REDSHIFT_DB = Sequel.connect(ENV.fetch('REDSHIFT_URL'), logger: Logger.new('redshift.log'))
|
7
|
-
POSTGRES_DB = Sequel.connect(ENV.fetch('DATABASE_URL'), logger: Logger.new('postgres.log'))
|
6
|
+
REDSHIFT_DB = Sequel.connect(ENV.fetch('REDSHIFT_URL', 'redshift://'), logger: Logger.new('redshift.log'))
|
7
|
+
POSTGRES_DB = Sequel.connect(ENV.fetch('DATABASE_URL', 'postgres://'), logger: Logger.new('postgres.log'))
|
8
8
|
|
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
12
|
SCHEMA_TABLE = :schema_migrations
|
13
|
+
SCHEMA_COLUMN = :filename
|
14
14
|
|
15
15
|
def initialize(&block)
|
16
16
|
@postgres_migration = Sequel::SimpleMigration.new
|
@@ -46,15 +46,6 @@ module Blueshift
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.insert_into_schema_migrations(db)
|
50
|
-
db.from(SCHEMA_TABLE).delete
|
51
|
-
migration_files = Dir["#{MIGRATION_DIR}/*"]
|
52
|
-
migration_files.each do |path|
|
53
|
-
f = File.basename(path)
|
54
|
-
db.from(SCHEMA_TABLE).insert(SCHEMA_COLUMN=>f)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
49
|
class << self
|
59
50
|
def run_pg!
|
60
51
|
Sequel::Migrator.run(POSTGRES_DB, MIGRATION_DIR)
|
@@ -68,6 +59,24 @@ module Blueshift
|
|
68
59
|
run_pg!
|
69
60
|
run_redshift!
|
70
61
|
end
|
62
|
+
|
63
|
+
def insert_into_schema_migrations(db)
|
64
|
+
ds = schema_dataset(db)
|
65
|
+
ds.delete
|
66
|
+
migration_files = Dir["#{MIGRATION_DIR}/*"]
|
67
|
+
migration_files.each do |path|
|
68
|
+
f = File.basename(path)
|
69
|
+
ds.insert(SCHEMA_COLUMN=>f)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def schema_dataset(db)
|
74
|
+
ds = db.from(SCHEMA_TABLE)
|
75
|
+
unless db.table_exists?(SCHEMA_TABLE)
|
76
|
+
db.create_table(SCHEMA_TABLE) { String SCHEMA_COLUMN, primary_key: true }
|
77
|
+
end
|
78
|
+
ds
|
79
|
+
end
|
71
80
|
end
|
72
81
|
|
73
82
|
private
|
data/lib/blueshift/version.rb
CHANGED
@@ -77,7 +77,10 @@ module Sequel
|
|
77
77
|
SQL::Function.new(:format_type, :pg_type__oid, :pg_attribute__atttypmod).as(:db_type),
|
78
78
|
SQL::Function.new(:pg_get_expr, :pg_attrdef__adbin, :pg_class__oid).as(:default),
|
79
79
|
SQL::BooleanExpression.new(:NOT, :pg_attribute__attnotnull).as(:allow_null),
|
80
|
-
SQL::Function.new(:COALESCE,
|
80
|
+
SQL::Function.new(:COALESCE,
|
81
|
+
SQL::BooleanExpression.from_value_pairs(:name => 'id'),
|
82
|
+
schema_migrations_column_name(table_name),
|
83
|
+
false).as(:primary_key)).
|
81
84
|
from(:pg_class).
|
82
85
|
join(:pg_attribute, :attrelid=>:oid).
|
83
86
|
join(:pg_type, :oid=>:atttypid).
|
@@ -107,6 +110,9 @@ module Sequel
|
|
107
110
|
end
|
108
111
|
end
|
109
112
|
|
113
|
+
def schema_migrations_column_name(table_name)
|
114
|
+
#SQL::BooleanExpression.from_value_pairs(:name => 'filename') if table_name == :schema_migrations
|
115
|
+
end
|
110
116
|
end
|
111
117
|
|
112
118
|
class Dataset < Postgres::Dataset
|
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.6
|
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-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|