rails_db_views 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_db_views/configuration.rb +16 -0
- data/lib/rails_db_views/database_symbol.rb +138 -0
- data/lib/rails_db_views/factory.rb +46 -0
- data/lib/rails_db_views/function.rb +15 -0
- data/lib/rails_db_views/railtie.rb +4 -4
- data/lib/rails_db_views/version.rb +1 -1
- data/lib/rails_db_views/view.rb +15 -0
- data/lib/rails_db_views.rb +9 -2
- data/lib/tasks/rails_db_views_tasks.rake +38 -27
- data/test/dummy/config/database.yml +2 -2
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/functions/add.sql +5 -0
- data/test/dummy/db/schema.rb +3 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/db/views/hello_world.sql +1 -1
- data/test/dummy/log/development.log +316 -0
- metadata +39 -5
- data/lib/rails_db_views/db_views_creator.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff2f855836b239c4af2dae529189588761c22ff3
|
4
|
+
data.tar.gz: 027d2f0e0f45ddb654d5ba70f4613219aa581eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1289482ced1e66da617ad275fd184e68fd2050aaa1ed0f53288066931e35418a6424ab4e7b09fc2bef98e598a90c382bb3d7311ff5107344061ed80b31d7bcd
|
7
|
+
data.tar.gz: 871085dcaac1dc9663bdc6c4b4ce983f9e9d9be8363c41f0cfeced6ca70023334598d09c9481efbca3aaa722411d7412fe6cefe23653e225a7d388e3b4e76f7e
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class RailsDbViews::Configuration
|
2
|
+
attr_accessor :views_paths, :views_extension
|
3
|
+
attr_accessor :functions_paths, :functions_extension
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@views_paths = %w(db/views)
|
7
|
+
@views_extension = "*.sql"
|
8
|
+
|
9
|
+
@functions_paths = %w(db/functions)
|
10
|
+
@functions_extension = "*.sql"
|
11
|
+
end
|
12
|
+
|
13
|
+
def [] *args
|
14
|
+
raise "rails_db_view has changed! Please use the methods views_paths/views_extension instead of hash notation"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
class RailsDbViews::DatabaseSymbol
|
2
|
+
class CircularReferenceError < RuntimeError; end
|
3
|
+
class SymbolNotFound < RuntimeError; end
|
4
|
+
|
5
|
+
attr_accessor :path, :sql_content, :status, :required, :inverse_of_required, :marked_as_deleted, :name
|
6
|
+
alias :marked_as_deleted? :marked_as_deleted
|
7
|
+
|
8
|
+
module Status
|
9
|
+
LOADED = :loaded
|
10
|
+
IN_PROGRESS = :in_progress
|
11
|
+
UNLOADED = :unloaded
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize file_path
|
15
|
+
@path = file_path
|
16
|
+
@name = File.basename(file_path, ".*")
|
17
|
+
|
18
|
+
@status = :none
|
19
|
+
@required = []
|
20
|
+
@marked_as_deleted = false
|
21
|
+
@sql_content = File.read(@path)
|
22
|
+
@inverse_of_required = []
|
23
|
+
|
24
|
+
load_directives
|
25
|
+
end
|
26
|
+
|
27
|
+
def process_inverse_of_required!
|
28
|
+
@required.each do |name|
|
29
|
+
required = RailsDbViews::Factory.get(self.class, name)
|
30
|
+
not_found_error if required.nil?
|
31
|
+
required.inverse_of_required << self.name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def mark_as_delete!
|
36
|
+
@marked_as_deleted = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def loaded?
|
40
|
+
status == Status::LOADED
|
41
|
+
end
|
42
|
+
|
43
|
+
def in_progress?
|
44
|
+
status == Status::IN_PROGRESS
|
45
|
+
end
|
46
|
+
|
47
|
+
def unloaded?
|
48
|
+
status == Status::UNLOADED
|
49
|
+
end
|
50
|
+
|
51
|
+
def create!
|
52
|
+
return if marked_as_deleted? || loaded?
|
53
|
+
|
54
|
+
circular_reference_error if in_progress?
|
55
|
+
|
56
|
+
self.status = Status::IN_PROGRESS
|
57
|
+
|
58
|
+
required.each do |symbol_name|
|
59
|
+
symbol = RailsDbViews::Factory.get(self.class, symbol_name)
|
60
|
+
not_found_error(symbol_name) if symbol.nil?
|
61
|
+
symbol.create!
|
62
|
+
end
|
63
|
+
|
64
|
+
ActiveRecord::Base.connection.execute(create_sql)
|
65
|
+
|
66
|
+
self.status = Status::LOADED
|
67
|
+
end
|
68
|
+
|
69
|
+
def drop!
|
70
|
+
return if loaded?
|
71
|
+
|
72
|
+
circular_reference_error if in_progress?
|
73
|
+
|
74
|
+
self.status = Status::IN_PROGRESS
|
75
|
+
|
76
|
+
# We start by the required one to delete first.
|
77
|
+
inverse_of_required.each do |symbol_name|
|
78
|
+
symbol = RailsDbViews::Factory.get(self.class, symbol_name)
|
79
|
+
not_found_error(symbol_name) if symbol.nil?
|
80
|
+
symbol.drop!
|
81
|
+
end
|
82
|
+
|
83
|
+
begin
|
84
|
+
ActiveRecord::Base.connection.execute(drop_sql)
|
85
|
+
#rescue ActiveRecord::ActiveRecordError => e #Probably because the symbol doesn't exists yet.
|
86
|
+
# handle_error_on_drop
|
87
|
+
end
|
88
|
+
|
89
|
+
self.status = Status::LOADED
|
90
|
+
end
|
91
|
+
|
92
|
+
# Theses methods should be implemented in children objects.
|
93
|
+
def drop_sql
|
94
|
+
raise NotImplementedError, "DatabaseSymbol should not be instanciated"
|
95
|
+
end
|
96
|
+
|
97
|
+
def create_sql
|
98
|
+
raise NotImplementedError, "DatabaseSymbol should not be instanciated"
|
99
|
+
end
|
100
|
+
|
101
|
+
def handle_error_on_drop
|
102
|
+
raise NotImplementedError, "DatabaseSymbol should not be instanciated"
|
103
|
+
end
|
104
|
+
|
105
|
+
protected
|
106
|
+
TWO_DASH_DIRECTIVE_START = /^--[ \t]*!/
|
107
|
+
SHARP_CHAR_DIRECTIVE_START = /^#[ \t]*!/
|
108
|
+
DIRECTIVE_START = /#{TWO_DASH_DIRECTIVE_START}|#{SHARP_CHAR_DIRECTIVE_START}/
|
109
|
+
|
110
|
+
def circular_reference_error
|
111
|
+
raise CircularReferenceError, "Circular file reference! (file: #{path})"
|
112
|
+
end
|
113
|
+
|
114
|
+
def not_found_error(symbol_name)
|
115
|
+
raise SymbolNotFound, "#{self.class.name} `#{symbol_name}` referenced in file #{path} cannot be found..."
|
116
|
+
end
|
117
|
+
|
118
|
+
def load_directives
|
119
|
+
content_lines = sql_content.split("\n")
|
120
|
+
|
121
|
+
directives = content_lines.map(&:strip).select{ |x| x =~ DIRECTIVE_START }.map{ |x|
|
122
|
+
x.gsub(DIRECTIVE_START, "")
|
123
|
+
}
|
124
|
+
|
125
|
+
directives.each do |d|
|
126
|
+
case d
|
127
|
+
when /^require /
|
128
|
+
self.required += d.split(/[ \t]+/)[1..-1]
|
129
|
+
when /^delete(d?) /
|
130
|
+
self.mark_as_delete!
|
131
|
+
else
|
132
|
+
raise IllegalDirective, "I don't know what to do with `#{d}` (in #{path})"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
class RailsDbViews::Factory
|
3
|
+
class AmbigousNameError < RuntimeError; end
|
4
|
+
|
5
|
+
@symbols = {}
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_reader :symbols
|
9
|
+
|
10
|
+
def register_files symbol_class, files
|
11
|
+
@symbols[symbol_class.to_s] ||= {}
|
12
|
+
|
13
|
+
files.each do |file|
|
14
|
+
symbol = symbol_class.new(file)
|
15
|
+
|
16
|
+
if s=@symbols[symbol_class.to_s][symbol.name]
|
17
|
+
raise AmbigousNameError, "between #{file} and #{s.path}"
|
18
|
+
end
|
19
|
+
|
20
|
+
@symbols[symbol_class.to_s][symbol.name] = symbol
|
21
|
+
end
|
22
|
+
|
23
|
+
@symbols.values.map(&:values).flatten.each(&:process_inverse_of_required!)
|
24
|
+
end
|
25
|
+
|
26
|
+
def drop(symbol_class)
|
27
|
+
symbol_list = @symbols[symbol_class.to_s]
|
28
|
+
|
29
|
+
symbol_list.values.each(&:drop!) if symbol_list
|
30
|
+
end
|
31
|
+
|
32
|
+
def create(symbol_class)
|
33
|
+
symbol_list = @symbols[symbol_class.to_s]
|
34
|
+
|
35
|
+
symbol_list.values.each(&:create!) if symbol_list
|
36
|
+
end
|
37
|
+
|
38
|
+
def get(symbol_class, name)
|
39
|
+
(@symbols[symbol_class.to_s]||{})[name]
|
40
|
+
end
|
41
|
+
|
42
|
+
def clear!
|
43
|
+
@symbols = {}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class RailsDbViews::Function < RailsDbViews::DatabaseSymbol
|
2
|
+
def create_sql
|
3
|
+
puts "CREATE OR REPLACE FUNCTION #{name}..."
|
4
|
+
"CREATE OR REPLACE FUNCTION #{name} #{sql_content}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def drop_sql
|
8
|
+
puts "DROP FUNCTION #{name}..."
|
9
|
+
"DROP FUNCTION #{name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def handle_error_on_drop
|
13
|
+
puts "WARNING: DROP FUNCTION #{name}... ERROR"
|
14
|
+
end
|
15
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
require 'rails_db_views/configuration'
|
2
|
+
|
3
|
+
class RailsDbViews::Railtie < Rails::Railtie
|
2
4
|
railtie_name :rails_db_views
|
3
5
|
|
4
|
-
config.rails_db_views =
|
6
|
+
config.rails_db_views = RailsDbViews::Configuration.new
|
5
7
|
|
6
8
|
initializer "rails_db_views.initialize" do |app|
|
7
|
-
app.config.rails_db_views[:views_path] = %w( db/views )
|
8
|
-
app.config.rails_db_views[:views_ext] = "*.sql"
|
9
9
|
end
|
10
10
|
|
11
11
|
rake_tasks do
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class RailsDbViews::View < RailsDbViews::DatabaseSymbol
|
2
|
+
def create_sql
|
3
|
+
puts "CREATE VIEW #{name}..."
|
4
|
+
"CREATE VIEW #{name} AS #{sql_content}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def drop_sql
|
8
|
+
puts "DROP VIEW #{name}..."
|
9
|
+
"DROP VIEW #{name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def handle_error_on_drop
|
13
|
+
puts "WARNING: DROP VIEW #{name}... ERROR"
|
14
|
+
end
|
15
|
+
end
|
data/lib/rails_db_views.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module RailsDbViews
|
2
|
-
|
3
|
-
|
2
|
+
unless defined?(Rails)
|
3
|
+
raise "This gem is made for Ruby on Rails!"
|
4
|
+
end
|
4
5
|
end
|
6
|
+
|
7
|
+
require 'rails_db_views/railtie'
|
8
|
+
require 'rails_db_views/database_symbol'
|
9
|
+
require 'rails_db_views/view'
|
10
|
+
require 'rails_db_views/function'
|
11
|
+
require 'rails_db_views/factory'
|
@@ -1,44 +1,55 @@
|
|
1
|
-
|
1
|
+
def apply_to paths, extension, method, klazz
|
2
|
+
RailsDbViews::Factory.clear!
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
paths.each do |path|
|
5
|
+
RailsDbViews::Factory.register_files klazz,
|
6
|
+
Dir[File.join(path, extension)].map{|x| File.expand_path(x)}
|
7
|
+
end
|
6
8
|
|
7
|
-
|
9
|
+
RailsDbViews::Factory.send(method, klazz)
|
10
|
+
end
|
8
11
|
|
9
|
-
|
10
|
-
creator.register_files Dir[File.join(path, views_ext)].map{|x| File.expand_path(x)}
|
11
|
-
end
|
12
|
+
namespace :db do
|
12
13
|
|
13
|
-
|
14
|
+
desc "Create all the database views of the current project. Views are usually located in db/views"
|
15
|
+
task :create_views => :environment do
|
16
|
+
config = Rails.configuration.rails_db_views
|
17
|
+
apply_to config.views_paths, config.views_extension, :create, RailsDbViews::View
|
14
18
|
end
|
15
19
|
|
16
20
|
desc "Drop all the database views of the current project"
|
17
21
|
task :drop_views => :environment do
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
config = Rails.configuration.rails_db_views
|
23
|
+
apply_to config.views_paths, config.views_extension, :drop, RailsDbViews::View
|
24
|
+
end
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
desc "Create or replace all the functions"
|
27
|
+
task :create_functions => :environment do
|
28
|
+
adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
29
|
+
config = Rails.configuration.rails_db_views
|
30
|
+
|
31
|
+
if adapter_type != :sqlite
|
32
|
+
apply_to config.functions_paths, config.functions_extension, :create, RailsDbViews::Function
|
33
|
+
else
|
34
|
+
if config.functions_paths.length>=1 || File.is_directory?(config.functions_paths.try(:first))
|
35
|
+
puts "Notice: db:create_functions will not trigger for sqlite."
|
36
|
+
end
|
24
37
|
end
|
38
|
+
end
|
25
39
|
|
26
|
-
|
40
|
+
desc "Remove all the functions (to use manually only)"
|
41
|
+
task :drop_functions => :environment do
|
42
|
+
config = Rails.configuration.rails_db_views
|
43
|
+
apply_to config.functions_paths, config.functions_extension, :drop, RailsDbViews::Function
|
27
44
|
end
|
28
45
|
end
|
29
46
|
|
30
47
|
require 'rake/hooks'
|
31
48
|
|
32
|
-
before
|
33
|
-
|
34
|
-
|
35
|
-
before "db:rollback" do
|
36
|
-
Rake::Task['db:drop_views'].invoke
|
37
|
-
end
|
49
|
+
before("db:migrate"){ Rake::Task['db:drop_views'].invoke }
|
50
|
+
before("db:migrate"){ Rake::Task['db:create_functions'].invoke }
|
51
|
+
after("db:migrate"){ Rake::Task['db:create_views'].invoke }
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
after "db:rollback" do
|
43
|
-
Rake::Task['db:create_views'].invoke
|
44
|
-
end
|
53
|
+
before("db:rollback"){ Rake::Task['db:drop_views'].invoke }
|
54
|
+
before("db:rollback"){ Rake::Task['db:create_functions'].invoke }
|
55
|
+
after("db:rollback"){ Rake::Task['db:create_views'].invoke }
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
File without changes
|
@@ -1,2 +1,2 @@
|
|
1
|
-
|
1
|
+
--!require required
|
2
2
|
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
@@ -166,3 +166,319 @@ SQLite3::SQLException: table required already exists: CREATE VIEW required AS SE
|
|
166
166
|
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
167
167
|
[1m[35m (0.9ms)[0m CREATE VIEW required AS SELECT 1 as id
|
168
168
|
[1m[36m (1.1ms)[0m [1mCREATE VIEW hello_world AS SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)[0m
|
169
|
+
[1m[36m (0.2ms)[0m [1mCREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
|
170
|
+
BEGIN
|
171
|
+
RETURN x + y;
|
172
|
+
END;
|
173
|
+
$$ LANGUAGE plpgsql; add.sql[0m
|
174
|
+
SQLite3::SQLException: near "OR": syntax error: CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
|
175
|
+
BEGIN
|
176
|
+
RETURN x + y;
|
177
|
+
END;
|
178
|
+
$$ LANGUAGE plpgsql; add.sql
|
179
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
180
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
181
|
+
[1m[36m (0.1ms)[0m [1mDROP FUNCTION add.sql[0m
|
182
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
183
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
184
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
185
|
+
[1m[36m (0.1ms)[0m [1mDROP FUNCTION add.sql[0m
|
186
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
187
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
188
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
189
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
190
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
191
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
192
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
193
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
194
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
195
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
196
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
197
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
198
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
199
|
+
[1m[36m (0.1ms)[0m [1mDROP FUNCTION add.sql[0m
|
200
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
201
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add.sql[0m
|
202
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add.sql
|
203
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
204
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
205
|
+
[1m[35m (0.2ms)[0m CREATE VIEW required
|
206
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
207
|
+
[1m[36m (0.1ms)[0m [1mCREATE VIEW hello_world[0m
|
208
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
209
|
+
[1m[35m (1.0ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
210
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
211
|
+
[1m[35m (0.8ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
212
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
213
|
+
[1m[35m (0.1ms)[0m CREATE VIEW SELECT 1 as id
|
214
|
+
SQLite3::SQLException: near "SELECT": syntax error: CREATE VIEW SELECT 1 as id
|
215
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
216
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
217
|
+
[1m[35m (0.2ms)[0m CREATE VIEW required
|
218
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
219
|
+
[1m[36m (0.2ms)[0m [1mCREATE VIEW hello_world[0m
|
220
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
221
|
+
[1m[35m (1.2ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
222
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
223
|
+
[1m[35m (0.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
224
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
225
|
+
[1m[35m (0.1ms)[0m CREATE VIEW SELECT 1 as id
|
226
|
+
SQLite3::SQLException: near "SELECT": syntax error: CREATE VIEW SELECT 1 as id
|
227
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
228
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
229
|
+
[1m[35m (0.1ms)[0m CREATE VIEW required
|
230
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
231
|
+
[1m[36m (0.1ms)[0m [1mCREATE VIEW hello_world[0m
|
232
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
233
|
+
[1m[35m (1.9ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
234
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
235
|
+
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
236
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
237
|
+
[1m[35m (1.0ms)[0m CREATE VIEW required AS SELECT 1 as id
|
238
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
239
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
240
|
+
[1m[35m (0.1ms)[0m CREATE VIEW required
|
241
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
242
|
+
[1m[36m (0.1ms)[0m [1mCREATE VIEW hello_world[0m
|
243
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
244
|
+
[1m[35m (1.4ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
245
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
246
|
+
[1m[35m (0.8ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
247
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
248
|
+
[1m[35m (0.7ms)[0m CREATE VIEW required AS SELECT 1 as id
|
249
|
+
[1m[36m (0.9ms)[0m [1mCREATE VIEW hello_world AS --!require required
|
250
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)[0m
|
251
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
252
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
253
|
+
[1m[35m (0.1ms)[0m CREATE VIEW required
|
254
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
255
|
+
[1m[36m (0.1ms)[0m [1mCREATE VIEW hello_world[0m
|
256
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
257
|
+
[1m[35m (1.4ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
258
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
259
|
+
[1m[35m (0.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
260
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
261
|
+
[1m[35m (0.8ms)[0m CREATE VIEW required AS SELECT 1 as id
|
262
|
+
[1m[36m (0.9ms)[0m [1mCREATE VIEW hello_world AS --!require required
|
263
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)[0m
|
264
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
265
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
266
|
+
[1m[35m (0.1ms)[0m CREATE VIEW required
|
267
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
268
|
+
[1m[36m (0.1ms)[0m [1mCREATE VIEW hello_world[0m
|
269
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
270
|
+
[1m[35m (1.0ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
271
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
272
|
+
[1m[35m (1.0ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
273
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
274
|
+
[1m[35m (0.9ms)[0m CREATE VIEW required AS SELECT 1 as id
|
275
|
+
[1m[36m (0.8ms)[0m [1mCREATE VIEW hello_world AS --!require required
|
276
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)[0m
|
277
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
278
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
279
|
+
[1m[35m (0.1ms)[0m CREATE VIEW required
|
280
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
281
|
+
[1m[36m (0.1ms)[0m [1mCREATE VIEW hello_world[0m
|
282
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
283
|
+
[1m[35m (1.2ms)[0m CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
|
284
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
285
|
+
[1m[35m (0.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
286
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
287
|
+
[1m[35m (0.8ms)[0m CREATE VIEW required AS SELECT 1 as id
|
288
|
+
[1m[36m (1.1ms)[0m [1mCREATE VIEW hello_world AS --!require required
|
289
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)[0m
|
290
|
+
[1m[36m (0.2ms)[0m [1mCREATE VIEW required[0m
|
291
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
292
|
+
[1m[35m (0.1ms)[0m CREATE VIEW hello_world
|
293
|
+
SQLite3::SQLException: near "hello_world": syntax error: CREATE VIEW hello_world
|
294
|
+
[1m[36m (1.1ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
295
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
296
|
+
[1m[36m (0.9ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
297
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
298
|
+
[1m[36m (3.9ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
299
|
+
[1m[35m (0.9ms)[0m CREATE VIEW hello_world AS --!require required
|
300
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
301
|
+
[1m[36m (0.2ms)[0m [1mDROP FUNCTION add[0m
|
302
|
+
SQLite3::SQLException: near "FUNCTION": syntax error: DROP FUNCTION add
|
303
|
+
[1m[36m (0.2ms)[0m [1mCREATE VIEW required[0m
|
304
|
+
SQLite3::SQLException: near "required": syntax error: CREATE VIEW required
|
305
|
+
[1m[36m (0.4ms)[0m [1mDROP VIEW required[0m
|
306
|
+
SQLite3::SQLException: no such view: required: DROP VIEW required
|
307
|
+
[1m[36m (0.3ms)[0m [1mDROP VIEW required[0m
|
308
|
+
SQLite3::SQLException: no such view: required: DROP VIEW required
|
309
|
+
[1m[36m (0.3ms)[0m [1mDROP VIEW required[0m
|
310
|
+
SQLite3::SQLException: no such view: required: DROP VIEW required
|
311
|
+
[1m[36m (0.3ms)[0m [1mDROP VIEW required[0m
|
312
|
+
SQLite3::SQLException: no such view: required: DROP VIEW required
|
313
|
+
[1m[35m (0.1ms)[0m DROP VIEW hello_world
|
314
|
+
SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
|
315
|
+
[1m[36m (1.2ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
316
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
317
|
+
[1m[36m (0.8ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
318
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
319
|
+
[1m[36m (0.7ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
320
|
+
[1m[35m (0.7ms)[0m CREATE VIEW hello_world AS --!require required
|
321
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
322
|
+
[1m[36m (0.3ms)[0m [1mDROP VIEW required[0m
|
323
|
+
SQLite3::SQLException: no such view: required: DROP VIEW required
|
324
|
+
[1m[35m (0.2ms)[0m DROP VIEW hello_world
|
325
|
+
SQLite3::SQLException: no such view: hello_world: DROP VIEW hello_world
|
326
|
+
[1m[36m (1.0ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
327
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
328
|
+
[1m[36m (0.8ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
329
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
330
|
+
[1m[36m (4.8ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
331
|
+
[1m[35m (1.3ms)[0m CREATE VIEW hello_world AS --!require required
|
332
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
333
|
+
[1m[36m (0.9ms)[0m [1mCREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
|
334
|
+
BEGIN
|
335
|
+
RETURN x + y;
|
336
|
+
END;
|
337
|
+
$$ LANGUAGE plpgsql; add[0m
|
338
|
+
PG::SyntaxError: ERROR: syntax error at or near "("
|
339
|
+
LINE 1: CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS in...
|
340
|
+
^
|
341
|
+
: CREATE OR REPLACE FUNCTION (x integer, y integer) RETURNS integer AS $$
|
342
|
+
BEGIN
|
343
|
+
RETURN x + y;
|
344
|
+
END;
|
345
|
+
$$ LANGUAGE plpgsql; add
|
346
|
+
[1m[36m (0.3ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
347
|
+
BEGIN
|
348
|
+
RETURN x + y;
|
349
|
+
END;
|
350
|
+
$$ LANGUAGE plpgsql; add[0m
|
351
|
+
PG::SyntaxError: ERROR: syntax error at or near "add"
|
352
|
+
LINE 5: $$ LANGUAGE plpgsql; add
|
353
|
+
^
|
354
|
+
: CREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
355
|
+
BEGIN
|
356
|
+
RETURN x + y;
|
357
|
+
END;
|
358
|
+
$$ LANGUAGE plpgsql; add
|
359
|
+
[1m[36m (8.7ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
360
|
+
BEGIN
|
361
|
+
RETURN x + y;
|
362
|
+
END;
|
363
|
+
$$ LANGUAGE plpgsql;[0m
|
364
|
+
[1m[35m (17.7ms)[0m DROP VIEW required
|
365
|
+
PG::UndefinedTable: ERROR: view "required" does not exist
|
366
|
+
: DROP VIEW required
|
367
|
+
[1m[36m (0.3ms)[0m [1mDROP VIEW hello_world[0m
|
368
|
+
PG::UndefinedTable: ERROR: view "hello_world" does not exist
|
369
|
+
: DROP VIEW hello_world
|
370
|
+
[1m[35m (24.1ms)[0m CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
|
371
|
+
[1m[36m (1.0ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
372
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
373
|
+
[1m[36m (23.3ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
374
|
+
[1m[35m (5.5ms)[0m CREATE VIEW hello_world AS --!require required
|
375
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
376
|
+
[1m[36m (12.3ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
377
|
+
BEGIN
|
378
|
+
RETURN x + y;
|
379
|
+
END;
|
380
|
+
$$ LANGUAGE plpgsql;[0m
|
381
|
+
[1m[35m (10.6ms)[0m DROP VIEW required
|
382
|
+
PG::DependentObjectsStillExist: ERROR: cannot drop view required because other objects depend on it
|
383
|
+
DETAIL: view hello_world depends on view required
|
384
|
+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
|
385
|
+
: DROP VIEW required
|
386
|
+
[1m[36m (18.0ms)[0m [1mDROP VIEW hello_world[0m
|
387
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
388
|
+
[1m[36m (0.2ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
389
|
+
PG::DuplicateTable: ERROR: relation "required" already exists
|
390
|
+
: CREATE VIEW required AS SELECT 1 as id
|
391
|
+
[1m[36m (2.5ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
392
|
+
BEGIN
|
393
|
+
RETURN x + y;
|
394
|
+
END;
|
395
|
+
$$ LANGUAGE plpgsql;[0m
|
396
|
+
[1m[35m (1.0ms)[0m DROP VIEW required
|
397
|
+
[1m[36m (0.4ms)[0m [1mDROP VIEW hello_world[0m
|
398
|
+
PG::UndefinedTable: ERROR: view "hello_world" does not exist
|
399
|
+
: DROP VIEW hello_world
|
400
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.4ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
401
|
+
[1m[36m (8.1ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
402
|
+
[1m[35m (6.6ms)[0m CREATE VIEW hello_world AS --!require required
|
403
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
404
|
+
[1m[36m (2.0ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
405
|
+
BEGIN
|
406
|
+
RETURN x + y;
|
407
|
+
END;
|
408
|
+
$$ LANGUAGE plpgsql;[0m
|
409
|
+
[1m[35m (0.6ms)[0m DROP VIEW required
|
410
|
+
PG::DependentObjectsStillExist: ERROR: cannot drop view required because other objects depend on it
|
411
|
+
DETAIL: view hello_world depends on view required
|
412
|
+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
|
413
|
+
: DROP VIEW required
|
414
|
+
[1m[36m (0.9ms)[0m [1mDROP VIEW hello_world[0m
|
415
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.5ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
416
|
+
[1m[36m (0.3ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
417
|
+
PG::DuplicateTable: ERROR: relation "required" already exists
|
418
|
+
: CREATE VIEW required AS SELECT 1 as id
|
419
|
+
[1m[36m (2.1ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
420
|
+
BEGIN
|
421
|
+
RETURN x + y;
|
422
|
+
END;
|
423
|
+
$$ LANGUAGE plpgsql;[0m
|
424
|
+
[1m[35m (0.9ms)[0m DROP VIEW required
|
425
|
+
[1m[36m (0.3ms)[0m [1mDROP VIEW hello_world[0m
|
426
|
+
PG::UndefinedTable: ERROR: view "hello_world" does not exist
|
427
|
+
: DROP VIEW hello_world
|
428
|
+
[1m[36m (2.0ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
429
|
+
BEGIN
|
430
|
+
RETURN x + y;
|
431
|
+
END;
|
432
|
+
$$ LANGUAGE plpgsql;[0m
|
433
|
+
[1m[35m (0.3ms)[0m DROP VIEW required
|
434
|
+
PG::UndefinedTable: ERROR: view "required" does not exist
|
435
|
+
: DROP VIEW required
|
436
|
+
[1m[36m (2.1ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
437
|
+
BEGIN
|
438
|
+
RETURN x + y;
|
439
|
+
END;
|
440
|
+
$$ LANGUAGE plpgsql;[0m
|
441
|
+
[1m[35m (0.3ms)[0m DROP VIEW required
|
442
|
+
PG::UndefinedTable: ERROR: view "required" does not exist
|
443
|
+
: DROP VIEW required
|
444
|
+
[1m[36m (2.0ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
445
|
+
BEGIN
|
446
|
+
RETURN x + y;
|
447
|
+
END;
|
448
|
+
$$ LANGUAGE plpgsql;[0m
|
449
|
+
[1m[35m (0.3ms)[0m DROP VIEW required
|
450
|
+
PG::UndefinedTable: ERROR: view "required" does not exist
|
451
|
+
: DROP VIEW required
|
452
|
+
[1m[36m (0.2ms)[0m [1mDROP VIEW hello_world[0m
|
453
|
+
PG::UndefinedTable: ERROR: view "hello_world" does not exist
|
454
|
+
: DROP VIEW hello_world
|
455
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
456
|
+
[1m[36m (6.7ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
457
|
+
[1m[35m (6.6ms)[0m CREATE VIEW hello_world AS --!require required
|
458
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
459
|
+
[1m[36m (2.3ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
460
|
+
BEGIN
|
461
|
+
RETURN x + y;
|
462
|
+
END;
|
463
|
+
$$ LANGUAGE plpgsql;[0m
|
464
|
+
[1m[35m (0.7ms)[0m DROP VIEW required
|
465
|
+
PG::DependentObjectsStillExist: ERROR: cannot drop view required because other objects depend on it
|
466
|
+
DETAIL: view hello_world depends on view required
|
467
|
+
HINT: Use DROP ... CASCADE to drop the dependent objects too.
|
468
|
+
: DROP VIEW required
|
469
|
+
[1m[36m (3.0ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
470
|
+
BEGIN
|
471
|
+
RETURN x + y;
|
472
|
+
END;
|
473
|
+
$$ LANGUAGE plpgsql;[0m
|
474
|
+
[1m[36m (1.4ms)[0m [1mCREATE OR REPLACE FUNCTION add (x integer, y integer) RETURNS integer AS $$
|
475
|
+
BEGIN
|
476
|
+
RETURN x + y;
|
477
|
+
END;
|
478
|
+
$$ LANGUAGE plpgsql;[0m
|
479
|
+
[1m[35m (1.2ms)[0m DROP VIEW hello_world
|
480
|
+
[1m[36m (0.6ms)[0m [1mDROP VIEW required[0m
|
481
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.3ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
482
|
+
[1m[36m (12.4ms)[0m [1mCREATE VIEW required AS SELECT 1 as id[0m
|
483
|
+
[1m[35m (12.6ms)[0m CREATE VIEW hello_world AS --!require required
|
484
|
+
SELECT 'HelloWorld' WHERE ( SELECT id FROM required ) IN (1)
|
metadata
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_db_views
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yacine Petitprez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
17
20
|
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: '4.0'
|
@@ -21,6 +24,9 @@ dependencies:
|
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4'
|
24
30
|
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
32
|
version: '4.0'
|
@@ -29,6 +35,9 @@ dependencies:
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.2'
|
40
|
+
- - ">="
|
32
41
|
- !ruby/object:Gem::Version
|
33
42
|
version: 1.2.3
|
34
43
|
type: :runtime
|
@@ -36,6 +45,9 @@ dependencies:
|
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
47
|
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.2'
|
50
|
+
- - ">="
|
39
51
|
- !ruby/object:Gem::Version
|
40
52
|
version: 1.2.3
|
41
53
|
- !ruby/object:Gem::Dependency
|
@@ -52,7 +64,21 @@ dependencies:
|
|
52
64
|
- - ">="
|
53
65
|
- !ruby/object:Gem::Version
|
54
66
|
version: '0'
|
55
|
-
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: pg
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
description: Provide tools to create and manage database view through Rails project.
|
56
82
|
email:
|
57
83
|
- anykeyh@gmail.com
|
58
84
|
executables: []
|
@@ -62,9 +88,13 @@ files:
|
|
62
88
|
- LICENSE
|
63
89
|
- Rakefile
|
64
90
|
- lib/rails_db_views.rb
|
65
|
-
- lib/rails_db_views/
|
91
|
+
- lib/rails_db_views/configuration.rb
|
92
|
+
- lib/rails_db_views/database_symbol.rb
|
93
|
+
- lib/rails_db_views/factory.rb
|
94
|
+
- lib/rails_db_views/function.rb
|
66
95
|
- lib/rails_db_views/railtie.rb
|
67
96
|
- lib/rails_db_views/version.rb
|
97
|
+
- lib/rails_db_views/view.rb
|
68
98
|
- lib/tasks/rails_db_views_tasks.rake
|
69
99
|
- test/dummy/README.rdoc
|
70
100
|
- test/dummy/Rakefile
|
@@ -94,7 +124,9 @@ files:
|
|
94
124
|
- test/dummy/config/locales/en.yml
|
95
125
|
- test/dummy/config/routes.rb
|
96
126
|
- test/dummy/db/development.sqlite3
|
127
|
+
- test/dummy/db/functions/add.sql
|
97
128
|
- test/dummy/db/schema.rb
|
129
|
+
- test/dummy/db/test.sqlite3
|
98
130
|
- test/dummy/db/views/hello_world.sql
|
99
131
|
- test/dummy/db/views/required.sql
|
100
132
|
- test/dummy/log/development.log
|
@@ -124,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
156
|
version: '0'
|
125
157
|
requirements: []
|
126
158
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.4.8
|
128
160
|
signing_key:
|
129
161
|
specification_version: 4
|
130
162
|
summary: Provide tools to create and manage database view through Rails project.
|
@@ -155,7 +187,9 @@ test_files:
|
|
155
187
|
- test/dummy/config/routes.rb
|
156
188
|
- test/dummy/config.ru
|
157
189
|
- test/dummy/db/development.sqlite3
|
190
|
+
- test/dummy/db/functions/add.sql
|
158
191
|
- test/dummy/db/schema.rb
|
192
|
+
- test/dummy/db/test.sqlite3
|
159
193
|
- test/dummy/db/views/hello_world.sql
|
160
194
|
- test/dummy/db/views/required.sql
|
161
195
|
- test/dummy/log/development.log
|
@@ -1,104 +0,0 @@
|
|
1
|
-
class RailsDbViews::DbViewsCreator
|
2
|
-
attr_reader :views
|
3
|
-
|
4
|
-
def initialize
|
5
|
-
@views = {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def register_files files
|
9
|
-
files.each do |file|
|
10
|
-
view_name = File.basename(file, File.extname(file))
|
11
|
-
|
12
|
-
content = File.read(file)
|
13
|
-
content_lines = content.split("\n")
|
14
|
-
|
15
|
-
# Reject the commented lines from the file
|
16
|
-
sql_content = content_lines.reject{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.join("\n")
|
17
|
-
|
18
|
-
file_obj = { path: file, sql_content: sql_content, status: :none, requires: [] }
|
19
|
-
|
20
|
-
# Detect directives in commentary
|
21
|
-
directives = content_lines.select{ |x| x.strip =~ /^--/ || x.strip =~ /^#/ }.map(&:strip).map{ |x|
|
22
|
-
x =~ /^--/ ? x[2..-1] : x[1..-1]
|
23
|
-
}.select{|x| x =~ /^!/ }
|
24
|
-
|
25
|
-
directives.each do |directive|
|
26
|
-
if directive =~ /^!require / #Currently only the require directive exists.
|
27
|
-
file_obj[:requires] += directive.split(" ")[1..-1]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
if @views[view_name]
|
32
|
-
puts "WARNING: #{view_name} already defined in `#{@views[view_name][:path]}`. Will be ignored and we use `#{file_obj[:path]}`..."
|
33
|
-
end
|
34
|
-
|
35
|
-
@views[view_name] = file_obj
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def drop_views
|
40
|
-
reset_views_status!
|
41
|
-
@views.each{ |name, view|
|
42
|
-
drop_view name, view
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_views
|
47
|
-
reset_views_status!
|
48
|
-
@views.each{ |name, view|
|
49
|
-
create_view name, view
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
def reset_views_status!
|
55
|
-
@views.each{ |name, view|
|
56
|
-
view[:status] = :none
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
def drop_view name, view
|
62
|
-
return if view[:status] == :loaded
|
63
|
-
|
64
|
-
if view[:status] == :inprogress
|
65
|
-
raise "Error: Circular file reference! (view #{name})"
|
66
|
-
end
|
67
|
-
|
68
|
-
view[:requires].each do |other_view|
|
69
|
-
drop_view other_view, @views[other_view]
|
70
|
-
end
|
71
|
-
|
72
|
-
sql = "DROP VIEW #{name}"
|
73
|
-
begin
|
74
|
-
ActiveRecord::Base.connection.execute(sql)
|
75
|
-
puts "DROP VIEW #{name}... OK"
|
76
|
-
rescue
|
77
|
-
puts "WARNING: DROP VIEW #{name}... ERROR"
|
78
|
-
end
|
79
|
-
|
80
|
-
view[:status] = :loaded
|
81
|
-
end
|
82
|
-
|
83
|
-
def create_view name, view
|
84
|
-
# View already loaded.
|
85
|
-
return if view[:status] == :loaded
|
86
|
-
|
87
|
-
if view[:status] == :inprogress
|
88
|
-
raise "Error: Circular file reference! (view #{name})"
|
89
|
-
end
|
90
|
-
|
91
|
-
view[:status] = :inprogress
|
92
|
-
|
93
|
-
view[:requires].each do |other_view|
|
94
|
-
create_view other_view, @views[other_view]
|
95
|
-
end
|
96
|
-
|
97
|
-
sql = "CREATE VIEW #{name} AS #{view[:sql_content]}"
|
98
|
-
ActiveRecord::Base.connection.execute(sql)
|
99
|
-
puts "CREATE VIEW #{name} AS... OK"
|
100
|
-
|
101
|
-
view[:status] = :loaded
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|