Skip to content

Port network_zones to the database generator #1802

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

Open
stgraber opened this issue Mar 17, 2025 · 3 comments
Open

Port network_zones to the database generator #1802

stgraber opened this issue Mar 17, 2025 · 3 comments
Assignees
Labels
Easy Good for new contributors
Milestone

Comments

@stgraber
Copy link
Member

Incus uses a built-in code generator for most of its database interactions.
Unfortunately not all entities have yet been moved over to that mechanism, causing us to have far more SQL code in our code tree than we'd really like.

The goal here is to define new code generated functions in internal/server/db/cluster/ and then remove the old implementation from internal/server/db/ transitioning everything over to the new generated functions.

A recent example of the database generator being used can be found here:
#655

Note that some of the syntax has since evolved, so you may want to look at the current version of networks_integrations.go to see how to invoke the generator.

@stgraber stgraber added the Easy Good for new contributors label Mar 17, 2025
@stgraber stgraber added this to the soon milestone Mar 17, 2025
@irhndt
Copy link
Contributor

irhndt commented Mar 19, 2025

May I try this one so I'll get what is going on with database generated functions?

@stgraber
Copy link
Member Author

Sure! I assigned it to you now.

@irhndt
Copy link
Contributor

irhndt commented Mar 20, 2025

Hi, I was wondering do you know where I can find good documentation on go generate?

It seems network zone have many function to migrate and I cannot find good examples in the actual codebase to inspire from, so I would like to understand better.
Notably I haven't seen a DeleteOne-by-ID, or examples for functions such as GetNetworkZoneKeys, also we have some functions that takes tx *sql.Tx as the first parameter which is unusual compared to the usual ctx context.Context.
Therefore I'm wondering on the way of handling those cases that's why I'm asking if you have some documentation to learn from somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Easy Good for new contributors
Development

No branches or pull requests

2 participants