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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f08f528b72fb07122fc5ad99a01f63c2c7a9ceae
4
- data.tar.gz: e8e92411017effb0f76ce135ff5852e0ebfddc04
3
+ metadata.gz: 2ba2efeff34013ecda9d1470847300d4c4672fef
4
+ data.tar.gz: 1084eda477b23e024194b0786ee5a52014d72ee6
5
5
  SHA512:
6
- metadata.gz: 94a782bf567eace61d3538e18ff461c6668ad5dd31d5e0e9ab95949edd07eb79b9a721f5774dfbe5085629271e8561eacf8f25aefe4037c398997a2b77616dc1
7
- data.tar.gz: f6c9574934c71434abeb1e368ad67f011fa9d79d41775d573459f200962ad598b4a65221d7cd3110629afdf164a30db012e2a81320d23ca608db3f379fa46692
6
+ metadata.gz: 6fa65136a66fb3283351223c052fcc84cb58cccdd5687af8d5b9e0f2bc6b2e264342f78251e64d7f2ef5893e342ee89ce827e2ab8671c8829bd641cd7a8a8d35
7
+ data.tar.gz: ed64339075b3032198be0e039c576f5bee471add340a7f122d46159cc72f7c824ad89f4087c686633de81096750afa880fcf271bd9e776210c78e3bf2e19cc89
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Blueshift
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
@@ -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, SQL::BooleanExpression.from_value_pairs(:name => 'id'), false).as(:primary_key)).
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.5
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-03-14 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel