schema_plus_views 0.2.3 → 0.4.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
- SHA1:
3
- metadata.gz: 3bd09e6485e8794d0454b7d3b6f9e79107f134d2
4
- data.tar.gz: a5ccbf2996d268630f616dded120613df7f9596a
2
+ SHA256:
3
+ metadata.gz: 764ef6eec1c0ff4459d83f12c562e0f05c29a3bfb69fd333184e0a7a05591c46
4
+ data.tar.gz: eb78bcad2c15b3c07a3dbbaee7e90626b914da1fb78d69c6bb478818a7b268e6
5
5
  SHA512:
6
- metadata.gz: 04ad39d4d0c9a6cdc8b2624326ff1fd3aac5e8ee3a95ef0fa3d84e17c0573494e2ffbe7de62f46f90bdac073278f9bbc0fd02b2d10db4bb493370f6e43caa2ed
7
- data.tar.gz: dbe18499e3d0108003110873f3738f99c0350870da6e5c7e338935b2a1f509a336554df69328f476348b10771cdd53a114865ca82c9e9d457f32d1da0e50b794
6
+ metadata.gz: 89a1a4eba2cd2c3f45e831d3525e71430da8a6171891947da8fe73abf1356b12424a94b23e59a7b570e6c5ed3f63062c7c1b6993f1990aba78561753d2b7b9eb
7
+ data.tar.gz: f569fa1e50557eadefd3c5bbf4975d6d2a6c0cdde63098ca8706f1c8775d83f999a46c7435fe957031040e2d05db0d0bd6ec36c54c05b140d7b22049807cf2e3
data/.travis.yml CHANGED
@@ -3,16 +3,87 @@
3
3
  # Please do not edit this file; any changes will be overwritten next time
4
4
  # schema_dev gets run.
5
5
  ---
6
- sudo: false
7
6
  rvm:
8
- - 2.1.5
7
+ - 2.5.9
8
+ - 2.7.3
9
9
  gemfile:
10
- - gemfiles/activerecord-4.2/Gemfile.mysql2
11
- - gemfiles/activerecord-4.2/Gemfile.postgresql
12
- - gemfiles/activerecord-4.2/Gemfile.sqlite3
13
- env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
14
- addons:
15
- postgresql: '9.4'
10
+ - gemfiles/activerecord-5.2/Gemfile.sqlite3
16
11
  before_script: bundle exec rake create_databases
17
12
  after_script: bundle exec rake drop_databases
18
13
  script: bundle exec rake travis
14
+ jobs:
15
+ include:
16
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.mysql2
17
+ rvm: 2.5.9
18
+ services:
19
+ - mysql
20
+ env: MYSQL_DB_USER=travis
21
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
22
+ rvm: 2.5.9
23
+ addons:
24
+ postgresql: '10'
25
+ apt:
26
+ packages:
27
+ - postgresql-10
28
+ - postgresql-client-10
29
+ env: POSTGRESQL_DB_USER=postgres
30
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
31
+ rvm: 2.5.9
32
+ addons:
33
+ postgresql: '11'
34
+ apt:
35
+ packages:
36
+ - postgresql-11
37
+ - postgresql-client-11
38
+ env: POSTGRESQL_DB_USER=travis PGPORT=5433
39
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
40
+ rvm: 2.5.9
41
+ addons:
42
+ postgresql: '12'
43
+ apt:
44
+ packages:
45
+ - postgresql-12
46
+ - postgresql-client-12
47
+ env: POSTGRESQL_DB_USER=travis PGPORT=5433
48
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
49
+ rvm: 2.5.9
50
+ addons:
51
+ postgresql: '9.6'
52
+ env: POSTGRESQL_DB_USER=postgres
53
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.mysql2
54
+ rvm: 2.7.3
55
+ services:
56
+ - mysql
57
+ env: MYSQL_DB_USER=travis
58
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
59
+ rvm: 2.7.3
60
+ addons:
61
+ postgresql: '11'
62
+ apt:
63
+ packages:
64
+ - postgresql-11
65
+ - postgresql-client-11
66
+ env: POSTGRESQL_DB_USER=travis PGPORT=5433
67
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
68
+ rvm: 2.7.3
69
+ addons:
70
+ postgresql: '12'
71
+ apt:
72
+ packages:
73
+ - postgresql-12
74
+ - postgresql-client-12
75
+ env: POSTGRESQL_DB_USER=travis PGPORT=5433
76
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
77
+ rvm: 2.7.3
78
+ addons:
79
+ postgresql: '10'
80
+ apt:
81
+ packages:
82
+ - postgresql-10
83
+ - postgresql-client-10
84
+ env: POSTGRESQL_DB_USER=postgres
85
+ - gemfile: gemfiles/activerecord-5.2/Gemfile.postgresql
86
+ rvm: 2.7.3
87
+ addons:
88
+ postgresql: '9.6'
89
+ env: POSTGRESQL_DB_USER=postgres
data/README.md CHANGED
@@ -28,7 +28,8 @@ SchemaPlus::Views is tested on:
28
28
 
29
29
  <!-- SCHEMA_DEV: MATRIX - begin -->
30
30
  <!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
31
- * ruby **2.1.5** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
31
+ * ruby **2.5.9** with activerecord **5.2**, using **mysql2**, **sqlite3** or **postgresql**
32
+ * ruby **2.7.3** with activerecord **5.2**, using **mysql2**, **sqlite3** or **postgresql**
32
33
 
33
34
  <!-- SCHEMA_DEV: MATRIX - end -->
34
35
 
@@ -56,9 +57,30 @@ Additional options can be provided:
56
57
 
57
58
  * `:allow_replace => true` will use the command "CREATE OR REPLACE" when creating the view, for seamlessly redefining the view even if other views depend on it. It's only supported by MySQL and PostgreSQL, and each has some limitations on when a view can be replaced; see their docs for details.
58
59
 
60
+ * `:materialized => true` will create a materialized view instead of a standard view. This view caches its contents on disk and must be refreshed to update its contents. It is only supported on PostgreSQL. Further, allow_replace is not supported on materialized views.
59
61
 
60
62
  SchemaPlus::Views also arranges to include the `create_view` statements (with literal SQL) in the schema dump.
61
63
 
64
+ #### Materialized views
65
+
66
+ Materialized views persist their data when created and must be manually refreshed to see new data.
67
+ Further materialized views can have indexes defined on them.
68
+
69
+ ```ruby
70
+ create_view :posts_commented_by_staff, <<~SQL, materialized: true
71
+ SELECT * FROM posts LEFT OUTER JOIN comments ON comments.post_id = posts.id WHERE comments.id IS NULL
72
+ SQL
73
+
74
+ add_index :posts_commented_by_staff, :category
75
+ add_index :posts_commented_by_staff, :token, unique: true
76
+ ```
77
+
78
+ To refresh a materialized view run the refresh_view connection command.
79
+
80
+ ```ruby
81
+ ActiveRecord::Base.connection.refresh_view('posts_commented_by_staff')
82
+ ```
83
+
62
84
  ### Dropping views
63
85
 
64
86
  In a migration:
@@ -66,6 +88,10 @@ In a migration:
66
88
  ```ruby
67
89
  drop_view :posts_commented_by_staff
68
90
  drop_view :uncommented_posts, :if_exists => true
91
+
92
+ # materialized views
93
+ drop_view :posts_commented_by_staff, materialized: true
94
+ drop_view :uncommented_posts, :if_exists => true, materialized: true
69
95
  ```
70
96
 
71
97
  ### Using views
@@ -87,14 +113,16 @@ You can look up the defined views analogously to looking up tables:
87
113
 
88
114
  ```ruby
89
115
  connection.tables # => array of table names [method provided by ActiveRecord]
90
- connection.views # => array of view names [method provided by SchemaPlus::Views]
116
+ connection.views # => array of view names [method overridden by SchemaPlus::Views for postgres]
91
117
  ```
92
118
 
93
119
  Notes:
94
120
 
95
- 1. For Mysql and SQLite3, ActiveRecord's `connection.tables` method would return views as well as tables; SchemaPlus::Views normalizes them to return only tables.
96
-
97
- 2. For PostgreSQL, `connection.views` suppresses views prefixed with `pg_` as those are presumed to be internal.
121
+ 1. For PostgreSQL, `connection.views` suppresses views prefixed with `pg_` as those are presumed to be internal. Also it suppresses the "postgis" specifically named tables
122
+ - geography_columns
123
+ - geometry_columns
124
+ - raster_columns
125
+ - raster_overviews
98
126
 
99
127
  ### Querying view definitions
100
128
 
@@ -106,9 +134,67 @@ connection.view_definition(view_name) # => returns SQL string
106
134
 
107
135
  This returns just the body of the definition, i.e. the part after the `CREATE VIEW 'name' AS` command.
108
136
 
137
+ You can also lookup the type of view (regular or materialized) using
138
+
139
+ ```ruby
140
+ connection.view_type(view_name) # => returns a Symbol, either :view or :materialized
141
+ ```
142
+
143
+ ## Customization API: Middleware Stacks
144
+
145
+ All the methods defined by SchemaPlus::Views provide middleware stacks, in case you need to do any custom filtering, rewriting, triggering, or whatever. For info on how to use middleware stacks, see the READMEs of [schema_monkey](https://github.com/SchemaPlus/schema_monkey) and [schema_plus_core](https://github.com/SchemaPlus/schema_plus_core).
146
+
147
+ ### `Schema::ViewDefinition` stack
148
+
149
+ Wraps the `connection.view_full_definition` method. Env contains:
150
+
151
+ Env Field | Description | Initialized
152
+ --- | --- | ---
153
+ `:connection` | The current ActiveRecord connection | *context*
154
+ `:view_name` | The view to look up | *arg*
155
+ `:query_name` | Optional label for ActiveRecord logging | *arg*
156
+ `:definition` | The view definition SQL | `nil`
157
+ `:view_type` | The view type symbol. | :view`
158
+
159
+ The base implementation looks up the definition of the view named
160
+ `env.view_name` and assigns the result to `env.definition`
161
+
162
+ ### `Migration::CreateView` stack
163
+
164
+ Wraps the `migration.create_view` method. Env contains:
165
+
166
+ Env Field | Description | Initialized
167
+ --- | --- | ---
168
+ `:connection` | The current ActiveRecord connection | *context*
169
+ `:view_name` | The view name | *arg*
170
+ `:definition` | The view definition SQL | *arg*
171
+ `:options` | Create view options | *arg*
172
+
173
+ The base implementation creates the view named `env.view_name` using the
174
+ definition in `env.definition` with options in `env.options`
175
+
176
+ ### `Migration::DropView` stack
177
+
178
+ Wraps the `migration.drop_view` method. Env contains:
179
+
180
+ Env Field | Description | Initialized
181
+ --- | --- | ---
182
+ `:connection` | The current ActiveRecord connection | *context*
183
+ `:view_name` | The view name | *arg*
184
+ `:options` | Drop view options | *arg*
185
+
186
+ The base implementation drops the view named `env.view_name` using the
187
+ options in `env.options`
188
+
109
189
 
110
190
  ## History
111
191
 
192
+ * 0.4.1 - Corrected spacing around dumped schema
193
+ * 0.4.0 - Added support for Rails 5.2 and materialized views in PostgreSQL
194
+ * 0.3.1 - Upgrade schema_plus_core and schema_dev dependencies
195
+ * 0.3.0
196
+ - Added middleware stacks
197
+ - Bug fix: view_definition: strip white space from result (postgresql)
112
198
  * 0.2.3 - Remove unnecessary escaping in dump; use single-quote heredoc
113
199
  * 0.2.2 - Prettier dumps: use heredoc for definition string
114
200
  * 0.2.1 - Fix db:rollback
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gemspec :path => File.expand_path('..', __FILE__)
2
+ gemspec path: File.expand_path('..', __FILE__)
3
3
 
4
4
  File.exist?(gemfile_local = File.expand_path('../Gemfile.local', __FILE__)) and eval File.read(gemfile_local), binding, gemfile_local
@@ -0,0 +1,4 @@
1
+ base_gemfile = File.expand_path('../../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile)
3
+
4
+ gem "activerecord", ">= 5.2.0.beta0", "< 5.3"
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -1,5 +1,5 @@
1
- require "pathname"
2
- eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
1
+ base_gemfile = File.expand_path('../Gemfile.base', __FILE__)
2
+ eval File.read(base_gemfile), binding, base_gemfile
3
3
 
4
4
  platform :ruby do
5
5
  gem "sqlite3"
@@ -7,4 +7,4 @@ end
7
7
 
8
8
  platform :jruby do
9
9
  gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
- end
10
+ end
@@ -5,27 +5,50 @@ module SchemaPlus::Views
5
5
  # Create a view given the SQL definition. Specify :force => true
6
6
  # to first drop the view if it already exists.
7
7
  def create_view(view_name, definition, options={})
8
- definition = definition.to_sql if definition.respond_to? :to_sql
9
- if options[:force]
10
- drop_view(view_name, if_exists: true)
11
- end
8
+ SchemaMonkey::Middleware::Migration::CreateView.start(connection: self, view_name: view_name, definition: definition, options: options) do |env|
9
+ raise ArgumentError, 'Materialized views are not implemented or supported on this database' if options[:materialized]
10
+ definition = env.definition
11
+ view_name = env.view_name
12
+ options = env.options
13
+ definition = definition.to_sql if definition.respond_to? :to_sql
14
+ if options[:force]
15
+ drop_view(view_name, if_exists: true)
16
+ end
12
17
 
13
- command = if options[:allow_replace]
14
- "CREATE OR REPLACE"
15
- else
16
- "CREATE"
17
- end
18
+ command = if options[:allow_replace]
19
+ "CREATE OR REPLACE"
20
+ else
21
+ "CREATE"
22
+ end
18
23
 
19
- execute "#{command} VIEW #{quote_table_name(view_name)} AS #{definition}"
24
+ execute "#{command} VIEW #{quote_table_name(view_name)} AS #{definition}"
25
+ end
20
26
  end
21
27
 
22
28
  # Drop the named view. Specify :if_exists => true
23
29
  # to fail silently if the view doesn't exist.
24
30
  def drop_view(view_name, options = {})
25
- sql = "DROP VIEW"
26
- sql += " IF EXISTS" if options[:if_exists]
27
- sql += " #{quote_table_name(view_name)}"
28
- execute sql
31
+ SchemaMonkey::Middleware::Migration::DropView.start(connection: self, view_name: view_name, options: options) do |env|
32
+ raise ArgumentError, 'Materialized views are not implemented or supported on this database' if options[:materialized]
33
+ view_name = env.view_name
34
+ options = env.options
35
+ sql = "DROP VIEW"
36
+ sql += " IF EXISTS" if options[:if_exists]
37
+ sql += " #{quote_table_name(view_name)}"
38
+ execute sql
39
+ end
40
+ end
41
+
42
+ # Returns the SQL definition of a given view. This is
43
+ # the literal SQL would come after 'CREATVE VIEW viewname AS ' in
44
+ # the SQL statement to create a view.
45
+ def view_definition(view_name, name = nil)
46
+ view_full_definition(view_name, name).first
47
+ end
48
+
49
+ # Returns the view type of a given view. This is either :view or :materialized
50
+ def view_type(view_name, name = nil)
51
+ view_full_definition(view_name, name).second
29
52
  end
30
53
 
31
54
  #####################################################################
@@ -34,13 +57,13 @@ module SchemaPlus::Views
34
57
  # define them all. Defining them here only for reference.
35
58
  #
36
59
 
37
- # (abstract) Returns the names of all views, as an array of strings
38
- def views(name = nil) raise "Internal Error: Connection adapter didn't override abstract function"; [] end
60
+ # (abstract) Refreshes the given materialized view.
61
+ def refresh_view(view_name, name = nil) raise "Internal Error: Connection adapter didn't override abstract function"; end
39
62
 
40
- # (abstract) Returns the SQL definition of a given view. This is
63
+ # (abstract) Returns the SQL definition and type of a given view. This is
41
64
  # the literal SQL would come after 'CREATVE VIEW viewname AS ' in
42
- # the SQL statement to create a view.
43
- def view_definition(view_name, name = nil) raise "Internal Error: Connection adapter didn't override abstract function"; end
65
+ # the SQL statement to create a view. The type is either :view, or :materialized
66
+ def view_full_definition(view_name, name = nil) raise "Internal Error: Connection adapter didn't override abstract function"; end
44
67
  end
45
68
  end
46
69
  end
@@ -3,25 +3,22 @@ module SchemaPlus::Views
3
3
  module ConnectionAdapters
4
4
  module Mysql2Adapter
5
5
 
6
- def views(name = nil)
7
- views = []
8
- select_all("SELECT table_name FROM information_schema.views WHERE table_schema = SCHEMA()", name).each do |row|
9
- views << row["table_name"]
10
- end
11
- views
12
- end
6
+ def view_full_definition(view_name, name = nil)
7
+ data = SchemaMonkey::Middleware::Schema::ViewDefinition.start(connection: self, view_name: view_name, query_name: name, view_type: :view) { |env|
8
+ results = select_all("SELECT view_definition, check_option FROM information_schema.views WHERE table_schema = SCHEMA() AND table_name = #{quote(view_name)}", name)
9
+ if results.any?
10
+ row = results.first
11
+ sql = row["view_definition"]
12
+ sql.gsub!(%r{#{quote_table_name(current_database)}[.]}, '')
13
+ case row["check_option"]
14
+ when "CASCADED" then sql += " WITH CASCADED CHECK OPTION"
15
+ when "LOCAL" then sql += " WITH LOCAL CHECK OPTION"
16
+ end
17
+ env.definition = sql
18
+ end
19
+ }
13
20
 
14
- def view_definition(view_name, name = nil)
15
- results = select_all("SELECT view_definition, check_option FROM information_schema.views WHERE table_schema = SCHEMA() AND table_name = #{quote(view_name)}", name)
16
- return nil unless results.any?
17
- row = results.first
18
- sql = row["view_definition"]
19
- sql.gsub!(%r{#{quote_table_name(current_database)}[.]}, '')
20
- case row["check_option"]
21
- when "CASCADED" then sql += " WITH CASCADED CHECK OPTION"
22
- when "LOCAL" then sql += " WITH LOCAL CHECK OPTION"
23
- end
24
- sql
21
+ [data.definition, data.view_type]
25
22
  end
26
23
 
27
24
  end
@@ -2,27 +2,88 @@ module SchemaPlus::Views
2
2
  module ActiveRecord
3
3
  module ConnectionAdapters
4
4
  module PostgresqlAdapter
5
+ POSTGIS_VIEWS = %W[
6
+ geography_columns
7
+ geometry_columns
8
+ raster_columns
9
+ raster_overviews
10
+ ].freeze
5
11
 
6
- def views(name = nil) #:nodoc:
7
- sql = <<-SQL
8
- SELECT viewname
9
- FROM pg_views
10
- WHERE schemaname = ANY (current_schemas(false))
11
- AND viewname NOT LIKE 'pg\_%'
12
- SQL
13
- sql += " AND schemaname != 'postgis'" if adapter_name == 'PostGIS'
14
- query(sql, name).map { |row| row[0] }
12
+ # Create a view given the SQL definition. Specify :force => true
13
+ # to first drop the view if it already exists.
14
+ def create_view(view_name, definition, options={})
15
+ SchemaMonkey::Middleware::Migration::CreateView.start(connection: self, view_name: view_name, definition: definition, options: options) do |env|
16
+ definition = env.definition
17
+ view_name = env.view_name
18
+ options = env.options
19
+ definition = definition.to_sql if definition.respond_to? :to_sql
20
+
21
+ if options[:materialized] && options[:allow_replace]
22
+ raise ArgumentError, 'allow_replace is not supported for materialized views'
23
+ end
24
+
25
+ if options[:force]
26
+ drop_view(view_name, {if_exists: true}.merge(options.slice(:materialized)))
27
+ end
28
+
29
+ command = if options[:materialized]
30
+ "CREATE MATERIALIZED"
31
+ elsif options[:allow_replace]
32
+ "CREATE OR REPLACE"
33
+ else
34
+ "CREATE"
35
+ end
36
+
37
+ execute "#{command} VIEW #{quote_table_name(view_name)} AS #{definition}"
38
+ end
39
+ end
40
+
41
+ # Drop the named view. Specify :if_exists => true
42
+ # to fail silently if the view doesn't exist.
43
+ def drop_view(view_name, options = {})
44
+ SchemaMonkey::Middleware::Migration::DropView.start(connection: self, view_name: view_name, options: options) do |env|
45
+ view_name = env.view_name
46
+ options = env.options
47
+ materialized = options[:materialized] ? 'MATERIALIZED' : ''
48
+ sql = "DROP #{materialized} VIEW"
49
+ sql += " IF EXISTS" if options[:if_exists]
50
+ sql += " #{quote_table_name(view_name)}"
51
+ execute sql
52
+ end
15
53
  end
16
54
 
17
- def view_definition(view_name, name = nil) #:nodoc:
18
- result = query(<<-SQL, name)
19
- SELECT pg_get_viewdef(oid)
20
- FROM pg_class
21
- WHERE relkind = 'v'
22
- AND relname = '#{view_name}'
23
- SQL
24
- row = result.first
25
- row.first.chomp(';') unless row.nil?
55
+ # Refresh a materialized view.
56
+ def refresh_view(view_name, options = {})
57
+ SchemaMonkey::Middleware::Migration::RefreshView.start(connection: self, view_name: view_name, options: options) do |env|
58
+ view_name = env.view_name
59
+ sql = "REFRESH MATERIALIZED VIEW #{quote_table_name(view_name)}"
60
+ execute sql
61
+ end
62
+ end
63
+
64
+ def views #:nodoc:
65
+ # Filter out any view that begins with "pg_"
66
+ super.reject do |c|
67
+ c.start_with?("pg_") || POSTGIS_VIEWS.include?(c)
68
+ end
69
+ end
70
+
71
+ def view_full_definition(view_name, name = nil) #:nodoc:
72
+ data = SchemaMonkey::Middleware::Schema::ViewDefinition.start(connection: self, view_name: view_name, query_name: name, view_type: :view) { |env|
73
+ result = env.connection.query(<<-SQL, name)
74
+ SELECT pg_get_viewdef(oid), relkind
75
+ FROM pg_class
76
+ WHERE relkind in ('v', 'm')
77
+ AND relname = '#{env.view_name}'
78
+ SQL
79
+ row = result.first
80
+ unless row.nil?
81
+ env.definition = row.first.chomp(';').strip
82
+ env.view_type = :materialized if row.second == 'm'
83
+ end
84
+ }
85
+
86
+ [data.definition, data.view_type]
26
87
  end
27
88
 
28
89
  end
@@ -3,13 +3,14 @@ module SchemaPlus::Views
3
3
  module ConnectionAdapters
4
4
  module Sqlite3Adapter
5
5
 
6
- def views(name = nil)
7
- execute("SELECT name FROM sqlite_master WHERE type='view'", name).collect{|row| row["name"]}
8
- end
6
+ def view_full_definition(view_name, name = nil)
7
+ data = SchemaMonkey::Middleware::Schema::ViewDefinition.start(connection: self, view_name: view_name, query_name: name, view_type: :view) { |env|
8
+ sql = env.connection.execute("SELECT sql FROM sqlite_master WHERE type='view' AND name=#{quote(env.view_name)}", env.query_name).collect{|row| row["sql"]}.first
9
+ sql.sub!(/^CREATE VIEW \S* AS\s+/im, '') unless sql.nil?
10
+ env.definition = sql
11
+ }
9
12
 
10
- def view_definition(view_name, name = nil)
11
- sql = execute("SELECT sql FROM sqlite_master WHERE type='view' AND name=#{quote(view_name)}", name).collect{|row| row["sql"]}.first
12
- sql.sub(/^CREATE VIEW \S* AS\s+/im, '') unless sql.nil?
13
+ [data.definition, data.view_type]
13
14
  end
14
15
 
15
16
  end
@@ -11,7 +11,9 @@ module SchemaPlus::Views
11
11
  end
12
12
 
13
13
  def invert_create_view(args)
14
- [ :drop_view, [args.first] ]
14
+ options = {}
15
+ options[:materialized] = args[2][:materialized] if args[2].has_key?(:materialized)
16
+ [ :drop_view, [args.first, options] ]
15
17
  end
16
18
 
17
19
  end