feat: Omit Columns from SQL statements (e.g uuid columns) #802
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've added two options for omitting columns from the SQL statements, to avoid having to modify class level
self.ignored_columns
since we've had issues with this affecting other code that runs at the same time. These options work as follows:Omit the guid column from SQL statement, allowing it to generate the uuid and not be forced to NULL:
Model.import(values, omit_columns: [:guid])
Allow per-model decisions, e.g for recursive imports:
Model.import(values, omit_columns: -> (model, column_name) { [:guid] if model == Model })
Use a hash instead of a proc:
Model.import(values, omit_columns: { Model => [:guid] })
The second option is
:omit_columns_with_default_functions
boolean, to automatically find columns that have a default function declared in the schema, and omit them by default.