feat: Omit Columns from SQL statements (e.g uuid columns)#802
Open
Amnesthesia wants to merge 3 commits intozdennis:masterfrom
Open
feat: Omit Columns from SQL statements (e.g uuid columns)#802Amnesthesia wants to merge 3 commits intozdennis:masterfrom
Amnesthesia wants to merge 3 commits intozdennis:masterfrom
Conversation
ffeb31a to
d3c99af
Compare
f190e54 to
b19a2ed
Compare
Author
|
Can this be merged or is this already implemented upstream? We're currently pointing our Gemfile to this branch and can't update until uuid primary keys are supported |
|
@Amnesthesia UUID primary keys already work, if they're following the standard naming convention, i.e. |
|
@Amnesthesia BTW, it's already possible to specify which columns should be imported. Pass an array of symbols as the first argument to |
Author
|
@jacob-carlborg-apoex This is for auto-generated UUID columns that are not primary keys :) |
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:
`Model.import(values, omit_columns: [:guid])` # Omit the guid column from SQL statement, allowing it to generate
`Model.import(values, omit_columns: -> (model, column_name) { [:guid] if model == Model })` Allow per-model decisions, e.g for recursive imports
`Model.import(values, omit_columns: { Model => [:guid] })` Use a hash instead of a proc
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.
fix: Require AR 5.0+
b19a2ed to
1226af2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_columnssince 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_functionsboolean, to automatically find columns that have a default function declared in the schema, and omit them by default.