Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introspect columns to include default, generated and identity columns #256

Merged
merged 2 commits into from
Jan 16, 2024

Conversation

soupi
Copy link
Contributor

@soupi soupi commented Jan 16, 2024

What

In order to generate insert mutations we'd like to know which columns should be inserted into, which we shouldn't insert to, and which can go either way.
To do that we add settings for default, generated, and identity information to column information, as well as introspection code.

How

  1. We create an enum for each setting, and include that information in ColumnInfo metadata
  2. We add SQL introspection and query this information from pg_attribute, but see the comment about generated columns

@soupi soupi requested a review from plcplc January 16, 2024 09:47
#[serde(default)]
pub description: Option<String>,
}

fn does_not_have_default(has_default: &HasDefault) -> bool {
matches!(has_default, HasDefault::NoDefault)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a clippy suggestion :)

Comment on lines +113 to +115
-- skipped because yugabyte is based on pg11 that does not have this field.
-- CASE WHEN att.attgenerated = 's' THEN 'isGenerated' ELSE 'notGenerated' END
-- AS is_generated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a trick being employed in pg_table_metadata.sql of HGE v2 which deals with this very issue. It could well be worth it to port that over.

Copy link
Contributor Author

@soupi soupi Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good to know, for reference: https://github.com/hasura/graphql-engine/blob/master/server/src-rsr/pg_table_metadata.sql#L70-75

Will do that in a follow-up PR.

@soupi soupi added this pull request to the merge queue Jan 16, 2024
Merged via the queue into main with commit a014373 Jan 16, 2024
26 checks passed
@soupi soupi deleted the gil/add-identity-default-generated branch January 16, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants