ihp
ihp copied to clipboard
Refactor Tests to have default values for `CreateTable { .. }` expressions
Right now our tests have a lot of expressions like this:
StatementCreateTable CreateTable {
name = "users"
, columns = [
Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
, constraints = []
, unlogged = False
}
In that expression constraints = []
and unlogged = False
are the default values, and are basically just overhead.
Now whenever we need to add a new field to the CreateTable
constructor, we have to add the new field across the full test code base. E.g. in https://github.com/digitallyinduced/ihp/commit/540106bb24a84294a3828dd4a574682b343806b5 there's a lot of boilerplate by adding unlogged = False
everywhere.
As a solution we could introduce a helper function emptyCreateTable
, and then use it like this:
-- Definition:
emptyCreateTable = CreateTable { name = "", columns = [], primaryKeyConstraint = [], constraints = [], unlogged = False }
-- Usage:
StatementCreateTable emptyCreateTable {
name = "users"
, columns = [
Column
{ name = "id"
, columnType = PUUID
, defaultValue = Just (CallExpression "uuid_generate_v4" [])
, notNull = True
, isUnique = False
, generator = Nothing
}
]
, primaryKeyConstraint = PrimaryKeyConstraint ["id"]
}
This way we can remove lots of boilerplate in the tests.
I'm doing this one but I'm a bit rusty in working out how to make the pull request. I'll try and figure before I sleep.
Is this issue still open ? @tobz619 do you want a helping hand in it ?
Hi,
Sure go for it! I'm quite bogged down with work right now so if you want to help complete it then go ahead!
Thanks,
Tobi
On Fri, 30 Jun 2023, 13:44 Shobhit Singh, @.***> wrote:
Is this issue still open ? @tobz619 https://github.com/tobz619 do you want a helping hand in it ?
— Reply to this email directly, view it on GitHub https://github.com/digitallyinduced/ihp/issues/1601#issuecomment-1614600143, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWH5OJOUIRWUDW7YHM63O5TXN3C3NANCNFSM6AAAAAAURZHCIY . You are receiving this because you were mentioned.Message ID: @.***>
Please look into it, I have made the pull request
is this one still open? The pull request was Closed.
This is still open 👍