-
Notifications
You must be signed in to change notification settings - Fork 195
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
Implement inherits
for Schema.sql
#1998
base: master
Are you sure you want to change the base?
Conversation
CONTRIBUTING.md
Outdated
@@ -82,7 +82,7 @@ use `make console` to load your application together with the framework located | |||
|
|||
``` | |||
ghci | |||
:l IHP/exe/IHP/IDE/DevServer.hs | |||
:l IHP/ihp-ide/exe/IHP/IDE/DevServer.hs |
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.
@mpscholten I think the doc is outdated.
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.
It could just be ghci
. make console
is just an alias for ghci
.
Can you try :set -iIHP/ihp-ide
in the ghci? This will add the IHP/ihp-ide
directory to the load path. After that it should load without the error.
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 can reproduce that. Just tried it locally and here's an approach how I got it working with latest IHP:
# Assuming workingDirectory is the project
cd IHP # switch to IHP
direnv allow # load direnv things if this is freshly cloned
ghci # Load ghci will all IHP dependencies
:cd .. # switch back to project directory
:set -iIHP
:set -iIHP/ihp-ide
:l IHP/ihp-ide/exe/IHP/IDE/DevServer.hs
That should work now
locally i run into a ghc bug while doing that, I hope it works for you:
ghci> :l IHP/ihp-ide/exe/IHP/IDE/DevServer.hs
Ok, 164 modules loaded.
ghci> main
panic! (the 'impossible' happened)
GHC version 9.8.2:
nameModule
internal $fHasQueryBuilderkJoinQueryBuilderWrapperjoinRegister1_iefl
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:191:37 in ghc-9.8.2-inplace:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Types/Name.hs:341:3 in ghc-9.8.2-inplace:GHC.Types.Name
CallStack (from HasCallStack):
panic, called at compiler/GHC/Utils/Error.hs:503:29 in ghc-9.8.2-inplace:GHC.Utils.Error
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
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.
As a workaround for the GHC bug I reverted the commit that introduced the bug by running git revert 4fe8b56e5a8c5dcb394a16b0dfb5eb2d6f77b18f
from within the IHP
directory
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've ran into more issues with the dev server right now and added a new helper called mainInParentDirectory
to fix that.
After you've synced this branch with latest master it should now work like this:
# Assuming workingDirectory is the project
cd IHP # switch to IHP
direnv allow # load direnv things if this is freshly cloned
ghci # Load ghci will all IHP dependencies
:l ihp-ide/exe/IHP/IDE/DevServer.hs
mainInParentDirectory # Will run the IHP project in the parent project directory
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.
Thank you for looking into it 🙏
I'm confused about which URL should be in my flake.nix
Lines 43 to 67 in 27a696a
### Nix Changes | |
If you're testing local nix changes, you need to change your `flake.nix` to point to the IHP project instead of pulling it from github: | |
```nix | |
{ | |
inputs = { | |
# The path needs to be absolute | |
ihp.url = "path:///Users/myuser/someproject/IHP"; | |
# ... | |
}; | |
``` | |
After that run `nix flake update`. | |
### Running the latest IHP `master` | |
When contributing to IHP core you will want to have your PRs synced with `master`. Your `flake.nix` should have this line: | |
```nix | |
{ | |
ihp.url = "github:digitallyinduced/ihp"; | |
} | |
``` | |
I'm guessing we should always tell folks to point to the local IHP, or is there a different use case?
Failing tests belong to https://github.com/digitallyinduced/ihp/blob/27a696af90efcd0f84260d84805dd2dc753e818c/Test/SchemaCompilerSpec.hs that require some trailing spaces. Let's see if we can remove those :) |
Next, I want to see if we can have revisions created either manually or by using Postgress triggers. Manual will be something like this: CREATE TABLE post_revisions (
revision_id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
post_id UUID NOT NULL
) INHERITS (posts); action CreatePostRevisionAction { .. } = do
post <- fetch postId
let revision = newRecord @PostRevision
|> set #postId post.id
|> set #title post.title
|> set #body post.body
createRecord revision
redirectTo ShowPostAction { .. } |
@mpscholten I've started working on the What are you doing in such cases? |
try |
This reverts commit 4fe8b56.
Thanks. How did you know it was that commit? So I'll know for next time 😄 |
When this specific bug happend the first time I was looking through the git history and just tried out various commits until I found the one that reproduced it. This was like a week or two weeks after that commit was created, so it was only a few commits I had to try out |
Got it to compile with this code! 🎈 |
Next is adapting |
I've updated the OP with a checklist. I'm not sure about some of the stuff, as I think it's not a small feature 😄 |
Happy to help if there's more questions :) |
Using triggersCREATE TABLE posts (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
title TEXT NOT NULL,
body TEXT NOT NULL,
user_id UUID NOT NULL
);
CREATE TABLE post_revisions (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
post_id UUID NOT NULL
) INHERITS (posts);
CREATE OR REPLACE FUNCTION create_post_revision() RETURNS TRIGGER AS $$
BEGIN
INSERT INTO post_revisions (id, post_id, title, body, user_id)
### Notice we use `ihp_user_id()` user here to capture the acting user.
VALUES (uuid_generate_v4(), NEW.id, NEW.title, NEW.body, ihp_user_id());
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER post_revision_trigger
AFTER UPDATE ON posts
FOR EACH ROW
EXECUTE FUNCTION create_post_revision(); I've logged in, and when I update a What should I do in order to get |
The In our case we can just use -- old
VALUES (uuid_generate_v4(), NEW.id, NEW.title, NEW.body, ihp_user_id());
-- new
VALUES (uuid_generate_v4(), NEW.id, NEW.title, NEW.body, NEW.user_id); |
Thanks.
Right. I guess I wanted to have another column called Is there a technical reason not to inject the user ID also if row level security isn't used? |
Yes, right now the Initially |
Could it be that the postgres server is not running? If that's the case, you could manually start one by running |
No, it's running. The app and ide run well. Just the migrate fails
…On Fri, Sep 13, 2024, 06:06 Marc Scholten ***@***.***> wrote:
Could it be that the postgres server is not running? If that's the case,
you could manually start one by running make postgres in a different tab
—
Reply to this email directly, view it on GitHub
<#1998 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA6WCY2TXICBIZQZI74SWLZWJJDJAVCNFSM6AAAAABMO2EGXOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBXHE2DQNZRGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
If you run the pg_dump command from the error message in a terminal yourself, does it output some SQL? |
To workaround the error, I'm checking it by running |
This reverts commit c957833.
inherits
triggers
inherit