Changes the insertable to true in views that are insertable through triggers [fixes #206]
This commit is contained in:
@@ -44,8 +44,9 @@ tables schema = do
|
||||
rows <- H.listEx $
|
||||
[H.stmt|
|
||||
select table_schema, table_name,
|
||||
is_insertable_into
|
||||
from information_schema.tables
|
||||
t.is_insertable_into::boolean OR coalesce(is_trigger_insertable_into::boolean, false)
|
||||
from information_schema.tables t
|
||||
left join information_schema.views using(table_catalog, table_schema, table_name)
|
||||
where table_schema = ?
|
||||
order by table_name
|
||||
|] schema
|
||||
@@ -135,8 +136,8 @@ data Column = Column {
|
||||
, colFK :: Maybe ForeignKey
|
||||
} deriving (Show)
|
||||
|
||||
tableFromRow :: (Text, Text, Text) -> Table
|
||||
tableFromRow (s, n, i) = Table s n (toBool i)
|
||||
tableFromRow :: (Text, Text, Bool) -> Table
|
||||
tableFromRow (s, n, i) = Table s n i
|
||||
|
||||
columnFromRow :: (Text, Text, Text,
|
||||
Int, Text, Text,
|
||||
|
||||
@@ -17,6 +17,7 @@ spec = around withApp $ do
|
||||
{"schema":"1","name":"auto_incrementing_pk","insertable":true}
|
||||
, {"schema":"1","name":"compound_pk","insertable":true}
|
||||
, {"schema":"1","name":"has_fk","insertable":true}
|
||||
, {"schema":"1","name":"insertable_view_with_join","insertable":true}
|
||||
, {"schema":"1","name":"items","insertable":true}
|
||||
, {"schema":"1","name":"json","insertable":true}
|
||||
, {"schema":"1","name":"menagerie","insertable":true}
|
||||
|
||||
@@ -14,7 +14,7 @@ spec = around dbWithSchema $ beforeWith setRole $ do
|
||||
it "shows all the tables" $ \conn -> do
|
||||
ts <- tables "1" conn
|
||||
map tableName ts `shouldBe` ["authors_only","auto_incrementing_pk",
|
||||
"compound_pk","has_fk","items","menagerie","no_pk", "simple_pk"]
|
||||
"compound_pk","has_fk","insertable_view_with_join","items","menagerie","no_pk", "simple_pk"]
|
||||
|
||||
describe "columns" $ do
|
||||
it "responds with each column for the table" $ \conn -> do
|
||||
|
||||
Vendored
+31
@@ -84,6 +84,17 @@ $$;
|
||||
|
||||
ALTER FUNCTION postgrest.set_authors_only_owner() OWNER TO postgrest_test;
|
||||
|
||||
CREATE FUNCTION "1".insert_insertable_view_with_join() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
begin
|
||||
INSERT INTO "1".auto_incrementing_pk (nullable_string, non_nullable_string) VALUES (NEW.nullable_string, NEW.non_nullable_string);
|
||||
RETURN NEW;
|
||||
end;
|
||||
$$;
|
||||
|
||||
ALTER FUNCTION "1".insert_insertable_view_with_join() OWNER TO postgrest_test;
|
||||
|
||||
SET search_path = "1", pg_catalog;
|
||||
|
||||
SET default_tablespace = '';
|
||||
@@ -159,6 +170,18 @@ ALTER TABLE "1".has_fk_id_seq OWNER TO postgrest_test;
|
||||
|
||||
ALTER SEQUENCE has_fk_id_seq OWNED BY has_fk.id;
|
||||
|
||||
CREATE VIEW "1".insertable_view_with_join AS
|
||||
SELECT has_fk.id,
|
||||
has_fk.auto_inc_fk,
|
||||
has_fk.simple_fk,
|
||||
auto_incrementing_pk.nullable_string,
|
||||
auto_incrementing_pk.non_nullable_string,
|
||||
auto_incrementing_pk.inserted_at
|
||||
FROM (has_fk
|
||||
JOIN auto_incrementing_pk USING (id));
|
||||
|
||||
|
||||
ALTER TABLE "1".insertable_view_with_join OWNER TO postgrest_test;
|
||||
|
||||
|
||||
CREATE TABLE items (
|
||||
@@ -341,6 +364,9 @@ SET search_path = "1", pg_catalog;
|
||||
ALTER TABLE ONLY authors_only
|
||||
ADD CONSTRAINT authors_only_pkey PRIMARY KEY (secret);
|
||||
|
||||
CREATE TRIGGER insert_insertable_view_with_join INSTEAD OF INSERT ON "1".insertable_view_with_join FOR EACH ROW EXECUTE PROCEDURE "1".insert_insertable_view_with_join();
|
||||
|
||||
|
||||
CREATE TRIGGER secrets_owner_track BEFORE INSERT OR UPDATE ON authors_only FOR EACH ROW EXECUTE PROCEDURE postgrest.set_authors_only_owner();
|
||||
|
||||
|
||||
@@ -511,6 +537,11 @@ REVOKE ALL ON TABLE tsearch FROM postgrest_test;
|
||||
GRANT ALL ON TABLE tsearch TO postgrest_test;
|
||||
GRANT ALL ON TABLE tsearch TO postgrest_anonymous;
|
||||
|
||||
REVOKE ALL ON TABLE insertable_view_with_join FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE insertable_view_with_join FROM postgrest_test;
|
||||
GRANT ALL ON TABLE insertable_view_with_join TO postgrest_test;
|
||||
GRANT ALL ON TABLE insertable_view_with_join TO postgrest_anonymous;
|
||||
|
||||
|
||||
SET search_path = postgrest, pg_catalog;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user