Class: ActiveRecord::ConnectionAdapters::PostgreSQLMaterializedViewAlterer
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLMaterializedViewAlterer
- Includes:
- PostgreSQLExtensions::Utils
- Defined in:
- lib/active_record/postgresql_extensions/materialized_views.rb
Overview
Alters a PostgreSQL materialized view definition. This class isn’t really meant to be used directly. Instead, see the various PostgreSQLAdapter materialied views methods for usage.
Constant Summary collapse
- VALID_OPTIONS =
%w{ set_default drop_default owner_to rename_to set_schema set_options reset_options cluster_on remove_cluster }.freeze
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#base ⇒ Object
Returns the value of attribute base.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(base, name, actions, options = {}) ⇒ PostgreSQLMaterializedViewAlterer
constructor
:nodoc:.
-
#to_sql ⇒ Object
:nodoc:.
Methods included from PostgreSQLExtensions::Utils
#hash_or_array_of_hashes, #options_from_hash_or_string, #strip_heredoc
Constructor Details
#initialize(base, name, actions, options = {}) ⇒ PostgreSQLMaterializedViewAlterer
:nodoc:
206 207 208 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 206 def initialize(base, name, actions, = {}) #:nodoc: @base, @name, @actions, @options = base, name, actions, end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
192 193 194 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 192 def actions @actions end |
#base ⇒ Object
Returns the value of attribute base.
192 193 194 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 192 def base @base end |
#name ⇒ Object
Returns the value of attribute name.
192 193 194 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 192 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
192 193 194 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 192 def @options end |
Instance Method Details
#to_sql ⇒ Object
:nodoc:
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/active_record/postgresql_extensions/materialized_views.rb', line 210 def to_sql #:nodoc: all_sql = [] VALID_OPTIONS.each do |key| key = key.to_sym if actions.key?(key) sql = "ALTER MATERIALIZED VIEW " sql << "IF EXISTS " if [:if_exists] sql << "#{base.quote_view_name(name)} " sql << case key when :set_default expression = if actions[:set_default].is_a?(Hash) && actions[:set_default].key?(:expression) actions[:set_default][:expression] else base.quote(actions[:set_default]) end "ALTER COLUMN #{base.quote_column_name(actions[:column])} SET DEFAULT #{expression}" when :drop_default "ALTER COLUMN #{base.quote_column_name(actions[:drop_default])} DROP DEFAULT" when :owner_to "OWNER TO #{base.quote_role(actions[:owner_to])}" when :rename_to "RENAME TO #{base.quote_generic_ignore_scoped_schema(actions[:rename_to])}" when :set_schema "SET SCHEMA #{base.quote_schema(actions[:set_schema])}" when :set_options ActiveRecord::PostgreSQLExtensions::Features.check_feature(:view_set_options) "SET (#{(actions[:set_options])})" if actions[:set_options].present? when :reset_options ActiveRecord::PostgreSQLExtensions::Features.check_feature(:view_set_options) 'RESET (' << Array.wrap(actions[:reset_options]).collect { |value| base.quote_generic(value) }.join(", ") << ')' when :cluster_on "CLUSTER ON #{base.quote_generic(actions[:cluster_on])}" when :remove_cluster next unless actions[:remove_cluster] "SET WITHOUT CLUSTER" end all_sql << "#{sql};" end end all_sql.join("\n") end |