-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat: postgres setup #508
feat: postgres setup #508
Conversation
d5a6cf7
to
3a253d4
Compare
@@ -7,8 +7,6 @@ on: | |||
- 'packages/api/**' | |||
- '.github/workflows/api.yml' | |||
pull_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.
We should be able to run CI tests for other branch targets, like here where we target the DB migration branch
d92e7d5
to
fe538cd
Compare
6198ff9
to
23b008c
Compare
e.g
|
I'm ok with the "dbClient" being a wrapper wround both fauna and postgres currently. I agree that fauna queries should live in their own file. Ideally the postgres implmentation would also live in it's own file and then the wrapper pulls in both implementations for now, so we could more easily compare the two implementations side by side. |
I avoided that to make it easier when we remove Fauna. But if you prefer for readability, I can make it its own file too. Probably better in #524 though? which is where I move fauna code around. |
yep, sounds good. |
Co-authored-by: Oli Evans <oli@tableflip.io>
Co-authored-by: Oli Evans <oli@tableflip.io>
packages/api/README.md
Outdated
@@ -50,6 +50,7 @@ One time set up of your cloudflare worker subdomain for dev: | |||
wrangler secret put S3_ACCESS_KEY_ID --env $(whoami) # Get from Amazon S3 (not required for dev) | |||
wrangler secret put S3_SECRET_ACCESS_KEY_ID --env $(whoami) # Get from Amazon S3 (not required for dev) | |||
wrangler secret put S3_BUCKET_NAME --env $(whoami) # e.g web3.storage-staging-us-east-2 (not required for dev) | |||
wrangler secret put DATABASE_TOKEN --env USER # Get from database postgrest |
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.
Change docs?
DROP FUNCTION IF EXISTS json_arr_to_upload__pin_type_arr; | ||
DROP FUNCTION IF EXISTS create_upload; | ||
DROP FUNCTION IF EXISTS find_deals_by_content_cids; | ||
|
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.
please to add a comment of what the input and output of these fns looks like!
packages/db/postgres/functions.sql
Outdated
RETURNS text[] LANGUAGE sql IMMUTABLE PARALLEL SAFE AS | ||
'SELECT ARRAY(SELECT json_array_elements_text(_json))'; | ||
|
||
CREATE OR REPLACE FUNCTION json_arr_to_upload__pin_type_arr(_json json) |
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.
can we rename to be clearer about what it does rather than where it is called from
foreach backup_url in array json_arr_to_text_arr(data -> 'backup_urls') | ||
loop | ||
-- insert into backup with update | ||
insert into backup (upload_id, |
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.
Needs an on conflict here... if the same user uploads the same car, the insert should fail... we dont want multiple backup records with the same s3 url
packages/db/postgres/functions.sql
Outdated
return query select * | ||
from upload u | ||
where u.user_id = (data ->> 'user_id')::BIGINT | ||
AND u.content_cid = data ->> 'content_cid'; |
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.
Use the inserted_upload_id
!
select * from upload u where u.id = inserted_upload_id
also AND
is shouty case
cargoSql = cargoSql.replace( | ||
` | ||
-- Create materialized view from cargo "aggregate_entries" table | ||
CREATE MATERIALIZED VIEW public.aggregate_entry | ||
AS | ||
SELECT * | ||
FROM cargo.aggregate_entries;`, | ||
` | ||
CREATE MATERIALIZED VIEW public.aggregate_entry | ||
AS | ||
SELECT * | ||
FROM cargo.aggregate_entries | ||
WHERE cid_v1 in ('bafybeiaj5yqocsg5cxsuhtvclnh4ulmrgsmnfbhbrfxrc3u2kkh35mts4e'); | ||
` |
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.
@hugomrdias can you say why we need this?
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.
merging this now! We can revisit in followup PR according to hugo's thoughts
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.
Huge lift! thanks!
* @param {import('./db-client-types').ContentItem} content | ||
* @return {import('./db-client-types').ContentItemOutput} | ||
*/ | ||
export function normalizeContent (content) { |
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.
Let's do as much of the normalising as we can in the queries, and only do the steps we can't do via postgrest here
* local setup for postgres database using docker compose * DB Client revamped to be used for the API * DB tests Co-authored-by: Oli Evans <oli@tableflip.io>
* local setup for postgres database using docker compose * DB Client revamped to be used for the API * DB tests Co-authored-by: Oli Evans <oli@tableflip.io>
This PR adds:
packages/db/postgres/*
and/packages/db/scripts/*
is heavily inspired from nft.storagetables.sql
,functions.sql
packages/db/postgres/db-types.d.ts
is auto generated by openapi-typescriptpackages/db/index.js
andpackages/db/db-client-types.ts