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

Move models/db to modules/db #22881

Closed
wants to merge 1 commit into from

Conversation

delvh
Copy link
Member

@delvh delvh commented Feb 12, 2023

This fixes quite a few imports to models inside modules.
In addition, it is the conceptually better fitting place for a package that has no application-specific dependencies but a lot of dependents.

This fixes quite a few imports to `models` inside `modules`, and is the
conceptually better fitting place for a package that has no application
specific outgoing dependencies but a lot of dependents.
@delvh delvh added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Feb 12, 2023
@delvh delvh added this to the 1.19.0 milestone Feb 12, 2023
@delvh delvh self-assigned this Feb 12, 2023
@delvh
Copy link
Member Author

delvh commented Feb 12, 2023

Why does the linter fail, even though my local make fmt doesn't change anything?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 12, 2023
@zeripath
Copy link
Contributor

Not sure about this. The idea was that modules would not be dependent on db or the models.

Why does this help?

@delvh
Copy link
Member Author

delvh commented Feb 12, 2023

In theory, I absolutely agree.
But then please explain to me why the changes between https://github.com/go-gitea/gitea/pull/22881/files#diff-df6792f0bd4f2d349508731c08110a47e5cf0c9559f863f9bb5d7c37cd4f1240 and https://github.com/go-gitea/gitea/pull/22881/files#diff-fa07e296d614e796de67f7ae9268a0660b89c09b6e5f6373b4ca7bf76a20dec7 were necessary…
Apparently, that rule wasn't kept previously.
I'm simply trying to untangle this import mess we've already produced to stay consistent with what our Docs say on how Gitea is structured (https://docs.gitea.io/en-us/guidelines-backend/#package-dependencies).
And as I said in the body of this PR, you can even argue that modules is a better root package for this package, as it only depends on modules/settings, and nothing else. And as shown above, even a lot of already existing code in modules depends on it.

@wxiaoguang
Copy link
Contributor

I think the db package is better to be kept in the models package, and refactor other dependencies.

The reason of putting the db package in models is that they are all database-related, while modules should do their best not touch database directly.

The purpose of defining the dependency order is to make the structure clear, and sometimes it's just difficult to strictly follow that pre-defined order.

My opinion is:

  • Do the best to keep the structure import order (say, just do the best, but not strictly follow)
  • If the db in the models is by purpose and clearer, I think it's good to keep it there, while refactor other packages.
  • If the benefit is not big enough, keep restraint for refactoring

I drafted a refactoring guideline in #22880 (I have experiences for maintaining systems which are 10 years old and refactoring them to modern, there are some my opinions to share).

@lunny
Copy link
Member

lunny commented Feb 14, 2023

Looks like there is no difference between putting db in models or modules, so we can keep it as before.

@delvh
Copy link
Member Author

delvh commented Feb 14, 2023

This refactoring seems to be unwanted.

@delvh delvh closed this Feb 14, 2023
@delvh delvh deleted the maintenance/move-db-to-modules branch February 14, 2023 12:12
@zeripath
Copy link
Contributor

@delvh thanks for trying though!

We should instead finish the move to make the dependency tree:

routers -> services -> models -> modules

So if a package in modules relies on models it should be moved to services or reconsidered entirely

@delvh
Copy link
Member Author

delvh commented Feb 14, 2023

😒 That's what this PR attempted to do in the least intrusive way.
Everything else will result in equivalent behavior, but with a lot more refactoring work.

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants