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

Struct validation #186

Merged
merged 27 commits into from
Sep 3, 2021
Merged

Struct validation #186

merged 27 commits into from
Sep 3, 2021

Conversation

tsmethurst
Copy link
Contributor

@tsmethurst tsmethurst commented Sep 2, 2021

This PR adds validation tags for all database model structs, and adds a struct validator in internal/validate, as well as tests for all of the defined structs.

It also reworks some of the structure of the packages to make a bit more sense, and adds a stub for Bun migration.

gtsmodel is now the only place that contains structs that enter the database, and it only contains structs that enter the database. Reason for this: when we do migrations, we can basically copy-paste whatever the current state of gtsmodel is into a subfolder of migrations that pertains to the specific migration ID, so each migration has a copy of the gtsmodels it pertains to, as they were at the time the migration was created. This will make it easier to play back or forward from a specific migration.

Note that this test doesn't actually hook the validation into the database logic yet, it only adds struct tags and validation tests to prepare for creating these db hooks in future

Interesting stuff in the PR starts from here downwards:
https://github.com/superseriousbusiness/gotosocial/pull/186/files#diff-7c8fa43ec6d65ce61a4f0617935c0e2fae26f679ffb4ac43ac06f41437521fd3

Tests are here onwards: https://github.com/superseriousbusiness/gotosocial/pull/186/files#diff-52727fb181f9f77e0dc72951e43903d0fc5355ed355f71923fb91d2c60518c16

internal/federation/dereferencing/account.go Outdated Show resolved Hide resolved
internal/federation/federatingdb/accept.go Outdated Show resolved Hide resolved
internal/federation/federatingdb/undo.go Outdated Show resolved Hide resolved
internal/validate/structvalidation.go Outdated Show resolved Hide resolved
internal/db/bundb/migrations/main.go Show resolved Hide resolved
internal/gtsmodel/instance.go Show resolved Hide resolved
internal/gtsmodel/token.go Outdated Show resolved Hide resolved
internal/gtsmodel/token.go Show resolved Hide resolved
internal/gtsmodel/user.go Show resolved Hide resolved
internal/gtsmodel/user.go Outdated Show resolved Hide resolved
@NyaaaWhatsUpDoc
Copy link
Member

Just ran this PR with SQLite and confirmed all tests are passing. Aside from mentioned issues, looks good!

@NyaaaWhatsUpDoc NyaaaWhatsUpDoc merged commit 25edd57 into main Sep 3, 2021
@NyaaaWhatsUpDoc NyaaaWhatsUpDoc deleted the struct_validation branch September 3, 2021 09:27
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