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

self-host init database failed #26

Closed
ninehills opened this issue Sep 26, 2023 · 12 comments
Closed

self-host init database failed #26

ninehills opened this issue Sep 26, 2023 · 12 comments

Comments

@ninehills
Copy link

Use Supabase SQL Editor to run setup-dump.sql, then failed with follow message:

Error running SQL: Invalid SQL query

file: https://raw.githubusercontent.com/llmonitor/llmonitor/main/selfhosting/setup-dump.sql

image
@pAkalpa
Copy link
Contributor

pAkalpa commented Sep 26, 2023

@ninehills The commit e36e498 solved the issue. Please Update Repo and try again.

@ninehills
Copy link
Author

@ninehills The commit e36e498 solved the issue. Please Update Repo and try again.

I have already used the latest version, but it still gives that error.

@pAkalpa
Copy link
Contributor

pAkalpa commented Sep 26, 2023

@ninehills I apologize for suggesting that it was fixed in the first place. My mistake!. The error appears to be occurring at line number 144 in the setup-dump.sql file. This might be because the public.app_user table hasn't been created yet. You can check the specific code snippet here
@vincelwt @hughcrt any comments
Screenshot 2023-09-26 111641

@Igosuki
Copy link

Igosuki commented Sep 27, 2023

This worked for me :


CREATE TABLE "public"."app_user" (
    "created_at" timestamptz DEFAULT now(),
    "app" uuid,
    "id" bigserial PRIMARY KEY,
    "external_id" text,
    "last_seen" timestamptz,
    "props" jsonb
);

CREATE POLICY app_user_owner_policy ON public.app_user USING ((( SELECT app.owner
   FROM public.app
  WHERE (app.id = app_user.app)) = auth.uid()));

ALTER TABLE public.run ADD COLUMN user bigint;

@andrey59412678
Copy link

@Igosuki that works for me, just had to add quotes around user

however, there is still something missing: column "profile.team_owner". I had to remove from the query in the code to make it work

@prazevj
Copy link

prazevj commented Sep 28, 2023

@Igosuki Thanks for suggesting "public"."app_user" table which is missing in setup_dump.sql table.
@andrey59412678 am also getting the same error in the web page (network tab) however I just created a column in profile table as team_owner as uuid() type and the error got fixed. But, am not sure about the data type and relation for this column.

Can anyone suggest a fix for this @vincelwt @pAkalpa ?

@hughcrt
Copy link
Member

hughcrt commented Sep 28, 2023

Hi @prazevj,

The correct table definition for profile is the following:

create table "public"."profile" (
	"id" uuid not null,
	"updated_at" timestamptz,
	"email" text,
	"name" text,
	"plan" text not null default 'free' ::text,
	"team_owner" uuid,
	constraint "profile_id_fkey1" foreign key ("id") references "auth"."users" ("id") on delete cascade,
	constraint "profile_id_fkey" foreign key ("id") references "auth"."users" ("id") on delete cascade,
	constraint "profile_team_owner_fkey" foreign key ("team_owner") references "public"."profile" ("id"),
	primary key ("id")
);

We'll make a cleaner database schema next week. We'll make sure to always keep setup-dump.sql after this. Sorry for the inconvenience!

@prazevj
Copy link

prazevj commented Oct 4, 2023

@hughcrt Thank you. It would be great if we can have a clear and cleaner self-host steps.

While using the self-hosted version in the callback handler code
res = requests.get(f"{self.__api_url}/api/app/{self.__app_id}")

this URL is giving me Internal Server Error. I tried changing the DEFAULT_API_URL and also have tried setting the LLMONITOR_API_URL, LLMONITOR_APP_ID. Unable to connect to the api endpoint. Any workaround or troubleshooting steps could you recommend ?

Note: Hosted on Supabase (Self-Host)

@nkuehn
Copy link

nkuehn commented Oct 5, 2023

I can confirm the above issues (initial SQL not working, requires fixes discussed above) plus the following

  • email verification has localhost:3000 as redirect URL (vs. the vercel project URL - no documentation on where / how to tell the system its deployment URL). After manually changing the URL in the email, the redirect from there with ?code=.... has localhost:3000 in it again. -> needs to be set at https://supabase.com/dashboard/project/{your-project-id}/auth/url-configuration
  • 406 authentication failures from the frontend when calling supabase REST APIs. (even after deleting the user and all data in supabase and re-trying) - "JSON object requested, multiple (or no) rows returned"
  • frontend making various calls to llmonitor.featurebase.app which is does not really look like a self-deployed setup

I can help testing a new version but can't really help with development

@vincelwt
Copy link
Member

vincelwt commented Oct 5, 2023

Hi guys! Apologies about those issues, we're currently fully focused on fixing some core issues with the python module and feedback tracking and will work on improving self hosting as soon as we have a bit more time on our hand.

@nkuehn

  • Email verification endpoint is configured in Supabase I think? If you're self hosting supabase that would be in the Supaabse env variables
  • Not sure about the 406 errors, could you share screenshot of the console logs so we can try to pinpoint where they are?
  • Good call about llmonitor.featurebase.app, I'll disable those in the self hosted version

@nkuehn
Copy link

nkuehn commented Oct 9, 2023

If you're self hosting supabase that would be in the Supaabse env variables

I can't see a related env var in the template - there's only the ones for resend.com

Not sure about the 406 errors, could you share screenshot of the console logs so we can try to pinpoint where they are?

This is the first one, all following fail the same way:

https://{my-tenant}.supabase.co/rest/v1/profile?select=id%2Cemail%2Cname%2Cupdated_at%2Cplan%2Cteam_owner&id=eq.6cfa5cd5-1413-4293-a1f5-1163e0423e26

Result is a 406, the body contains:

{
    "code": "PGRST116",
    "details": "The result contains 0 rows",
    "hint": null,
    "message": "JSON object requested, multiple (or no) rows returned"
}

My best guess is that the initialization with the first user is not working as intended. After resetting everything and retrying, in supabase there is an account under "authentication" but all the tables are still empty. So the initial setup click flow is not actually creating a user in llmonitor, just the supabase auth entry. My first guess is that is silently fails somewhere e.g. because the DB schema is not correct. my vercel logs are empty. For me: pausing this until there is a reliable DB schema setup script that does not make the app fail.

@hughcrt
Copy link
Member

hughcrt commented Oct 28, 2023

Hi,
We've fixed self hosting. It's been tested internally and by one of our users and it seems to work fine. Here are the instructions:

  1. Setup a new Supabase project (don't reuse the previous one, as the setup script will fail if the tables already exist).
  2. Clone the repo and deploy it to Vercel
  3. Look at .env.example to see what environment variables you need to set on Vercel
  4. Open the Supabase Admin dashboard
    4.1. Go to Database > Webhooks and click on "Enable webhooks"
    4.2. Copy the content of setup-dump.sql in the SQL editor. Replace <your_vercel_project_url> by the actual URL at the end of the script and run it.
    4.3. Go to Authentication > Url Configuration and replace http://localhost:3000 by your Vercel project url.

Please let me know if it works for you!
@ninehills @Igosuki @nkuehn @prazevj

@hughcrt hughcrt closed this as completed Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants