Class: DB::Features
- Inherits:
-
Object
- Object
- DB::Features
- Defined in:
- lib/db/features.rb
Overview
Standardized feature detection for database adapters. All features default to false, and adapters can enable specific capabilities.
Instance Method Summary collapse
-
#alter_column_type? ⇒ Boolean
PostgreSQL-style column type modification: ALTER COLUMN name TYPE type USING expression.
-
#auto_increment? ⇒ Boolean
MySQL-style AUTO_INCREMENT auto-increment columns.
-
#batch_alter_table? ⇒ Boolean
Multiple operations can be combined in a single ALTER TABLE statement.
-
#concurrent_schema? ⇒ Boolean
Support for concurrent/online schema changes.
-
#conditional_operations? ⇒ Boolean
Support for IF EXISTS/IF NOT EXISTS clauses.
-
#deferred_constraints? ⇒ Boolean
Support for adding constraints with validation deferred.
-
#enabled?(feature) ⇒ Boolean
Check if a specific feature is enabled.
-
#enabled_features ⇒ Object
Get all enabled features.
-
#identity_columns? ⇒ Boolean
Support for IDENTITY columns (SQL Server/newer PostgreSQL).
-
#initialize(**features) ⇒ Features
constructor
A new instance of Features.
-
#integer_primary_key_autoincrement? ⇒ Boolean
SQLite-style INTEGER PRIMARY KEY auto-increment.
-
#modify_column? ⇒ Boolean
MySQL-style column modification: MODIFY COLUMN name type.
-
#serial_columns? ⇒ Boolean
PostgreSQL-style SERIAL/BIGSERIAL auto-increment columns.
-
#transactional_schema? ⇒ Boolean
Schema operations can be rolled back within transactions.
-
#using_clause? ⇒ Boolean
Support for USING clause in column type changes.
-
#with(**additional_features) ⇒ Object
Create a new Features instance with additional or modified features.
Constructor Details
#initialize(**features) ⇒ Features
Returns a new instance of Features.
10 11 12 |
# File 'lib/db/features.rb', line 10 def initialize(**features) @features = features end |
Instance Method Details
#alter_column_type? ⇒ Boolean
PostgreSQL-style column type modification: ALTER COLUMN name TYPE type USING expression.
30 31 32 |
# File 'lib/db/features.rb', line 30 def alter_column_type? @features.fetch(:alter_column_type, false) end |
#auto_increment? ⇒ Boolean
MySQL-style AUTO_INCREMENT auto-increment columns.
75 76 77 |
# File 'lib/db/features.rb', line 75 def auto_increment? @features.fetch(:auto_increment, false) end |
#batch_alter_table? ⇒ Boolean
Multiple operations can be combined in a single ALTER TABLE statement.
55 56 57 |
# File 'lib/db/features.rb', line 55 def batch_alter_table? @features.fetch(:batch_alter_table, false) end |
#concurrent_schema? ⇒ Boolean
Support for concurrent/online schema changes.
60 61 62 |
# File 'lib/db/features.rb', line 60 def concurrent_schema? @features.fetch(:concurrent_schema, false) end |
#conditional_operations? ⇒ Boolean
Support for IF EXISTS/IF NOT EXISTS clauses.
45 46 47 |
# File 'lib/db/features.rb', line 45 def conditional_operations? @features.fetch(:conditional_operations, false) end |
#deferred_constraints? ⇒ Boolean
Support for adding constraints with validation deferred.
65 66 67 |
# File 'lib/db/features.rb', line 65 def deferred_constraints? @features.fetch(:deferred_constraints, false) end |
#enabled?(feature) ⇒ Boolean
Check if a specific feature is enabled.
15 16 17 |
# File 'lib/db/features.rb', line 15 def enabled?(feature) @features.fetch(feature, false) end |
#enabled_features ⇒ Object
Get all enabled features.
20 21 22 |
# File 'lib/db/features.rb', line 20 def enabled_features @features.select{|_, enabled| enabled}.keys end |
#identity_columns? ⇒ Boolean
Support for IDENTITY columns (SQL Server/newer PostgreSQL).
85 86 87 |
# File 'lib/db/features.rb', line 85 def identity_columns? @features.fetch(:identity_columns, false) end |
#integer_primary_key_autoincrement? ⇒ Boolean
SQLite-style INTEGER PRIMARY KEY auto-increment.
80 81 82 |
# File 'lib/db/features.rb', line 80 def integer_primary_key_autoincrement? @features.fetch(:integer_primary_key_autoincrement, false) end |
#modify_column? ⇒ Boolean
MySQL-style column modification: MODIFY COLUMN name type.
35 36 37 |
# File 'lib/db/features.rb', line 35 def modify_column? @features.fetch(:modify_column, false) end |
#serial_columns? ⇒ Boolean
PostgreSQL-style SERIAL/BIGSERIAL auto-increment columns.
70 71 72 |
# File 'lib/db/features.rb', line 70 def serial_columns? @features.fetch(:serial_columns, false) end |
#transactional_schema? ⇒ Boolean
Schema operations can be rolled back within transactions.
50 51 52 |
# File 'lib/db/features.rb', line 50 def transactional_schema? @features.fetch(:transactional_schema, false) end |
#using_clause? ⇒ Boolean
Support for USING clause in column type changes.
40 41 42 |
# File 'lib/db/features.rb', line 40 def using_clause? @features.fetch(:using_clause, false) end |
#with(**additional_features) ⇒ Object
Create a new Features instance with additional or modified features.
25 26 27 |
# File 'lib/db/features.rb', line 25 def with(**additional_features) self.class.new(**@features, **additional_features) end |