activerecord_views 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 846f267566c95c8e6adc3a7dc503e0aaefa83d48dcd5c27b865f6ff60dc70bc0
4
- data.tar.gz: be109db5a85a682c00244c2ff52d7f29cefb72d20b54ea03431937d04355bdcb
3
+ metadata.gz: 777d910ae40ada55060df98887059878cc8ddb8ec65f6d49a890d2de9164810f
4
+ data.tar.gz: d905c23880139d85f0fb9ec3c00318670a1638351fc8e42bab05656c8d097d2e
5
5
  SHA512:
6
- metadata.gz: 530ed043fe22df67d38ce2a5ce63f65af5617f2ead4e0de329fe47fe6f0072c25f837861f90f222af24e084d43516785a182125becd0b06e81409d930215a0c0
7
- data.tar.gz: ea5cacee78d55faaaa1aed554c34317a43d156f71f5bc017de4a9031df8c3432b0b785da335efdc85b67ee1dcc68ce064fc1bdc707d8214912a8fd69b0281052
6
+ metadata.gz: ed3ac3d78b82bf20501936c0c3f4a30815300da89d2516d9149d37723d977638f06f0c6414a62d1460239da7e94478110bb89ec13459d656d28cbe37ca94e254
7
+ data.tar.gz: 0f6f5bf130436bc8fcf1a9fd1ad383044bc4a0373dd1f18a56c5691ee20a1eb55d38476e8af294c9daeb740182b520aff7202c4c6b75cc638d46dd12cda26dff
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordViews
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -52,12 +52,26 @@ Rake::Task[schema_rake_task].enhance do
52
52
  pg_tasks = tasks.send(:class_for_adapter, adapter).new(config)
53
53
  pg_tasks.send(:set_psql_env)
54
54
 
55
- require 'shellwords'
56
- system("pg_dump --data-only --table=active_record_views #{Shellwords.escape database} >> #{Shellwords.escape filename}")
57
- raise 'active_record_views metadata dump failed' unless $?.success?
55
+ begin
56
+ active_record_views_dump = Tempfile.open("active_record_views_dump.sql")
57
+ require 'shellwords'
58
+ system("pg_dump --data-only --no-owner --table=active_record_views #{Shellwords.escape database} >> #{Shellwords.escape active_record_views_dump.path}")
59
+ raise 'active_record_views metadata dump failed' unless $?.success?
58
60
 
59
- File.open filename, 'a' do |io|
60
- io.puts 'UPDATE public.active_record_views SET refreshed_at = NULL WHERE refreshed_at IS NOT NULL;'
61
+ if Gem::Version.new(Rails.version) >= Gem::Version.new("5.1")
62
+ pg_tasks.send(:remove_sql_header_comments, active_record_views_dump.path)
63
+ end
64
+
65
+ File.open filename, 'a' do |io|
66
+ # Seek to the end to ensure we don't overwrite the existing content
67
+ io.seek(0, IO::SEEK_END)
68
+ IO.copy_stream active_record_views_dump, io
69
+
70
+ io.puts 'UPDATE public.active_record_views SET refreshed_at = NULL WHERE refreshed_at IS NOT NULL;'
71
+ end
72
+ ensure
73
+ active_record_views_dump.close
74
+ active_record_views_dump.unlink
61
75
  end
62
76
  end
63
77
  end
data/spec/tasks_spec.rb CHANGED
@@ -77,6 +77,8 @@ describe 'rake tasks' do
77
77
 
78
78
  expect(File.exist?('spec/internal/db/schema.rb')).to eq false
79
79
  sql = File.read('spec/internal/db/structure.sql')
80
+ expect(sql).to match(/CREATE TABLE public\.schema_migrations/)
81
+ expect(sql).to match(/CREATE VIEW public\.test_view/)
80
82
  expect(sql).to match(/COPY public\.active_record_views.+test_view\tTestView/m)
81
83
  expect(sql).to match(/UPDATE public\.active_record_views SET refreshed_at = NULL/)
82
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_views
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Weathered
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-29 00:00:00.000000000 Z
11
+ date: 2021-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord