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

Migrate database to GORM and new schema #8

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jessegeens
Copy link

Following ADR-Reva-003, this PR refactors the sharing SQL logic to now use GORM, an ORM for Go. This change also comes with newly written unit tests for all the database logic.

@jessegeens jessegeens marked this pull request as ready for review January 8, 2025 08:35
@jessegeens jessegeens requested a review from glpatcern January 8, 2025 08:35
Copy link

@diocas diocas left a comment

Choose a reason for hiding this comment

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

Some questions and comments. Haven't had the time to review the tests yet.

share/model.go Outdated
"gorm.io/gorm"
)

// +---------------------------------+-----------------+------+-----+---------+----------------+
Copy link

Choose a reason for hiding this comment

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

This might be useful in the migration script, but I would clean it from here.

share/model.go Outdated
gorm.Model
UIDOwner string
UIDInitiator string
ItemType string // file | folder
Copy link

Choose a reason for hiding this comment

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

Enum? Btw, ResourceTypeToItem can return other strings.

Copy link
Author

Choose a reason for hiding this comment

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

Real Enum's don't exist in Go, but I can do something like this:

type ItemType string

const (
	ItemTypeFile      ItemType = "file"
	ItemTypeFolder    ItemType = "folder"
	ItemTypeReference ItemType = "reference"
	ItemTypeSymlink   ItemType = "symlink"
)

Copy link
Author

Choose a reason for hiding this comment

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

outside of this package you can then do share.ItemTypeFile for example (you can also do illegal values, but then you would have to do ItemType("illegal-value")), so I think this should at least make it clear and kind of enforces it

share/model.go Outdated

type ProtoShare struct {
// Including gorm.Model will embed a number of gorm-default fields
// such as creation_time, id etc
Copy link

Choose a reason for hiding this comment

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

Can you put the full list of defaults?

Copy link
Author

Choose a reason for hiding this comment

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

I'll maybe just remove the "// such as creation_time, id etc" then, you can see the fields by hovering over gorm.Model :)

Copy link

Choose a reason for hiding this comment

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

Remove it then!

share/model.go Outdated
InitialPath string
Inode string
FileSource int64
FileTarget string
Copy link

Choose a reason for hiding this comment

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

I no longer remember what was this FileSource and FileTarget. Maybe it would be worth to have some description for some of these fields. For future reference.

Copy link
Author

Choose a reason for hiding this comment

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

FileSource seems to be the same as ItemSource, i.e. the inode (this is true for all but 8 of the entries in the prod db). So this can maybe also be dropped.
FileTarget seems to be the last part of the path of the file, e.g. /MyFile.txt. Since we have the InitialPath now I think we could also drop this

Copy link

Choose a reason for hiding this comment

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

I think we decided to drop those, but I don't see a comment like that in the rfc file you did... Confirm in the code where these are used and drop them if ok.

share/model.go Outdated Show resolved Hide resolved
share/sql/sql.go Outdated Show resolved Hide resolved
share/sql/sql.go Outdated Show resolved Hide resolved
share/sql/sql.go Outdated Show resolved Hide resolved
share/sql/sql.go Outdated Show resolved Hide resolved
share/sql/sql.go Outdated Show resolved Hide resolved
@jessegeens jessegeens force-pushed the fix/tx-sharing branch 3 times, most recently from 6b8c45a to 7843bfb Compare January 10, 2025 16:03
@jessegeens jessegeens force-pushed the fix/tx-sharing branch 2 times, most recently from f2d54aa to 48683cf Compare January 13, 2025 12:16
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.

3 participants