Micky
04/21/2023, 12:26 PMJohnyMcB
04/21/2023, 12:38 PMGregorDoltar
04/21/2023, 1:44 PMrbl
04/21/2023, 2:59 PMRosibert
04/21/2023, 4:45 PMjs
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.21.0"
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"
const supabaseClient = createClient(
// Supabase API URL - env var exported by default.
Deno.env.get('SUPABASE_URL') ?? '',
// Supabase API ANON KEY - env var exported by default.
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
)
serve(async (req) => {
const { userId } = await req.json()
console.log(userId)
supabaseClient.from('public.user_roles').insert({user: userId, role: 'customer'})
return new Response(
JSON.stringify(userId),
{ headers: { "Content-Type": "application/json" } },
)
})
my schema looks like this:
https://cdn.discordapp.com/attachments/1099013143746846840/1099013143985914006/image.png▾
ven
04/21/2023, 5:51 PM-- inserts a row into public.profile when a new user is created
create or replace function public.handle_new_user() returns trigger as $$ begin
-- insert a row into public.profile with the user_uid and email
insert into public."profile" (user_uid, email)
values (new.id::text, new.email);
-- insert a row into public.account with the profile_id
insert into public."account" (profileId)
values (new.id::number);
return new;
end;
$$ language plpgsql security definer;
MATTI
04/21/2023, 6:01 PMhttps://cdn.discordapp.com/attachments/1099032207902912512/1099032208326533230/image.png▾
https://cdn.discordapp.com/attachments/1099032207902912512/1099032208628531292/image.png▾
mantism
04/21/2023, 6:24 PMJulian IncrEdelman
04/21/2023, 7:33 PMThe server does not guarantee that every message will be delivered to your clients so keep that in mind as you're using Realtime.
https://github.com/supabase/realtime
I'm curious - are there any sort of guarantees? Is it at-most-once?
Are there any guidelines or best practices on what sort of fail-safes to have? I understand it will be application-specific, but I can imagine a few options (a refresh button, a system to poll with a lower frequency as a failsafe). I was wondering if perhaps there was any recommended libraries for these failsafes so I could avoid rolling my own.
Thanks and love Supabase!tristansinclair
04/21/2023, 8:15 PMhttps://cdn.discordapp.com/attachments/1099065832463675542/1099075845945041061/Screenshot_2023-04-21_at_1.54.39_PM.png▾
MusashiGarami
04/21/2023, 8:23 PMven
04/21/2023, 9:51 PMcptCrunch
04/21/2023, 10:20 PMsql
create table
public.myTable(
id bigint generated by default as identity not null,
created_at timestamp with time zone null default now()
) tablespace pg_default;
duhherro
04/21/2023, 10:34 PMcptCrunch
04/21/2023, 11:12 PMselect()
statement.
Users Table
-----------
id
first_name
last_name
Clients Table
-------------
id
first_name
last_name
Agents Table
------------
id
first_name
last_name
Inspections Table
-----------------
id
user_id_fkey
client_id_fkey
agent_id_fkey
Rather than returning the id's I would like to return the First and Last Names of each table respectively when I query the Inspections table.InASunshineState
04/22/2023, 12:25 AMjon.m
04/22/2023, 3:40 AMPSully
04/22/2023, 3:47 AMconst subEvent = (event, table) => ({
event: event,
schema: 'public',
table: table,
filter: `user_id=eq.${user.id}`,
});
const on = 'postgres_changes';
supabase
.channel('any')
.on(on, subEvent('INSERT', 'daily_foods'), insertDailyFoods)
.on(on, subEvent('DELETE', 'daily_foods'), deleteDailyFoods)
.on(on, subEvent('UPDATE', 'foods'), updateFoods)
.on(on, subEvent('UPDATE', 'user_profile'), updateUserProfile)
.subscribe();
I have them being filtered by user.id so the events aren't sent to every single connected
client. This seems to be working for all but the DELETE
into daily_foods
. I am still
receiving this event on every single connected client. I've tried toggling RSL on or off,
but this doesn't seem to change anything at all. (Other than only returning the ID in the
payload.old
). I have also ensured that user.id
is 100% populated.
Am I totally missing something here? Can't seem to find anything in the docs that would shed any light on what is going on here for me.richardoreo
04/22/2023, 3:59 AM{
"data": null,
"errors": [
{
"message": "Input for type StringFilter contains extra keys [\"startsWith\"]"
}
]
}
here is my query:
query Test {
profilesCollection(filter: {username: {startsWith: "Richard"}}) {
edges {
node {
name
}
}
}
}
Apollo
04/22/2023, 4:11 AMRender.com
managed Postgres databased with a self-hosted postgres database on fly.io. After learning about supavisor, I want to host this + our db on fly.io.
I see in the installation docs (https://github.com/supabase/supavisor/wiki/Installation-and-Usage) a section about deploying fly.io, but it doesn't make sense to me. I have a few questions.
1) I can attach any normal postgres database as a tenant, correct? So I could deploy a normal postgres-ha from fly.io, and connect them to supavisor. Or do I need to do something special?
2) It seems supavisor also needs a postgres database to keep track of tenants, do I attach a db when deploying to fly io, or is it bring your own database?
3) If I deploy supabase via self-hosting (https://supabase.com/docs/guides/self-hosting), how does supavisor integrate?
4) Would it be better to deploy the supabase image of postgres on fly, as shown by @copple here: https://github.com/kiwicopple/postgres-ha/pull/1/files ? I want to deploy most of the supabase stack on flyFranck
04/22/2023, 4:40 AMven
04/22/2023, 5:29 AMHermanus147
04/22/2023, 5:55 AMLimuz
04/22/2023, 6:55 AMjs
async getPaginatedCustomersRest() {
try {
console.log(this.taskCount, this.taskPaginationSize, this.taskPagination);
const runs = Math.floor(this.taskCount / this.taskPaginationSize / 10);
const concurrency = 5;
let tasks = [];
for (let i = 0; i <= runs; i++) {
let limit = this.taskPaginationSize * i * 10;
let offset = limit + (this.taskPaginationSize * 10);
if (runs === i) {
offset = this.taskCount;
}
tasks.push(this.fillCustomers(limit, offset));
if (tasks.length >= concurrency) {
await Promise.all(tasks);
tasks = [];
}
}
await Promise.all(tasks);
await new Promise(resolve => setTimeout(resolve, 1000))
} catch (error) {
console.error(error);
}
},
with this function
js
async fillCustomers(limit, offset) {
if (limit === 0){
limit = this.taskPaginationSize
}
console.log('fillCustomers', limit, offset);
const { data, error } = await supabase
.from('customer')
.select('*,customer_address(*),customer_contactperson(*)')
.range(Number(limit), Number(offset))
.order('id', { ascending: false })
console.log('fillCustomers', limit, offset);
if (data?.length) {
this.allCustomers = this.allCustomers.concat(data as Company[])
}
},
And after some runs,
see screenshot but log says limit and offset is alright
js
fillCustomers 1250 1500
customer.ts:98 fillCustomers 1500 1750
customer.ts:98 fillCustomers 1750 2000
customer.ts:98 fillCustomers 2000 2250
customer.ts:98 fillCustomers 2250 2500
customer.ts:98 fillCustomers 2500 2750
customer.ts:98 fillCustomers 2750 3000
customer.ts:98 fillCustomers 3000 3250
customer.ts:98 fillCustomers 3250 3500
customer.ts:98 fillCustomers 3500 3750
customer.ts:98 fillCustomers 3750 4000
customer.ts:98 fillCustomers 4000 4153
https://cdn.discordapp.com/attachments/1099227043591364708/1099227043725574144/image.png▾
EKI
04/22/2023, 7:40 AMtreepumpkin
04/22/2023, 8:31 AMeagerashwani
04/22/2023, 10:25 AMhttps://cdn.discordapp.com/attachments/1099279860620349601/1099279860792303626/A7826EC4-FB64-4602-9820-FB18FB281A99.png▾
jarnold
04/22/2023, 1:30 PMFyl
04/22/2023, 1:45 PMexchange_id
column must be unique for each user.
If the user inserts new data and exchange_id
already exists for this user, the row should simply be updated but never created again.
Here is my table definition:
create table
public.exchanges(
id integer not null default nextval('exchanges_id_seq'::regclass),
user_id uuid not null,
exchange_id text null,
api_key text null,
secret_key text null,
constraint exchanges_pkey primary key (id),
constraint unique_exchange_id unique (exchange_id),
constraint exchanges_user_id_fkey foreign key (user_id) references auth.users (id) on delete cascade
) tablespace pg_default;
and my query:
js
const { error } = await supabase
.from("exchanges")
.upsert(
{ exchange_id: exchangeId, api_key: api, secret_key: secret, user_id: uid },
{ onConflict: 'exchange_id' }
)
.select()
This works almost fine except it is bound to all users. This makes user Y unable to create an entry if user X already has a row with user Y's exchange_id.
Any help is welcome, thanks.Fyl
04/22/2023, 3:29 PM/add-exchange/
API route works and correctly adds the data to my database.
Is this a known issue?
EDIT: another recent post describe this problem : https://discord.com/channels/839993398554656828/1096835059660636260