-
Notifications
You must be signed in to change notification settings - Fork 23
DAO implementation, accounts table, seed script #6
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
Conversation
While working on DAO and REST, I find SshPublicKey hard to type, any objections to name the model as PubKey (table pubkeys) and REST endpoint /public_keys ? |
I am pushing initial DAO and REST API (POC only) implementation for Accounts. Do not merge, the implementation suffers from an interesting bug - I am getting all records pointing to the same struct for some reason :)
I will take a look on Monday, unless someone else can figure this one out. |
Fixed the problem, lint will fail tho. I will add error wrapping to DAO, however, I will need to turn off statement close check for the dao package:
As it is stated in the Go documentation: https://pkg.go.dev/database/sql#Stmt If a Stmt is prepared on a DB, it will remain usable for the lifetime of the DB. When the Stmt needs to execute on a new underlying connection, it will prepare itself on the new connection automatically. I am taking advantage of this in the DAO package, each DAO implementation prepares statements on the connection and when executed it the connection pool automatically creates them on the fly. They are never closed, that is what this lint is all about, but in this case it makes sense. We could close the statements at the end of each request but thats actually not needed. |
Ok fixed all the problems, DAO is now clean API with error wrapping, vastly improved also service package error wrapping and rendering. Removes SSH keys from this PR, I will implement it separately. |
Hmm the linter on CI errors out while its passing locally: Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: goanalysis_metalinter: execinquery: package "dao" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference Looks like an issue with master branch: golangci/golangci-lint#2851 |
fe7b1b0
to
1d9c036
Compare
Fixed, I upgraded GHA actions to v3 where appropriate and also pinned the goloangci-lint action to version 1.45 which works fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks quite ready to me, but I got a domain question: Do we even want to expose Accounts as API endpoints? It seems to me we do not, but I'm happy to be proven wrong.
"net/http" | ||
) | ||
|
||
func ListAccounts(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we even expose Accounts in API? it seems unecessary as the service should always run in a context of one account IMHO, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I know, but I wanted to create few example API calls with DAO so we have at least something, I had to start with Accounts because of dependencies. We will either delete REST operations completely or create an administrative role. It would be good if you could figure out if administrative roles are allowed by SRE or is something that is a good practice.
We can actually turn this into turnpike API which is only available from inside of our RH network.
END; | ||
$empty$ LANGUAGE 'plpgsql'; | ||
|
||
COMMIT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's still quite a lot of end lines missing ^_^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with git ls-files -z | while IFS= read -rd '' f; do tail -c1 < "$f" | read -r _ || echo >> "$f"; done
Added editorconfig for go project.
api/requests/get-account.http
Outdated
@@ -0,0 +1,3 @@ | |||
// @no-log | |||
GET http://localhost:8000/accounts/1 HTTP/1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this file? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped, that is a test file for HTTP Client plugin for GoLand/VSCode and others.
CREATE TABLE accounts | ||
( | ||
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | ||
account_number TEXT NOT NULL UNIQUE CHECK (NOT empty(account_number)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong as account_numer is being phased out and I've read that there are already CUs that do not have account_number, so we might want to have this null or at least empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know for sure, if I have to choose between get that info and store it to only drop it later or ignore this and solve when we encounter problems, I choose one. There is a transition period planned and some services will only accept the account number for some time, although there is the translation service why not to keep those numbers in our database since it will come for free in requests anyway? Dropping a column is literally a DDL one-liner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not against keeping the account_number, I want to allow a blank value for it. There are already some CUs that will not have account_number
and such CUs would not be able to use our service :)
Squashed into a single commit. |
Great work, really helped. |
Yeah I still believe we should allow blank accounts 🤔 but we can talk about that later, but would be better not to change migrations ^_^ |
So I am assuming that NOT NULL will not work with UNIQUE, but let me try maybe NULLs are not taken into account. |
You were right, NULL values are allowed regardless of the unique constraint, therefore let's go with that. Also I removed the ssh key table from the seed script - that was a leftover. Finally, I added go documentation to the account model type. |
CREATE TABLE accounts | ||
( | ||
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | ||
account_number TEXT UNIQUE CHECK (NOT empty(account_number)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧡
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good, thanks @lzap and thanks @adiabramovitch for the review !
Also drop down-migrations, these do not appear to be very helpful in golang-migrate because when migration fails, it sets the "dirty" flag and database must be fixed manually anyway. We can add down migrations later if we need to.
The patch also adds seeds support, this will be helpful for setting up a working development setup. By deafult this is turned off, use DB_SEED_SCRIPT=dev_small to use it.