Public schema table embedding (#803)
* Alter fixture to test objects in public schema Properly erase and restore the public schema -- requires permissions to install pgcrypto each time. * Test for fks through public schema tables * Thanks @fab1an
This commit is contained in:
@@ -9,6 +9,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
### Fixed
|
||||
|
||||
- Resource embedding in views referencing tables in public schema - @fab1an
|
||||
|
||||
## [0.4.0.0] - 2017-01-19
|
||||
|
||||
### Added
|
||||
|
||||
@@ -606,7 +606,7 @@ allSynonyms cols =
|
||||
select case when match is not null then coalesce(match[8], match[7], match[4]) end
|
||||
from regexp_matches(
|
||||
CONCAT('SELECT ', SPLIT_PART(vcu.view_definition, 'SELECT', 2)),
|
||||
CONCAT('SELECT.*?((',vcu.table_name,')|(\w+))\.(', vcu.column_name, ')(\s+AS\s+("([^"]+)"|([^, \n\t]+)))?.*?FROM.*?',vcu.table_schema,'\.(\2|',vcu.table_name,'\s+(as\s)?\3)'),
|
||||
CONCAT('SELECT.*?((',vcu.table_name,')|(\w+))\.(', vcu.column_name, ')(\s+AS\s+("([^"]+)"|([^, \n\t]+)))?.*?FROM.*?(',vcu.table_schema,'\.|)(\2|',vcu.table_name,'\s+(as\s)?\3)'),
|
||||
'nsi'
|
||||
) match
|
||||
) as view_column_name
|
||||
|
||||
@@ -302,6 +302,10 @@ spec = do
|
||||
get "/projects?id=in.1,3&select=id,name,client_id,client{id,name}" `shouldRespondWith`
|
||||
[str|[{"id":1,"name":"Windows 7","client_id":1,"client":{"id":1,"name":"Microsoft"}},{"id":3,"name":"IOS","client_id":2,"client":{"id":2,"name":"Apple"}}]|]
|
||||
|
||||
it "can detect fk relations through views to tables in the public schema" $
|
||||
get "/consumers_view?select=*,orders_view{*}" `shouldRespondWith` 200
|
||||
|
||||
|
||||
describe "ordering response" $ do
|
||||
it "by a column asc" $
|
||||
get "/items?id=lte.2&order=id.asc"
|
||||
|
||||
+3
-1
@@ -43,8 +43,10 @@ WHERE pg_stat_activity.datname = '$DB'
|
||||
|
||||
DROP DATABASE IF EXISTS $DB;
|
||||
DROP ROLE IF EXISTS $TEST_USER_NAME;
|
||||
CREATE USER $TEST_USER_NAME WITH LOGIN NOINHERIT PASSWORD '$TEST_USER_PASS' CREATEROLE;
|
||||
CREATE USER $TEST_USER_NAME WITH SUPERUSER LOGIN NOINHERIT PASSWORD '$TEST_USER_PASS' CREATEROLE;
|
||||
CREATE DATABASE $DB OWNER $TEST_USER_NAME;
|
||||
\\connect $DB
|
||||
ALTER SCHEMA public OWNER TO $TEST_USER_NAME;
|
||||
EOF
|
||||
|
||||
PGDATABASE=$DB PGOPTIONS='-c client_min_messages=WARNING' psql "$URI" --set=db=$DB -Xq <<EOF
|
||||
|
||||
Vendored
+2
-2
@@ -1,3 +1,3 @@
|
||||
set client_min_messages to warning;
|
||||
DROP SCHEMA IF EXISTS test, private, postgrest, jwt, تست CASCADE;
|
||||
DROP TYPE IF EXISTS jwt_token CASCADE;
|
||||
DROP SCHEMA IF EXISTS test, private, postgrest, jwt, public, تست CASCADE;
|
||||
DROP TYPE IF EXISTS jwt_token CASCADE;
|
||||
|
||||
Vendored
+5
@@ -3,6 +3,7 @@ GRANT USAGE ON SCHEMA
|
||||
postgrest
|
||||
, test
|
||||
, jwt
|
||||
, public
|
||||
, "تست"
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
@@ -44,6 +45,10 @@ GRANT ALL ON TABLE
|
||||
, "موارد"
|
||||
, addresses
|
||||
, orders
|
||||
, public.public_consumers
|
||||
, public.public_orders
|
||||
, consumers_view
|
||||
, orders_view
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
Vendored
+1
-1
@@ -4,4 +4,4 @@ CREATE ROLE postgrest_test_anonymous;
|
||||
CREATE ROLE postgrest_test_default_role;
|
||||
CREATE ROLE postgrest_test_author;
|
||||
|
||||
GRANT postgrest_test_anonymous, postgrest_test_default_role, postgrest_test_author TO :USER;
|
||||
GRANT postgrest_test_anonymous, postgrest_test_default_role, postgrest_test_author TO :USER;
|
||||
|
||||
Vendored
+25
-23
@@ -12,31 +12,10 @@ SET standard_conforming_strings = on;
|
||||
SET check_function_bodies = false;
|
||||
SET client_min_messages = warning;
|
||||
|
||||
--
|
||||
-- Name: postgrest; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA public;
|
||||
CREATE SCHEMA postgrest;
|
||||
|
||||
|
||||
--
|
||||
-- Name: private; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA private;
|
||||
|
||||
|
||||
--
|
||||
-- Name: test; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA test;
|
||||
|
||||
|
||||
--
|
||||
-- Name: تست; Type: SCHEMA; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE SCHEMA تست;
|
||||
|
||||
|
||||
@@ -48,11 +27,13 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
|
||||
|
||||
SET search_path = public, pg_catalog;
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
|
||||
--
|
||||
-- Name: jwt_token; Type: TYPE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TYPE jwt_token AS (
|
||||
CREATE TYPE public.jwt_token AS (
|
||||
token text
|
||||
);
|
||||
|
||||
@@ -142,6 +123,19 @@ CREATE FUNCTION always_true(test.items) RETURNS boolean
|
||||
AS $$ SELECT true $$;
|
||||
|
||||
|
||||
create table public_consumers (
|
||||
id serial not null unique,
|
||||
name text not null check (name <> ''),
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table public_orders (
|
||||
id serial not null unique,
|
||||
consumer integer not null references public_consumers(id),
|
||||
number integer not null,
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
--
|
||||
-- Name: anti_id(test.items); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
@@ -161,6 +155,14 @@ CREATE TABLE موارد (
|
||||
|
||||
SET search_path = test, pg_catalog;
|
||||
|
||||
|
||||
create view orders_view as
|
||||
select * from public.public_orders;
|
||||
|
||||
create view consumers_view as
|
||||
select * from public.public_consumers;
|
||||
|
||||
|
||||
--
|
||||
-- Name: getitemrange(bigint, bigint); Type: FUNCTION; Schema: test; Owner: -
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user