Skip to content

Conversation

@erezrokah
Copy link
Member

@erezrokah erezrokah commented Jul 21, 2023

Summary

Fixes #1106

Plugin validation was removed in https://github.com/cloudquery/plugin-sdk/pull/984/files#diff-95f04007d983a3bfdb080b338b9de5a8bbd73a3d65910fbe664f97788a9021b3.

As a result we don't validate tables and columns anymore, see resulted bug in cloudquery/cloudquery#12428.

This PR brings it back and per a better option puts the validation in the Init method. Other options:

  1. Have each plugin call .validate on the plugin side, probably after transformation here. Downside that each plugin needs to implement the call
  2. Have the validation done as a part of schema.TransformTables here. Downside it will happen before any custom transformation that are executed on tables like titleTransformer

Please note that before it was removed validate was called during NewPlugin which means it errored right after calling the serve command, meaning the plugin would not start. With this fix the plugin will error out during Init, which means you need to run sync/migrate to see the error


Use the following steps to ensure your PR is ready to be reviewed

  • Read the contribution guidelines 🧑‍🎓
  • Run go fmt to format your code 🖊
  • Lint your changes via golangci-lint run 🚨 (install golangci-lint here)
  • Update or add tests 🧪
  • Ensure the status checks below are successful ✅

@erezrokah erezrokah requested a review from yevgenypats as a code owner July 21, 2023 11:38
@github-actions github-actions bot added the fix label Jul 21, 2023
}

func (tt Tables) ValidateDuplicateTables() error {
tableNames := tt.TableNames()
Copy link
Member Author

Choose a reason for hiding this comment

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

Previous code only validated top level tables. Fixed it so it uses TableNames() which gives us relations too, and added a test

return fmt.Errorf("table name %q is not valid: table names must contain only lower-case letters, numbers and underscores, and must start with a lower-case letter or underscore", t.Name)
}
return nil
return ValidateTable(t)
Copy link
Member Author

@erezrokah erezrokah Jul 21, 2023

Choose a reason for hiding this comment

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

There's some refactoring to be done around the validation code as we have a separate schema/validators.go file which also has some code to validate table names. It currently only validates the length, so I added the call here

@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Patch coverage: 36.66% and project coverage change: +0.20% 🎉

Comparison is base (e1ea578) 48.66% compared to head (4d07755) 48.87%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1108      +/-   ##
==========================================
+ Coverage   48.66%   48.87%   +0.20%     
==========================================
  Files          86       87       +1     
  Lines        8012     8037      +25     
==========================================
+ Hits         3899     3928      +29     
+ Misses       3760     3749      -11     
- Partials      353      360       +7     
Files Changed Coverage Δ
plugin/plugin.go 33.33% <0.00%> (-1.45%) ⬇️
plugin/validate.go 28.57% <28.57%> (ø)
schema/table.go 54.87% <83.33%> (+5.43%) ⬆️

... and 1 file with indirect coverage changes

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

@github-actions
Copy link

github-actions bot commented Jul 21, 2023

⏱️ Benchmark results

Comparing with e1ea578

  • Glob-8 ns/op: 99.14 ⬇️ 0.08% decrease vs. e1ea578

@github-actions github-actions bot added fix and removed fix labels Jul 21, 2023
@erezrokah erezrokah force-pushed the fix/validate_plugin branch from 71451d3 to 4d07755 Compare August 18, 2023 08:05
@kodiakhq kodiakhq bot merged commit 61765a7 into cloudquery:main Aug 18, 2023
@erezrokah erezrokah deleted the fix/validate_plugin branch August 18, 2023 08:48
kodiakhq bot pushed a commit that referenced this pull request Aug 18, 2023
🤖 I have created a release *beep* *boop*
---


## [4.5.1](v4.5.0...v4.5.1) (2023-08-18)


### Bug Fixes

* Bring back plugin validation ([#1108](#1108)) ([61765a7](61765a7))
* **deps:** Update module github.com/cloudquery/plugin-pb-go to v1.9.3 ([#1149](#1149)) ([e1ea578](e1ea578))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.5.0 ([#1145](#1145)) ([70d12e4](70d12e4))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
kodiakhq bot pushed a commit that referenced this pull request Sep 5, 2023


Follow up to #1108. This PR relaxes the validation to check only for duplicates.
Some databases allow uppercase table tables and the validation in the SDK seemed to be PostgreSQL oriented.
At some point we might want to have destination specific validation/normalization.

Related to https://discord.com/channels/872925471417962546/873606591335759872/1148643989348679770

---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: Add a test to validate table names are unique per plugin

3 participants