Refactors tests to use new fixtures and remove some haskell functions that wont be necessary anymore

This commit is contained in:
Diogo Biazus
2015-12-08 00:44:49 -05:00
parent 027bbc6074
commit 0961524e70
12 changed files with 1010 additions and 595 deletions
+1 -3
View File
@@ -10,9 +10,7 @@ import SpecHelper
-- }}} -- }}}
spec :: Spec spec :: Spec
spec = beforeAll spec = around (withApp cfgDefault)
(clearTable "postgrest.auth") . afterAll_ (clearTable "postgrest.auth")
$ around (withApp cfgDefault)
$ describe "authorization" $ do $ describe "authorization" $ do
it "hides tables that anonymous does not own" $ it "hides tables that anonymous does not own" $
+1 -1
View File
@@ -7,7 +7,7 @@ import SpecHelper
import Network.HTTP.Types import Network.HTTP.Types
spec :: Spec spec :: Spec
spec = beforeAll (clearTable "items" >> createItems 15) . afterAll_ (clearTable "items") spec = beforeAll resetDb
. around (withApp cfgDefault) $ . around (withApp cfgDefault) $
describe "Deleting" $ do describe "Deleting" $ do
context "existing record" $ do context "existing record" $ do
+4 -5
View File
@@ -17,7 +17,7 @@ import Control.Monad (replicateM_)
import TestTypes(IncPK(..), CompoundPK(..)) import TestTypes(IncPK(..), CompoundPK(..))
spec :: Spec spec :: Spec
spec = afterAll_ resetDb $ around (withApp cfgDefault) $ do spec = beforeAll_ resetDb $ around (withApp cfgDefault) $ do
describe "Posting new record" $ do describe "Posting new record" $ do
after_ (clearTable "menagerie") . context "disparate csv types" $ do after_ (clearTable "menagerie") . context "disparate csv types" $ do
it "accepts disparate json types" $ do it "accepts disparate json types" $ do
@@ -301,17 +301,16 @@ spec = afterAll_ resetDb $ around (withApp cfgDefault) $ do
context "on an empty table" $ context "on an empty table" $
it "indicates no records found to update" $ it "indicates no records found to update" $
request methodPatch "/simple_pk" [] request methodPatch "/empty_table" []
[json| { "extra":20 } |] [json| { "extra":20 } |]
`shouldRespondWith` 404 `shouldRespondWith` 404
context "in a nonempty table" . before_ (clearTable "items" >> createItems 15) . context "in a nonempty table" $ do
after_ (clearTable "items") $ do
it "can update a single item" $ do it "can update a single item" $ do
g <- get "/items?id=eq.42" g <- get "/items?id=eq.42"
liftIO $ simpleHeaders g liftIO $ simpleHeaders g
`shouldSatisfy` matchHeader "Content-Range" "\\*/0" `shouldSatisfy` matchHeader "Content-Range" "\\*/0"
request methodPatch "/items?id=eq.1" [] request methodPatch "/items?id=eq.2" []
[json| { "id":42 } |] [json| { "id":42 } |]
`shouldRespondWith` ResponseMatcher { `shouldRespondWith` ResponseMatcher {
matchBody = Nothing, matchBody = Nothing,
+1 -2
View File
@@ -10,8 +10,7 @@ import SpecHelper
spec :: Spec spec :: Spec
spec = spec =
beforeAll (clearTable "items" >> createItems 15) beforeAll resetDb
. afterAll_ (clearTable "items")
. around (withApp $ cfgLimitRows 3) $ . around (withApp $ cfgLimitRows 3) $
describe "Requesting many items with server limits enabled" $ do describe "Requesting many items with server limits enabled" $ do
it "restricts results" $ it "restricts results" $
+2 -14
View File
@@ -11,18 +11,7 @@ import Text.Heredoc
spec :: Spec spec :: Spec
spec = spec = around (withApp cfgDefault) $ do
beforeAll (clearTable "items" >> createItems 15)
. beforeAll clearProjectsTable
. beforeAll (clearTable "complex_items" >> createComplexItems)
. beforeAll (clearTable "nullable_integer" >> createNullInteger)
. beforeAll (
clearTable "no_pk" >>
createNulls 2 >>
createLikableStrings >>
createJsonData)
. afterAll_ (clearTable "items" >> clearTable "complex_items" >> clearTable "no_pk" >> clearTable "simple_pk")
. around (withApp cfgDefault) $ do
describe "Querying a table with a column called count" $ describe "Querying a table with a column called count" $
it "should not confuse count column with pg_catalog.count aggregate" $ it "should not confuse count column with pg_catalog.count aggregate" $
@@ -355,8 +344,7 @@ spec =
[json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |] [json| [{"data": {"id": 1, "foo": {"bar": "baz"}}}] |]
describe "remote procedure call" $ do describe "remote procedure call" $ do
context "a proc that returns a set" . before_ (clearTable "items" >> createItems 10) . context "a proc that returns a set" $
after_ (clearTable "items") $
it "returns proper json" $ it "returns proper json" $
post "/rpc/getitemrange" [json| { "min": 2, "max": 4 } |] `shouldRespondWith` post "/rpc/getitemrange" [json| { "min": 2, "max": 4 } |] `shouldRespondWith`
[json| [ {"id": 3}, {"id":4} ] |] [json| [ {"id": 3}, {"id":4} ] |]
+1 -1
View File
@@ -9,7 +9,7 @@ import Network.Wai.Test (SResponse(simpleHeaders,simpleStatus))
import SpecHelper import SpecHelper
spec :: Spec spec :: Spec
spec = beforeAll (clearTable "items" >> createItems 15) . afterAll_ (clearTable "items") spec = beforeAll resetDb
. around (withApp cfgDefault) $ . around (withApp cfgDefault) $
describe "GET /items" $ do describe "GET /items" $ do
+1 -1
View File
@@ -5,4 +5,4 @@ import SpecHelper
import Spec import Spec
main :: IO () main :: IO ()
main = resetDb >> hspec spec main = setupDb >> hspec spec
+20 -85
View File
@@ -14,7 +14,6 @@ import Data.Text hiding (map)
import qualified Data.Vector as V import qualified Data.Vector as V
import Data.Time.Clock.POSIX (getPOSIXTime) import Data.Time.Clock.POSIX (getPOSIXTime)
import Control.Monad (void) import Control.Monad (void)
import Control.Applicative
import Network.HTTP.Types.Header (Header, ByteRange, renderByteRange, import Network.HTTP.Types.Header (Header, ByteRange, renderByteRange,
hRange, hAuthorization, hAccept) hRange, hAuthorization, hAccept)
@@ -26,28 +25,30 @@ import qualified Data.ByteString.Char8 as BS
import System.Process (readProcess) import System.Process (readProcess)
import Web.JWT (secret) import Web.JWT (secret)
import qualified Data.Aeson.Types as J
import PostgREST.App (app) import PostgREST.App (app)
import PostgREST.Config (AppConfig(..)) import PostgREST.Config (AppConfig(..))
import PostgREST.Middleware import PostgREST.Middleware
import PostgREST.Error(pgErrResponse) import PostgREST.Error(pgErrResponse)
import PostgREST.DbStructure import PostgREST.DbStructure
systemDb :: String
systemDb = "postgres://localhost"
dbString :: String dbString :: String
dbString = "postgres://postgrest_test@localhost:5432/postgrest_test" dbString = "postgres://postgrest_authenticator@localhost:5432/postgrest_test"
isLeft :: Either a b -> Bool isLeft :: Either a b -> Bool
isLeft (Left _ ) = True isLeft (Left _ ) = True
isLeft _ = False isLeft _ = False
cfg :: String -> Maybe Int -> AppConfig
cfg conStr limit = AppConfig conStr 3000 "postgrest_anonymous" "test" (secret "safe") 10 limit
cfgDefault :: AppConfig cfgDefault :: AppConfig
cfgDefault = AppConfig dbString 3000 "postgrest_anonymous" "test" (secret "safe") 10 Nothing cfgDefault = cfg dbString Nothing
cfgLimitRows :: Int -> AppConfig cfgLimitRows :: Int -> AppConfig
cfgLimitRows limit = cfgLimitRows = (cfg dbString) . Just
AppConfig dbString 3000 "postgrest_anonymous" "test"
(secret "safe") 10 (Just limit)
testPoolOpts :: PoolSettings testPoolOpts :: PoolSettings
testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30 testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30
@@ -55,6 +56,9 @@ testPoolOpts = fromMaybe (error "bad settings") $ H.poolSettings 1 30
pgSettings :: P.Settings pgSettings :: P.Settings
pgSettings = P.StringSettings $ cs dbString pgSettings = P.StringSettings $ cs dbString
setupSettings :: P.Settings
setupSettings = P.StringSettings $ cs systemDb
withApp :: AppConfig -> ActionWith Application -> IO () withApp :: AppConfig -> ActionWith Application -> IO ()
withApp config perform = do withApp config perform = do
pool :: H.Pool P.Postgres pool :: H.Pool P.Postgres
@@ -73,20 +77,16 @@ withApp config perform = do
where middle = defaultMiddle where middle = defaultMiddle
setupDb :: IO ()
setupDb = do
void $ readProcess "psql" ["-a", "-f", "test/fixtures/database.sql"] []
loadFixture "roles"
loadFixture "schema"
resetDb
resetDb :: IO () resetDb :: IO ()
resetDb = do resetDb = do
pool :: H.Pool P.Postgres loadFixture "data"
<- H.acquirePool pgSettings testPoolOpts
void . liftIO $ H.session pool $
H.tx Nothing $ do
H.unitEx [H.stmt| drop schema if exists test cascade |]
H.unitEx [H.stmt| drop schema if exists private cascade |]
H.unitEx [H.stmt| drop schema if exists postgrest cascade |]
loadFixture "roles"
loadFixture "schema"
loadFixture :: FilePath -> IO() loadFixture :: FilePath -> IO()
loadFixture name = loadFixture name =
@@ -121,69 +121,4 @@ clearTable :: Text -> IO ()
clearTable table = do clearTable table = do
pool <- testPool pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing $ void . liftIO $ H.session pool $ H.tx Nothing $
H.unitEx $ B.Stmt ("delete from test."<>table) V.empty True H.unitEx $ B.Stmt ("truncate table test." <> table <> " cascade") V.empty True
clearProjectsTable :: IO ()
clearProjectsTable = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing $
H.unitEx $ B.Stmt "delete from test.projects where id > 4" V.empty True
createItems :: Int -> IO ()
createItems n = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing txn
where
txn = mapM_ H.unitEx stmts
stmts = map [H.stmt|insert into test.items (id) values (?)|] [1..n]
createComplexItems :: IO ()
createComplexItems = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing txn
where
txn = mapM_ H.unitEx stmts
stmts = getZipList $ [H.stmt|insert into test.complex_items (id, name, settings, arr_data) values (?,?,?,?)|]
<$> ZipList ([1..3]::[Int])
<*> ZipList (["One", "Two", "Three"]::[Text])
<*> ZipList [jobj,jobj,jobj]
<*> ZipList ([[1], [1,2], [1,2,3]]::[[Int]])
jobj = J.object [("foo", J.object [("int", J.Number 1),("bar", J.String "baz")])]
createNulls :: Int -> IO ()
createNulls n = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing txn
where
txn = mapM_ H.unitEx (stmt':stmts)
stmt' = [H.stmt|insert into test.no_pk (a,b) values (null,null)|]
stmts = map [H.stmt|insert into test.no_pk (a,b) values (?,0)|] [1..n]
createNullInteger :: IO ()
createNullInteger = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing $
H.unitEx $ [H.stmt| insert into "test".nullable_integer (a) values (null) |]
createLikableStrings :: IO ()
createLikableStrings = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing $ do
H.unitEx $ insertSimplePk "xyyx" "u"
H.unitEx $ insertSimplePk "xYYx" "v"
where
insertSimplePk :: Text -> Text -> H.Stmt P.Postgres
insertSimplePk = [H.stmt|insert into test.simple_pk (k, extra) values (?,?)|]
createJsonData :: IO ()
createJsonData = do
pool <- testPool
void . liftIO $ H.session pool $ H.tx Nothing $
H.unitEx $
[H.stmt|
insert into test.json (data) values (?)
|]
(J.object [("id", J.Number 1)
,("foo", J.object [("bar", J.String "baz")])
])
+19 -2
View File
@@ -11,7 +11,6 @@ SET client_encoding = 'UTF8';
SET standard_conforming_strings = on; SET standard_conforming_strings = on;
SET check_function_bodies = false; SET check_function_bodies = false;
SET client_min_messages = warning; SET client_min_messages = warning;
SET row_security = off;
SET search_path = postgrest, pg_catalog; SET search_path = postgrest, pg_catalog;
@@ -19,6 +18,7 @@ SET search_path = postgrest, pg_catalog;
-- Data for Name: auth; Type: TABLE DATA; Schema: postgrest; Owner: - -- Data for Name: auth; Type: TABLE DATA; Schema: postgrest; Owner: -
-- --
TRUNCATE TABLE auth CASCADE;
INSERT INTO auth VALUES ('jdoe', 'postgrest_test_author', '1234 '); INSERT INTO auth VALUES ('jdoe', 'postgrest_test_author', '1234 ');
@@ -28,6 +28,7 @@ SET search_path = private, pg_catalog;
-- Data for Name: articles; Type: TABLE DATA; Schema: private; Owner: - -- Data for Name: articles; Type: TABLE DATA; Schema: private; Owner: -
-- --
TRUNCATE TABLE articles CASCADE;
INSERT INTO articles VALUES (1, 'No… It''s a thing; it''s like a plan, but with more greatness.', 'diogo'); INSERT INTO articles VALUES (1, 'No… It''s a thing; it''s like a plan, but with more greatness.', 'diogo');
INSERT INTO articles VALUES (2, 'Stop talking, brain thinking. Hush.', 'diogo'); INSERT INTO articles VALUES (2, 'Stop talking, brain thinking. Hush.', 'diogo');
INSERT INTO articles VALUES (3, 'It''s a fez. I wear a fez now. Fezes are cool.', 'diogo'); INSERT INTO articles VALUES (3, 'It''s a fez. I wear a fez now. Fezes are cool.', 'diogo');
@@ -39,6 +40,7 @@ SET search_path = test, pg_catalog;
-- Data for Name: users; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: users; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE users CASCADE;
INSERT INTO users VALUES (1, 'Angela Martin'); INSERT INTO users VALUES (1, 'Angela Martin');
INSERT INTO users VALUES (2, 'Michael Scott'); INSERT INTO users VALUES (2, 'Michael Scott');
INSERT INTO users VALUES (3, 'Dwight Schrute'); INSERT INTO users VALUES (3, 'Dwight Schrute');
@@ -50,6 +52,7 @@ SET search_path = private, pg_catalog;
-- Data for Name: article_stars; Type: TABLE DATA; Schema: private; Owner: - -- Data for Name: article_stars; Type: TABLE DATA; Schema: private; Owner: -
-- --
TRUNCATE TABLE article_stars CASCADE;
INSERT INTO article_stars VALUES (1, 1, '2015-12-08 04:22:57.472738'); INSERT INTO article_stars VALUES (1, 1, '2015-12-08 04:22:57.472738');
INSERT INTO article_stars VALUES (1, 2, '2015-12-08 04:22:57.472738'); INSERT INTO article_stars VALUES (1, 2, '2015-12-08 04:22:57.472738');
INSERT INTO article_stars VALUES (2, 3, '2015-12-08 04:22:57.472738'); INSERT INTO article_stars VALUES (2, 3, '2015-12-08 04:22:57.472738');
@@ -82,6 +85,7 @@ SELECT pg_catalog.setval('auto_incrementing_pk_id_seq', 1, true);
-- Data for Name: clients; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: clients; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE clients CASCADE;
INSERT INTO clients VALUES (1, 'Microsoft'); INSERT INTO clients VALUES (1, 'Microsoft');
INSERT INTO clients VALUES (2, 'Apple'); INSERT INTO clients VALUES (2, 'Apple');
@@ -90,6 +94,7 @@ INSERT INTO clients VALUES (2, 'Apple');
-- Data for Name: projects; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: projects; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE projects CASCADE;
INSERT INTO projects VALUES (1, 'Windows 7', 1); INSERT INTO projects VALUES (1, 'Windows 7', 1);
INSERT INTO projects VALUES (2, 'Windows 10', 1); INSERT INTO projects VALUES (2, 'Windows 10', 1);
INSERT INTO projects VALUES (3, 'IOS', 2); INSERT INTO projects VALUES (3, 'IOS', 2);
@@ -100,6 +105,7 @@ INSERT INTO projects VALUES (4, 'OSX', 2);
-- Data for Name: tasks; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: tasks; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE tasks CASCADE;
INSERT INTO tasks VALUES (1, 'Design w7', 1); INSERT INTO tasks VALUES (1, 'Design w7', 1);
INSERT INTO tasks VALUES (2, 'Code w7', 1); INSERT INTO tasks VALUES (2, 'Code w7', 1);
INSERT INTO tasks VALUES (3, 'Design w10', 2); INSERT INTO tasks VALUES (3, 'Design w10', 2);
@@ -114,6 +120,7 @@ INSERT INTO tasks VALUES (8, 'Code OSX', 4);
-- Data for Name: users_tasks; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: users_tasks; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE users_tasks CASCADE;
INSERT INTO users_tasks VALUES (1, 1); INSERT INTO users_tasks VALUES (1, 1);
INSERT INTO users_tasks VALUES (1, 2); INSERT INTO users_tasks VALUES (1, 2);
INSERT INTO users_tasks VALUES (1, 3); INSERT INTO users_tasks VALUES (1, 3);
@@ -129,6 +136,7 @@ INSERT INTO users_tasks VALUES (3, 5);
-- Data for Name: comments; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: comments; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE comments CASCADE;
INSERT INTO comments VALUES (1, 1, 2, 6, 'Needs to be delivered ASAP'); INSERT INTO comments VALUES (1, 1, 2, 6, 'Needs to be delivered ASAP');
@@ -136,6 +144,7 @@ INSERT INTO comments VALUES (1, 1, 2, 6, 'Needs to be delivered ASAP');
-- Data for Name: complex_items; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: complex_items; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE complex_items CASCADE;
INSERT INTO complex_items VALUES (1, 'One', '{"foo":{"int":1,"bar":"baz"}}', '{1}'); INSERT INTO complex_items VALUES (1, 'One', '{"foo":{"int":1,"bar":"baz"}}', '{1}');
INSERT INTO complex_items VALUES (2, 'Two', '{"foo":{"int":1,"bar":"baz"}}', '{1,2}'); INSERT INTO complex_items VALUES (2, 'Two', '{"foo":{"int":1,"bar":"baz"}}', '{1,2}');
INSERT INTO complex_items VALUES (3, 'Three', '{"foo":{"int":1,"bar":"baz"}}', '{1,2,3}'); INSERT INTO complex_items VALUES (3, 'Three', '{"foo":{"int":1,"bar":"baz"}}', '{1,2,3}');
@@ -151,7 +160,9 @@ INSERT INTO complex_items VALUES (3, 'Three', '{"foo":{"int":1,"bar":"baz"}}', '
-- Data for Name: simple_pk; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: simple_pk; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE simple_pk CASCADE;
INSERT INTO simple_pk VALUES ('xyyx', 'u');
INSERT INTO simple_pk VALUES ('xYYx', 'v');
-- --
-- Data for Name: has_fk; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: has_fk; Type: TABLE DATA; Schema: test; Owner: -
@@ -170,6 +181,7 @@ SELECT pg_catalog.setval('has_fk_id_seq', 1, false);
-- Data for Name: items; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: items; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE items CASCADE;
INSERT INTO items VALUES (1); INSERT INTO items VALUES (1);
INSERT INTO items VALUES (2); INSERT INTO items VALUES (2);
INSERT INTO items VALUES (3); INSERT INTO items VALUES (3);
@@ -198,6 +210,7 @@ SELECT pg_catalog.setval('items_id_seq', 1, true);
-- Data for Name: json; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: json; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE json CASCADE;
INSERT INTO json VALUES ('{"foo":{"bar":"baz"},"id":1}'); INSERT INTO json VALUES ('{"foo":{"bar":"baz"},"id":1}');
@@ -211,6 +224,7 @@ INSERT INTO json VALUES ('{"foo":{"bar":"baz"},"id":1}');
-- Data for Name: no_pk; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: no_pk; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE no_pk CASCADE;
INSERT INTO no_pk VALUES (NULL, NULL); INSERT INTO no_pk VALUES (NULL, NULL);
INSERT INTO no_pk VALUES ('1', '0'); INSERT INTO no_pk VALUES ('1', '0');
INSERT INTO no_pk VALUES ('2', '0'); INSERT INTO no_pk VALUES ('2', '0');
@@ -220,6 +234,7 @@ INSERT INTO no_pk VALUES ('2', '0');
-- Data for Name: nullable_integer; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: nullable_integer; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE nullable_integer CASCADE;
INSERT INTO nullable_integer VALUES (NULL); INSERT INTO nullable_integer VALUES (NULL);
@@ -227,6 +242,7 @@ INSERT INTO nullable_integer VALUES (NULL);
-- Data for Name: tsearch; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: tsearch; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE tsearch CASCADE;
INSERT INTO tsearch VALUES ('''bar'':2 ''foo'':1'); INSERT INTO tsearch VALUES ('''bar'':2 ''foo'':1');
INSERT INTO tsearch VALUES ('''baz'':1 ''qux'':2'); INSERT INTO tsearch VALUES ('''baz'':1 ''qux'':2');
@@ -235,6 +251,7 @@ INSERT INTO tsearch VALUES ('''baz'':1 ''qux'':2');
-- Data for Name: users_projects; Type: TABLE DATA; Schema: test; Owner: - -- Data for Name: users_projects; Type: TABLE DATA; Schema: test; Owner: -
-- --
TRUNCATE TABLE users_projects CASCADE;
INSERT INTO users_projects VALUES (1, 1); INSERT INTO users_projects VALUES (1, 1);
INSERT INTO users_projects VALUES (1, 2); INSERT INTO users_projects VALUES (1, 2);
INSERT INTO users_projects VALUES (2, 3); INSERT INTO users_projects VALUES (2, 3);
+3 -1
View File
@@ -1,2 +1,4 @@
DROP DATABASE IF EXISTS postgrest_test; DROP DATABASE IF EXISTS postgrest_test;
CREATE DATABASE postgrest_test; DROP ROLE IF EXISTS postgrest_test;
CREATE USER postgrest_test createdb createrole;
CREATE DATABASE postgrest_test OWNER postgrest_test;
+6 -15
View File
@@ -1,16 +1,7 @@
create function pg_temp.create_role_if_not_exists(rolename name, opts character varying) RETURNS text DROP ROLE IF EXISTS postgrest_authenticator, postgrest_anonymous, test_default_role, postgrest_test_author;
LANGUAGE plpgsql CREATE ROLE postgrest_authenticator WITH login;
AS $$ CREATE ROLE postgrest_anonymous;
BEGIN CREATE ROLE test_default_role;
IF NOT EXISTS (SELECT * FROM pg_roles WHERE rolname = rolename) THEN CREATE ROLE postgrest_test_author;
EXECUTE format('CREATE ROLE %I %s', rolename, opts);
RETURN 'CREATE ROLE';
ELSE
RETURN format('ROLE ''%I'' ALREADY EXISTS', rolename);
END IF;
END;
$$;
select pg_temp.create_role_if_not_exists('postgrest_anonymous', 'with nologin') as a GRANT postgrest_anonymous, test_default_role, postgrest_test_author TO postgrest_authenticator;
, pg_temp.create_role_if_not_exists('test_default_role', 'with nologin') as b
, pg_temp.create_role_if_not_exists('postgrest_test_author', 'with nologin') into temp shh;
+951 -465
View File
File diff suppressed because it is too large Load Diff