-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for selecting a schema for postgrest. (#17)
- Loading branch information
Showing
6 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
sdk: ^2.0.0-alpha.124 | ||
sdk: ^2.0.0-alpha.128 | ||
prefixes: | ||
host: pkg-host | ||
http: pkg-http | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Supabase tests | ||
|
||
The supabase tests are in a subdirectory of tests, so that we can | ||
include the package in the external tests of the Toit repository. | ||
|
||
This way the supabase tests are ignored by the Toit framework. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (C) 2023 Toitware ApS. | ||
// Use of this source code is governed by a Zero-Clause BSD license that can | ||
// be found in the TESTS_LICENSE file. | ||
import supabase | ||
import supabase.filter | ||
import .supabase_local_server | ||
|
||
import expect show * | ||
|
||
main: | ||
config := get_supabase_config --sub_directory="supabase/supabase_test" | ||
|
||
client = supabase.Client --server_config=config | ||
--certificate_provider=: unreachable | ||
|
||
try: | ||
test_schema | ||
finally: | ||
client.close | ||
|
||
TEST_SCHEMA ::= "other_schema" | ||
TEST_TABLE ::= "some_table" | ||
|
||
client/supabase.Client := ? | ||
|
||
test_schema: | ||
client.rest.delete TEST_TABLE | ||
--schema=TEST_SCHEMA | ||
--filters=[ | ||
// Delete requires a where clause. | ||
filter.greater-than-or-equal "id" 0, | ||
] | ||
|
||
inserted := client.rest.insert TEST_TABLE | ||
--schema=TEST_SCHEMA | ||
{ "value": 499 } | ||
|
||
expect-equals 499 inserted["value"] | ||
|
||
rows := client.rest.select TEST_TABLE --schema=TEST_SCHEMA | ||
expect-equals 1 rows.size | ||
expect-equals 499 rows[0]["value"] | ||
|
||
client.rest.update TEST_TABLE | ||
--schema=TEST_SCHEMA | ||
--filters=[ | ||
filter.equals "id" rows[0]["id"], | ||
] | ||
{ "value": 500 } | ||
rows = client.rest.select TEST_TABLE --schema=TEST_SCHEMA | ||
expect-equals 1 rows.size | ||
expect-equals 500 rows[0]["value"] | ||
|
||
client.rest.upsert TEST_TABLE | ||
--schema=TEST_SCHEMA | ||
{ | ||
"id": rows[0]["id"], | ||
"value": 501, | ||
} | ||
rows = client.rest.select TEST_TABLE --schema=TEST_SCHEMA | ||
expect-equals 1 rows.size | ||
expect-equals 501 rows[0]["value"] | ||
|
||
client.rest.upsert TEST_TABLE | ||
--schema=TEST_SCHEMA | ||
{ | ||
"id": rows[0]["id"] + 1, | ||
"value": 502, | ||
} | ||
rows = client.rest.select TEST_TABLE --schema=TEST_SCHEMA | ||
expect-equals 2 rows.size | ||
expect-equals 501 rows[0]["value"] | ||
expect-equals 502 rows[1]["value"] | ||
|
||
client.rest.delete TEST_TABLE | ||
--schema=TEST_SCHEMA | ||
--filters=[ | ||
filter.equals "id" rows[0]["id"], | ||
] | ||
rows = client.rest.select TEST_TABLE --schema=TEST_SCHEMA | ||
expect-equals 1 rows.size | ||
expect-equals 502 rows[0]["value"] | ||
|
||
rpc-value := client.rest.rpc "fun" --schema=TEST_SCHEMA {:} | ||
expect-equals 42 rpc-value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/supabase/supabase_test/supabase/migrations/20240325135511_other_schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Copyright (C) 2024 Toitware ApS. | ||
-- Use of this source code is governed by a Zero-Clause BSD license that can | ||
-- be found in the TESTS_LICENSE file. | ||
|
||
CREATE SCHEMA IF NOT EXISTS other_schema; | ||
|
||
GRANT USAGE ON SCHEMA other_schema TO anon, authenticated, service_role; | ||
GRANT ALL ON ALL TABLES IN SCHEMA other_schema TO anon, authenticated, service_role; | ||
GRANT ALL ON ALL ROUTINES IN SCHEMA other_schema TO anon, authenticated, service_role; | ||
GRANT ALL ON ALL SEQUENCES IN SCHEMA other_schema TO anon, authenticated, service_role; | ||
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA other_schema GRANT ALL ON TABLES TO anon, authenticated, service_role; | ||
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA other_schema GRANT ALL ON ROUTINES TO anon, authenticated, service_role; | ||
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA other_schema GRANT ALL ON SEQUENCES TO anon, authenticated, service_role; | ||
|
||
CREATE TABLE other_schema.some_table ( | ||
id SERIAL PRIMARY KEY, | ||
value INTEGER | ||
); | ||
|
||
CREATE FUNCTION other_schema.fun() | ||
RETURNS INTEGER | ||
LANGUAGE plpgsql | ||
SECURITY INVOKER | ||
AS $$ | ||
BEGIN | ||
RETURN 42; | ||
END; | ||
$$; |