Delete unused files
This commit is contained in:
committed by
Steve Chávez
parent
39adbefb9d
commit
7c376d6e84
@@ -1,10 +0,0 @@
|
|||||||
export POSTGREST_VER=`grep ^version /app/postgrest.cabal | sed -En 's/.*\s+([0-9\.]+)/\1/p'`
|
|
||||||
|
|
||||||
curl -L http://sourceforge.net/projects/s3tools/files/s3cmd/1.5.0-alpha1/s3cmd-1.5.0-alpha1.tar.gz | tar zx
|
|
||||||
|
|
||||||
cp /app/dist/build/postgrest/postgrest postgrest-${POSTGREST_VER}
|
|
||||||
tar cJf postgrest-${POSTGREST_VER}.tar.xz postgrest-${POSTGREST_VER}
|
|
||||||
|
|
||||||
touch ~/.s3cfg
|
|
||||||
|
|
||||||
s3cmd-1.5.0-alpha1/s3cmd put --access_key=${S3_ACCESS_KEY} --secret_key=${S3_SECRET_KEY} -P -f postgrest-${POSTGREST_VER}.tar.xz $S3_BUCKET/postgrest-${POSTGREST_VER}.tar.xz
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
module Unit.DbStructureSpec where
|
|
||||||
|
|
||||||
import Test.Hspec
|
|
||||||
import DbStructure (Table(..), tables, Column(..), columns, ForeignKey(..),
|
|
||||||
foreignKeys)
|
|
||||||
|
|
||||||
import Database.HDBC (quickQuery)
|
|
||||||
import SpecHelper(dbWithSchema)
|
|
||||||
import qualified Data.Map as M;
|
|
||||||
|
|
||||||
spec :: Spec
|
|
||||||
spec = around dbWithSchema $ beforeWith setRole $ do
|
|
||||||
describe "tables" $
|
|
||||||
it "shows all the tables" $ \conn -> do
|
|
||||||
ts <- tables "test" conn
|
|
||||||
map tableName ts `shouldBe` ["authors_only","auto_incrementing_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
|
|
||||||
cs <- columns "test" "auto_incrementing_pk" conn
|
|
||||||
map colName cs `shouldBe` ["id","nullable_string","non_nullable_string",
|
|
||||||
"inserted_at"]
|
|
||||||
|
|
||||||
it "includes foreign key data" $ \conn -> do
|
|
||||||
cs <- columns "test" "has_fk" conn
|
|
||||||
map colFK cs `shouldBe` [Nothing,
|
|
||||||
Just $ ForeignKey "auto_incrementing_pk" "id",
|
|
||||||
Just $ ForeignKey "simple_pk" "k"]
|
|
||||||
|
|
||||||
describe "foreignKeys" $
|
|
||||||
it "has a description of the foreign key columns" $ \conn ->
|
|
||||||
foreignKeys "test" "has_fk" conn `shouldReturn` M.fromList [
|
|
||||||
("auto_inc_fk", ForeignKey {fkTable="auto_incrementing_pk", fkCol="id"}),
|
|
||||||
("simple_fk", ForeignKey { fkTable="simple_pk", fkCol="k"})]
|
|
||||||
|
|
||||||
where setRole conn = quickQuery conn "set role postgrest_test" [] >> return conn
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
module Unit.PgQuerySpec where
|
|
||||||
|
|
||||||
import Test.Hspec
|
|
||||||
import Test.QuickCheck
|
|
||||||
import Test.QuickCheck.Monadic
|
|
||||||
|
|
||||||
import Database.HDBC (IConnection, SqlValue, toSql, prepare,
|
|
||||||
quickQuery, fromSql, execute, seState, fetchAllRowsAL)
|
|
||||||
|
|
||||||
import PgQuery (LoginAttempt(..), insert, addUser, signInRole, checkPass
|
|
||||||
, pgFmtIdent, pgFmtLit)
|
|
||||||
import Types (SqlRow(SqlRow))
|
|
||||||
import TestTypes (incFromList, incStr, incNullableStr, incInsert, incId)
|
|
||||||
import Data.Map (toList)
|
|
||||||
import Data.String.Conversions (cs)
|
|
||||||
import Data.Monoid ((<>))
|
|
||||||
import Control.Arrow
|
|
||||||
|
|
||||||
import SpecHelper(dbWithSchema)
|
|
||||||
|
|
||||||
quickALQuery :: IConnection conn => conn ->
|
|
||||||
String ->
|
|
||||||
[SqlValue] ->
|
|
||||||
IO [[(String, SqlValue)]]
|
|
||||||
quickALQuery conn q bind = do
|
|
||||||
sth <- prepare conn q
|
|
||||||
_ <- execute sth bind
|
|
||||||
fetchAllRowsAL sth
|
|
||||||
|
|
||||||
spec :: Spec
|
|
||||||
spec = around dbWithSchema $ do
|
|
||||||
describe "insert" $
|
|
||||||
describe "with an auto-increment key" $ do
|
|
||||||
it "inserts and responds with a full object description" $ \conn -> do
|
|
||||||
r <- insert "test" "auto_incrementing_pk" (SqlRow [
|
|
||||||
("non_nullable_string", toSql ("a string"::String))]) conn
|
|
||||||
let returnRow = incFromList . toList $ r
|
|
||||||
incStr returnRow `shouldBe` "a string"
|
|
||||||
incNullableStr returnRow `shouldBe` Nothing
|
|
||||||
incInsert returnRow `shouldSatisfy` not . null
|
|
||||||
incId returnRow `shouldSatisfy` (>= 0)
|
|
||||||
tRows <- quickALQuery conn "select * from \"1\".auto_incrementing_pk" []
|
|
||||||
[returnRow] `shouldBe` map incFromList tRows
|
|
||||||
|
|
||||||
it "throws an exception if the PK is not unique" $ \conn -> do
|
|
||||||
r <- insert "test" "auto_incrementing_pk" (SqlRow [
|
|
||||||
("non_nullable_string", toSql ("a string"::String))]) conn
|
|
||||||
let row = SqlRow . map (Control.Arrow.first cs) . toList $ r
|
|
||||||
insert "test" "auto_incrementing_pk" row conn `shouldThrow` \e ->
|
|
||||||
seState e == "23505" -- uniqueness violation code
|
|
||||||
|
|
||||||
it "throws an exception if a required value is missing" $ \conn ->
|
|
||||||
insert "test" "auto_incrementing_pk" (SqlRow [
|
|
||||||
("nullable_string", toSql ("a string"::String))]) conn
|
|
||||||
`shouldThrow` \e -> seState e == "23502"
|
|
||||||
|
|
||||||
it "generates a default values query if no data is provided" $ \c -> do
|
|
||||||
r <- insert "test" "items" (SqlRow []) c
|
|
||||||
let [row] = toList r
|
|
||||||
quickALQuery c "select * from \"1\".items where id = ?" [snd row]
|
|
||||||
`shouldReturn` [[row]]
|
|
||||||
|
|
||||||
let {user = "jdoe"; pass = "secret"; role = "postgrest_test_default_role"}
|
|
||||||
describe "addUser" $ do
|
|
||||||
it "adds a correct user to the right table" $ \conn -> do
|
|
||||||
addUser user pass role conn
|
|
||||||
[r] <- quickQuery conn "select * from postgrest.auth" []
|
|
||||||
let [newUser, newRole, encryptedPass] = map fromSql r :: [String]
|
|
||||||
cs newUser `shouldBe` user
|
|
||||||
cs newRole `shouldBe` role
|
|
||||||
checkPass (cs encryptedPass) pass `shouldBe` True
|
|
||||||
|
|
||||||
it "will not add a user with an unknown role" $ \conn ->
|
|
||||||
addUser user pass "not-a-real-role" conn `shouldThrow` \e ->
|
|
||||||
take 2 (seState e) == "23" --integrity constraint violation
|
|
||||||
|
|
||||||
|
|
||||||
describe "signInRole" $ beforeWith (\conn -> do
|
|
||||||
addUser user pass role conn
|
|
||||||
return conn) $ do
|
|
||||||
it "accepts correct credentials and return the role" $ \conn ->
|
|
||||||
signInRole user pass conn `shouldReturn` LoginSuccess role user
|
|
||||||
|
|
||||||
it "returns nothing with bad creds" $ \conn -> do
|
|
||||||
signInRole "not-a-user" pass conn `shouldReturn` LoginFailed
|
|
||||||
signInRole user (pass <> "crap") conn `shouldReturn` LoginFailed
|
|
||||||
|
|
||||||
describe "pgFmtIdent" $
|
|
||||||
it "Does what format %I would do" $ \conn -> property $ \fuzz ->
|
|
||||||
monadicIO $ do
|
|
||||||
[[row]] <- run $ quickALQuery conn "select format('%I', ? :: varchar)" [toSql (fuzz :: String)]
|
|
||||||
assert $ fromSql (snd row) == pgFmtIdent (cs fuzz)
|
|
||||||
|
|
||||||
describe "pgFmtLit" $
|
|
||||||
it "Does what format %L would do" $ \conn ->
|
|
||||||
property $ monadicIO $ do
|
|
||||||
fuzz <- pick arbitrary
|
|
||||||
[[row]] <- run $ quickALQuery conn "select format('%L', ? :: varchar)" [toSql (fuzz :: String)]
|
|
||||||
assert $ fromSql (snd row) == pgFmtLit (cs fuzz)
|
|
||||||
Vendored
-21
@@ -176,20 +176,6 @@ CREATE FUNCTION noparamsproc() RETURNS text
|
|||||||
SELECT a FROM (VALUES ('Return value of no parameters procedure.')) s(a);
|
SELECT a FROM (VALUES ('Return value of no parameters procedure.')) s(a);
|
||||||
$$;
|
$$;
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: insert_insertable_view_with_join(); Type: FUNCTION; Schema: test; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
CREATE FUNCTION insert_insertable_view_with_join() RETURNS trigger
|
|
||||||
LANGUAGE plpgsql
|
|
||||||
AS $$
|
|
||||||
begin
|
|
||||||
INSERT INTO test.auto_incrementing_pk (nullable_string, non_nullable_string) VALUES (NEW.nullable_string, NEW.non_nullable_string);
|
|
||||||
RETURN NEW;
|
|
||||||
end;
|
|
||||||
$$;
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: login(text, text); Type: FUNCTION; Schema: test; Owner: -
|
-- Name: login(text, text); Type: FUNCTION; Schema: test; Owner: -
|
||||||
--
|
--
|
||||||
@@ -964,13 +950,6 @@ CREATE TRIGGER articles_owner_track BEFORE INSERT OR UPDATE ON articles FOR EACH
|
|||||||
|
|
||||||
SET search_path = test, pg_catalog;
|
SET search_path = test, pg_catalog;
|
||||||
|
|
||||||
--
|
|
||||||
-- Name: insert_insertable_view_with_join; Type: TRIGGER; Schema: test; Owner: -
|
|
||||||
--
|
|
||||||
|
|
||||||
CREATE TRIGGER insert_insertable_view_with_join INSTEAD OF INSERT ON insertable_view_with_join FOR EACH ROW EXECUTE PROCEDURE insert_insertable_view_with_join();
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: secrets_owner_track; Type: TRIGGER; Schema: test; Owner: -
|
-- Name: secrets_owner_track; Type: TRIGGER; Schema: test; Owner: -
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user