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

NEOS-969: filter out defaults #1843

Merged
merged 6 commits into from
Apr 29, 2024
Merged

NEOS-969: filter out defaults #1843

merged 6 commits into from
Apr 29, 2024

Conversation

evisdrenova
Copy link
Contributor

No description provided.

Copy link

linear bot commented Apr 28, 2024

Copy link

vercel bot commented Apr 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
neosync-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2024 9:29pm
neosync-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2024 9:29pm

Copy link

codecov bot commented Apr 28, 2024

Codecov Report

Attention: Patch coverage is 64.70588% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 10.98%. Comparing base (363b8b3) to head (76dc6f7).
Report is 4 commits behind head on main.

Files Patch % Lines
...1alpha1/connection-data-service/connection-data.go 70.00% 4 Missing and 2 partials ⚠️
.../gen/go/protos/mgmt/v1alpha1/connection_data.pb.go 20.00% 4 Missing ⚠️
...rotos/mgmt/v1alpha1/connection_data.pb.validate.go 0.00% 1 Missing ⚠️
backend/pkg/sqlmanager/postgres-manager.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1843      +/-   ##
==========================================
- Coverage   17.15%   10.98%   -6.18%     
==========================================
  Files         214      119      -95     
  Lines       45003    37666    -7337     
==========================================
- Hits         7721     4136    -3585     
+ Misses      36317    32985    -3332     
+ Partials      965      545     -420     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@nickzelei nickzelei left a comment

Choose a reason for hiding this comment

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

thanks for working on this! Left a few comments.

Comment on lines 409 to 415
hasDefault := false
if col.ColumnDefault != nil {
// ColumnDefault is an interface we need to check the value to see if it's set or not
value := reflect.ValueOf(col.ColumnDefault)
hasDefault = !value.IsZero()
}

Copy link
Member

Choose a reason for hiding this comment

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

If you go into the system.sql file for postgres queries, there are two queries in there that can be updated that will make all of this code go away.

Look for this block (shows up twice):

    COALESCE(
        pg_catalog.pg_get_expr(d.adbin, d.adrelid),
        ''
    ) AS column_default,

That is the bit that calculates this column. However, sqlc isn't smart enough to know the type, so we just need to cast it to text like so:

    COALESCE(
        pg_catalog.pg_get_expr(d.adbin, d.adrelid),
        ''
    )::text AS column_default,

This will cause the Go struct to appear as a string. Then all of this reflect stuff can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sweet - didn't know this was there. Updated! Also had to update a few other places that relied on that column being an interface

@@ -66,6 +66,8 @@ message DatabaseColumn {
string data_type = 4;
// The isNullable Flag of the column
string is_nullable = 5;
// Indicates where the column has a default value
bool has_default = 6;
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest just returning the default value itself here instead of a computed. Since this is the database schema data, we might actually want to use that in the future. Then this can just be computed easily on the frontend.

Suggested change
bool has_default = 6;
optional string column_default = 6;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that can work - I was hesitant at first to do that because our front-end really doesn't touch much "actual" data right now, aka data that would be found in a column but the default value might be okay since I guess it's kinda like metadata? so in the future if we do a hybrid deployment, and we want to isolate any data to the backend/worker, then we would maybe have to reverse this to keep the front-end clean of any data. But maybe it's okay for now.

Comment on lines 77 to 80
!filters.hasDefault &&
transformer.source === TransformerSource.GENERATE_DEFAULT
) {
return true;
return false;
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand why this was changed.
We want this block to return true if the filter says that it has a default and the source is Generate default

Copy link
Member

@nickzelei nickzelei left a comment

Choose a reason for hiding this comment

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

LGTM

@evisdrenova evisdrenova merged commit 3b9a86f into main Apr 29, 2024
16 of 17 checks passed
@evisdrenova evisdrenova deleted the filterOutGenerateDefault branch April 29, 2024 21:31
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