Merge branch 'fk'
Conflicts: src/PgStructure.hs test/Feature/StructureSpec.hs test/fixtures/schema.sql
This commit is contained in:
+1
-1
@@ -77,7 +77,7 @@ httpRequesterRole :: RequestHeaders -> Connection -> IO LoginAttempt
|
||||
httpRequesterRole hdrs conn = do
|
||||
let auth = fromMaybe "" $ lookup hAuthorization hdrs
|
||||
case BS.split ' ' (cs auth) of
|
||||
("Basic " : b64 : _) ->
|
||||
("Basic" : b64 : _) ->
|
||||
case BS.split ':' $ cs (decode $ cs b64) of
|
||||
(u:p:_) -> signInRole u p conn
|
||||
_ -> return MalformedAuth
|
||||
|
||||
+36
-9
@@ -1,8 +1,6 @@
|
||||
-- {{{ Imports
|
||||
|
||||
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
|
||||
module PgStructure where
|
||||
|
||||
import Data.Functor ( (<$>) )
|
||||
@@ -14,14 +12,13 @@ import qualified Data.ByteString.Lazy as BL
|
||||
import Data.List.Split (splitOn)
|
||||
|
||||
import qualified Data.Aeson as JSON
|
||||
import qualified Data.Map as Map
|
||||
|
||||
import Database.HDBC hiding (colType, colNullable)
|
||||
import Database.HDBC.PostgreSQL
|
||||
|
||||
import Data.Aeson ((.=))
|
||||
|
||||
-- }}}
|
||||
|
||||
data Table = Table {
|
||||
tableSchema :: String
|
||||
, tableName :: String
|
||||
@@ -37,6 +34,31 @@ instance JSON.ToJSON Table where
|
||||
toBool :: String -> Bool
|
||||
toBool = (== "YES")
|
||||
|
||||
data ForeignKey = ForeignKey {
|
||||
fkTable::String, fkCol::String
|
||||
} deriving (Eq, Show)
|
||||
|
||||
instance JSON.ToJSON ForeignKey where
|
||||
toJSON fk = JSON.object ["table".=fkTable fk, "column".=fkCol fk]
|
||||
|
||||
foreignKeys :: String -> String -> Connection -> IO (Map.Map String ForeignKey)
|
||||
foreignKeys schema table conn = do
|
||||
r <- quickQuery conn
|
||||
"select kcu.column_name, ccu.table_name AS foreign_table_name,\
|
||||
\ ccu.column_name AS foreign_column_name \
|
||||
\from information_schema.table_constraints AS tc \
|
||||
\ join information_schema.key_column_usage AS kcu \
|
||||
\ on tc.constraint_name = kcu.constraint_name \
|
||||
\ join information_schema.constraint_column_usage AS ccu \
|
||||
\ on ccu.constraint_name = tc.constraint_name \
|
||||
\where constraint_type = 'FOREIGN KEY' \
|
||||
\ and tc.table_name=? and tc.table_schema = ? \
|
||||
\order by kcu.column_name" (map toSql [table, schema])
|
||||
return $ foldl addKey Map.empty $ map (map fromSql) r
|
||||
where
|
||||
addKey m [col, ftab, fcol] = Map.insert col (ForeignKey ftab fcol) m
|
||||
addKey m _ = m --should never happen
|
||||
|
||||
data Column = Column {
|
||||
colSchema :: String
|
||||
, colTable :: String
|
||||
@@ -49,6 +71,7 @@ data Column = Column {
|
||||
, colPrecision :: Maybe Int
|
||||
, colDefault :: Maybe String
|
||||
, colEnum :: Maybe [String]
|
||||
, colFK :: Maybe ForeignKey
|
||||
} deriving (Show)
|
||||
|
||||
instance JSON.ToJSON Column where
|
||||
@@ -61,6 +84,7 @@ instance JSON.ToJSON Column where
|
||||
, "updatable" .= colUpdatable c
|
||||
, "maxLen" .= colMaxLen c
|
||||
, "precision" .= colPrecision c
|
||||
, "references".= colFK c
|
||||
, "default" .= colDefault c
|
||||
, "enum" .= colEnum c ]
|
||||
|
||||
@@ -120,11 +144,15 @@ columns s t conn = do
|
||||
\ ) as enum_info \
|
||||
\ on (info.udt_name = enum_info.n) \
|
||||
\order by position" [toSql s, toSql t]
|
||||
return $ mapMaybe mkColumn r
|
||||
fks <- foreignKeys s t conn
|
||||
let lookupFK (_:_:name:_) = Map.lookup (fromSql name) fks
|
||||
lookupFK _ = Nothing
|
||||
let cols = zipWith ($) (map mkColumn r) (map lookupFK r)
|
||||
return cols
|
||||
|
||||
where
|
||||
mkColumn [schema, table, name, pos, nullable, colT, updatable, maxlen, precision, defVal, enum] =
|
||||
Just $ Column (fromSql schema)
|
||||
--TODO: handle failed pattern match with an appropriate exception
|
||||
mkColumn [schema, table, name, pos, nullable, colT, updatable, maxlen, precision, defVal, enum] = Column (fromSql schema)
|
||||
(fromSql table)
|
||||
(fromSql name)
|
||||
(fromSql pos)
|
||||
@@ -135,7 +163,6 @@ columns s t conn = do
|
||||
(fromSql precision)
|
||||
(fromSql defVal)
|
||||
(splitOn "," <$> fromSql enum)
|
||||
mkColumn _ = Nothing
|
||||
|
||||
printTables :: String -> Connection -> IO BL.ByteString
|
||||
printTables schema conn = JSON.encode <$> tables schema conn
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
|
||||
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
|
||||
module Feature.StructureSpec where
|
||||
|
||||
@@ -8,15 +9,26 @@ import Test.Hspec.Wai.JSON
|
||||
import SpecHelper
|
||||
|
||||
import Network.HTTP.Types
|
||||
import Codec.Binary.Base64.String (encode)
|
||||
import Data.Monoid ((<>))
|
||||
import Data.String.Conversions (cs)
|
||||
|
||||
uName = "a user"
|
||||
uPass = "nobody can ever know"
|
||||
uRole = "dbapi_test"
|
||||
|
||||
spec :: Spec
|
||||
spec = around appWithFixture $ do
|
||||
spec = around withDatabaseConnection $
|
||||
aroundWith (withUser uName uPass uRole) $ aroundWith withApp $ do
|
||||
describe "GET /" $
|
||||
it "lists views in schema" $
|
||||
get "/" `shouldRespondWith`
|
||||
[json| [
|
||||
{"schema":"1","name":"auto_incrementing_pk","insertable":true}
|
||||
request methodGet "/"
|
||||
[("Authorization", "Basic "<>(cs.encode $ cs uName<>":"<>cs uPass))] ""
|
||||
`shouldRespondWith` [json| [
|
||||
{"schema":"1","name":"authors_only","insertable":true}
|
||||
, {"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":"items","insertable":true}
|
||||
, {"schema":"1","name":"menagerie","insertable":true}
|
||||
, {"schema":"1","name":"no_pk","insertable":true}
|
||||
@@ -24,7 +36,7 @@ spec = around appWithFixture $ do
|
||||
] |]
|
||||
{matchStatus = 200}
|
||||
|
||||
describe "Table info" $
|
||||
describe "Table info" $ do
|
||||
it "is available with OPTIONS verb" $
|
||||
request methodOptions "/menagerie" [] "" `shouldRespondWith`
|
||||
[json|
|
||||
@@ -41,7 +53,9 @@ spec = around appWithFixture $ do
|
||||
"maxLen": null,
|
||||
"enum": null,
|
||||
"nullable": false,
|
||||
"position": 1
|
||||
"position": 1,
|
||||
"references": null,
|
||||
"default": null
|
||||
}, {
|
||||
"default": null,
|
||||
"precision": 53,
|
||||
@@ -52,6 +66,7 @@ spec = around appWithFixture $ do
|
||||
"maxLen": null,
|
||||
"enum": null,
|
||||
"nullable": false,
|
||||
"references": null,
|
||||
"position": 2
|
||||
}, {
|
||||
"default": null,
|
||||
@@ -63,7 +78,9 @@ spec = around appWithFixture $ do
|
||||
"maxLen": null,
|
||||
"enum": null,
|
||||
"nullable": false,
|
||||
"position": 3
|
||||
"position": 3,
|
||||
"references": null,
|
||||
"default": null
|
||||
}, {
|
||||
"default": null,
|
||||
"precision": null,
|
||||
@@ -74,6 +91,7 @@ spec = around appWithFixture $ do
|
||||
"maxLen": null,
|
||||
"enum": null,
|
||||
"nullable": false,
|
||||
"references": null,
|
||||
"position": 4
|
||||
}, {
|
||||
"default": null,
|
||||
@@ -85,6 +103,7 @@ spec = around appWithFixture $ do
|
||||
"maxLen": null,
|
||||
"enum": null,
|
||||
"nullable": false,
|
||||
"references": null,
|
||||
"position": 5
|
||||
}, {
|
||||
"default": null,
|
||||
@@ -96,7 +115,9 @@ spec = around appWithFixture $ do
|
||||
"maxLen": null,
|
||||
"enum": null,
|
||||
"nullable": false,
|
||||
"position": 6
|
||||
"position": 6,
|
||||
"references": null,
|
||||
"default": null
|
||||
}, {
|
||||
"default": null,
|
||||
"precision": null,
|
||||
@@ -110,7 +131,57 @@ spec = around appWithFixture $ do
|
||||
"bar"
|
||||
],
|
||||
"nullable": false,
|
||||
"position": 7
|
||||
"position": 7,
|
||||
"references": null,
|
||||
"default": null
|
||||
}
|
||||
]
|
||||
}
|
||||
|]
|
||||
|
||||
it "includes foreign key data" $
|
||||
request methodOptions "/has_fk"
|
||||
[("Authorization", "Basic "<>(cs.encode $ cs uName<>":"<>cs uPass))] ""
|
||||
`shouldRespondWith` [json|
|
||||
{
|
||||
"pkey": ["id"],
|
||||
"columns":[
|
||||
{
|
||||
"default": "nextval('\"1\".has_fk_id_seq'::regclass)",
|
||||
"precision": 64,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "id",
|
||||
"type": "bigint",
|
||||
"maxLen": null,
|
||||
"nullable": false,
|
||||
"position": 1,
|
||||
"enum": null,
|
||||
"references": null
|
||||
}, {
|
||||
"default": null,
|
||||
"precision": 32,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "auto_inc_fk",
|
||||
"type": "integer",
|
||||
"maxLen": null,
|
||||
"nullable": true,
|
||||
"position": 2,
|
||||
"enum": null,
|
||||
"references": {"table": "auto_incrementing_pk", "column": "id"}
|
||||
}, {
|
||||
"default": null,
|
||||
"precision": null,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "simple_fk",
|
||||
"type": "character varying",
|
||||
"maxLen": 255,
|
||||
"nullable": true,
|
||||
"position": 3,
|
||||
"enum": null,
|
||||
"references": {"table": "simple_pk", "column": "k"}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
+20
-3
@@ -9,9 +9,7 @@ import Database.HDBC
|
||||
import Database.HDBC.PostgreSQL
|
||||
|
||||
import Data.String.Conversions (cs)
|
||||
import Data.Either (isLeft)
|
||||
|
||||
import Control.Exception.Base (bracket, tryJust)
|
||||
import Control.Exception.Base (bracket, finally, tryJust)
|
||||
import Control.Monad (when)
|
||||
|
||||
import Network.HTTP.Types.Header (Header, ByteRange, renderByteRange,
|
||||
@@ -24,6 +22,11 @@ import qualified Data.ByteString.Char8 as BS
|
||||
import Network.Wai.Middleware.Cors (cors)
|
||||
|
||||
import Dbapi (app, corsPolicy, AppConfig(..))
|
||||
import PgQuery(addUser)
|
||||
|
||||
isLeft :: Either a b -> Bool
|
||||
isLeft (Left _ ) = True
|
||||
isLeft _ = False
|
||||
|
||||
cfg :: AppConfig
|
||||
cfg = AppConfig "postgres://dbapi_test:@localhost:5432/dbapi_test" 9000 "test/test.crt" "test/test.key" "dbapi_anonymous"
|
||||
@@ -45,6 +48,20 @@ dbWithSchema action = withDatabaseConnection $ \c -> do
|
||||
action c
|
||||
rollback c
|
||||
|
||||
withUser :: BS.ByteString -> BS.ByteString -> BS.ByteString ->
|
||||
ActionWith Connection -> ActionWith Connection
|
||||
withUser name pass role action conn = do
|
||||
addUser name pass role conn
|
||||
finally (action conn) $ do
|
||||
_ <- run conn "delete from dbapi.auth where id=?" [toSql name]
|
||||
runRaw conn "commit"
|
||||
|
||||
withApp :: ActionWith Application -> ActionWith Connection
|
||||
withApp action conn = do
|
||||
runRaw conn "begin;"
|
||||
action $ cors corsPolicy $ app conn "dbapi_anonymous"
|
||||
rollback conn
|
||||
|
||||
appWithFixture :: ActionWith Application -> IO ()
|
||||
appWithFixture action = withDatabaseConnection $ \c -> do
|
||||
result <- tryJust transactionAborted $ do
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
module Unit.PgStructureSpec where
|
||||
|
||||
import Test.Hspec
|
||||
import PgStructure (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 "1" conn
|
||||
map tableName ts `shouldBe` ["authors_only","auto_incrementing_pk",
|
||||
"compound_pk","has_fk","items","menagerie","no_pk", "simple_pk"]
|
||||
|
||||
describe "columns" $ do
|
||||
it "responds with each column for the table" $ \conn -> do
|
||||
cs <- columns "1" "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 "1" "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 "1" "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 dbapi_test" [] >> return conn
|
||||
+161
-147
@@ -2,9 +2,10 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 9.3.5
|
||||
-- Dumped by pg_dump version 9.3.5
|
||||
-- Started on 2014-10-07 15:55:44 PDT
|
||||
-- Dumped from database version 9.3.4
|
||||
-- Dumped by pg_dump version 9.3.4
|
||||
-- Started on 2014-10-01 13:41:39 PDT
|
||||
-- Started on 2014-10-07 16:46:34 PDT
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
@@ -14,7 +15,7 @@ SET check_function_bodies = false;
|
||||
SET client_min_messages = warning;
|
||||
|
||||
--
|
||||
-- TOC entry 10 (class 2615 OID 309036)
|
||||
-- TOC entry 11 (class 2615 OID 280932)
|
||||
-- Name: 1; Type: SCHEMA; Schema: -; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -24,7 +25,7 @@ CREATE SCHEMA "1";
|
||||
ALTER SCHEMA "1" OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 15 (class 2615 OID 309037)
|
||||
-- TOC entry 8 (class 2615 OID 50928)
|
||||
-- Name: dbapi; Type: SCHEMA; Schema: -; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -34,7 +35,7 @@ CREATE SCHEMA dbapi;
|
||||
ALTER SCHEMA dbapi OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 9 (class 2615 OID 309038)
|
||||
-- TOC entry 9 (class 2615 OID 50929)
|
||||
-- Name: private; Type: SCHEMA; Schema: -; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -44,7 +45,7 @@ CREATE SCHEMA private;
|
||||
ALTER SCHEMA private OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 190 (class 3079 OID 12018)
|
||||
-- TOC entry 187 (class 3079 OID 12018)
|
||||
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
|
||||
--
|
||||
|
||||
@@ -52,14 +53,11 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2287 (class 0 OID 0)
|
||||
-- Dependencies: 190
|
||||
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
|
||||
|
||||
|
||||
SET search_path = "1", pg_catalog;
|
||||
|
||||
--
|
||||
@@ -68,19 +66,16 @@ SET search_path = "1", pg_catalog;
|
||||
--
|
||||
|
||||
CREATE TYPE "1".enum_menagerie_type AS ENUM (
|
||||
'foo',
|
||||
'bar'
|
||||
'foo',
|
||||
'bar'
|
||||
);
|
||||
|
||||
|
||||
SET search_path = dbapi, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 203 (class 1255 OID 309039)
|
||||
-- Name: check_role_exists(); Type: FUNCTION; Schema: dbapi; Owner: dbapi_test
|
||||
--
|
||||
|
||||
CREATE FUNCTION check_role_exists() RETURNS trigger
|
||||
CREATE FUNCTION dbapi.check_role_exists() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
begin
|
||||
@@ -95,12 +90,8 @@ $$;
|
||||
|
||||
ALTER FUNCTION dbapi.check_role_exists() OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 204 (class 1255 OID 309040)
|
||||
-- Name: update_owner(); Type: FUNCTION; Schema: dbapi; Owner: dbapi_test
|
||||
--
|
||||
|
||||
CREATE FUNCTION update_owner() RETURNS trigger
|
||||
CREATE FUNCTION dbapi.update_owner() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
@@ -119,8 +110,16 @@ SET default_tablespace = '';
|
||||
SET default_with_oids = false;
|
||||
|
||||
--
|
||||
-- TOC entry 179 (class 1259 OID 309041)
|
||||
-- Name: auto_incrementing_pk; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
|
||||
CREATE TABLE authors_only (
|
||||
secret character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE "1".authors_only OWNER TO dbapi_test_author;
|
||||
|
||||
--
|
||||
-- TOC entry 175 (class 1259 OID 280937)
|
||||
--
|
||||
|
||||
CREATE TABLE auto_incrementing_pk (
|
||||
@@ -134,7 +133,6 @@ CREATE TABLE auto_incrementing_pk (
|
||||
ALTER TABLE "1".auto_incrementing_pk OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 180 (class 1259 OID 309048)
|
||||
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -149,16 +147,12 @@ CREATE SEQUENCE auto_incrementing_pk_id_seq
|
||||
ALTER TABLE "1".auto_incrementing_pk_id_seq OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 2289 (class 0 OID 0)
|
||||
-- Dependencies: 180
|
||||
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
ALTER SEQUENCE auto_incrementing_pk_id_seq OWNED BY auto_incrementing_pk.id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 181 (class 1259 OID 309050)
|
||||
-- Name: compound_pk; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -172,7 +166,44 @@ CREATE TABLE compound_pk (
|
||||
ALTER TABLE "1".compound_pk OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 182 (class 1259 OID 309053)
|
||||
-- Name: has_fk; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
CREATE TABLE has_fk (
|
||||
id bigint NOT NULL,
|
||||
auto_inc_fk integer,
|
||||
simple_fk character varying(255)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE "1".has_fk OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 185 (class 1259 OID 50947)
|
||||
-- Name: has_fk_id_seq; Type: SEQUENCE; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
CREATE SEQUENCE has_fk_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE "1".has_fk_id_seq OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 2042 (class 0 OID 0)
|
||||
-- Dependencies: 185
|
||||
-- Name: has_fk_id_seq; Type: SEQUENCE OWNED BY; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
ALTER SEQUENCE has_fk_id_seq OWNED BY has_fk.id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 186 (class 1259 OID 50949)
|
||||
-- Name: items; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -184,7 +215,6 @@ CREATE TABLE items (
|
||||
ALTER TABLE "1".items OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 183 (class 1259 OID 309056)
|
||||
-- Name: items_id_seq; Type: SEQUENCE; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -199,8 +229,6 @@ CREATE SEQUENCE items_id_seq
|
||||
ALTER TABLE "1".items_id_seq OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 2293 (class 0 OID 0)
|
||||
-- Dependencies: 183
|
||||
-- Name: items_id_seq; Type: SEQUENCE OWNED BY; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -208,7 +236,6 @@ ALTER SEQUENCE items_id_seq OWNED BY items.id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 184 (class 1259 OID 309058)
|
||||
-- Name: menagerie; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -219,14 +246,13 @@ CREATE TABLE menagerie (
|
||||
"boolean" boolean NOT NULL,
|
||||
date date NOT NULL,
|
||||
money money NOT NULL,
|
||||
enum "1".enum_menagerie_type NOT NULL
|
||||
enum "1".enum_menagerie_type not null
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE "1".menagerie OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 185 (class 1259 OID 309064)
|
||||
-- Name: no_pk; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -239,7 +265,6 @@ CREATE TABLE no_pk (
|
||||
ALTER TABLE "1".no_pk OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 186 (class 1259 OID 309070)
|
||||
-- Name: simple_pk; Type: TABLE; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -254,7 +279,6 @@ ALTER TABLE "1".simple_pk OWNER TO dbapi_test;
|
||||
SET search_path = dbapi, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 187 (class 1259 OID 309076)
|
||||
-- Name: auth; Type: TABLE; Schema: dbapi; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -270,7 +294,6 @@ ALTER TABLE dbapi.auth OWNER TO dbapi_test;
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 188 (class 1259 OID 309082)
|
||||
-- Name: articles; Type: TABLE; Schema: private; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -284,7 +307,6 @@ CREATE TABLE articles (
|
||||
ALTER TABLE private.articles OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 189 (class 1259 OID 309088)
|
||||
-- Name: articles_id_seq; Type: SEQUENCE; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -299,8 +321,6 @@ CREATE SEQUENCE articles_id_seq
|
||||
ALTER TABLE private.articles_id_seq OWNER TO dbapi_test;
|
||||
|
||||
--
|
||||
-- TOC entry 2299 (class 0 OID 0)
|
||||
-- Dependencies: 189
|
||||
-- Name: articles_id_seq; Type: SEQUENCE OWNED BY; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -310,7 +330,6 @@ ALTER SEQUENCE articles_id_seq OWNED BY articles.id;
|
||||
SET search_path = "1", pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2142 (class 2604 OID 309090)
|
||||
-- Name: id; Type: DEFAULT; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -318,7 +337,15 @@ ALTER TABLE ONLY auto_incrementing_pk ALTER COLUMN id SET DEFAULT nextval('auto_
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2143 (class 2604 OID 309091)
|
||||
-- TOC entry 1886 (class 2604 OID 50987)
|
||||
-- Name: id; Type: DEFAULT; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY has_fk ALTER COLUMN id SET DEFAULT nextval('has_fk_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 1887 (class 2604 OID 50988)
|
||||
-- Name: id; Type: DEFAULT; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -328,7 +355,6 @@ ALTER TABLE ONLY items ALTER COLUMN id SET DEFAULT nextval('items_id_seq'::regcl
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2144 (class 2604 OID 309092)
|
||||
-- Name: id; Type: DEFAULT; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -338,33 +364,58 @@ ALTER TABLE ONLY articles ALTER COLUMN id SET DEFAULT nextval('articles_id_seq':
|
||||
SET search_path = "1", pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2268 (class 0 OID 309041)
|
||||
-- Dependencies: 179
|
||||
-- TOC entry 2279 (class 0 OID 281006)
|
||||
-- Dependencies: 186
|
||||
-- Data for Name: authors_only; Type: TABLE DATA; Schema: 1; Owner: dbapi_test_author
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2268 (class 0 OID 280937)
|
||||
-- Dependencies: 175
|
||||
-- TOC entry 2016 (class 0 OID 50932)
|
||||
-- Dependencies: 181
|
||||
-- Data for Name: auto_incrementing_pk; Type: TABLE DATA; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2300 (class 0 OID 0)
|
||||
-- Dependencies: 180
|
||||
-- TOC entry 2270 (class 0 OID 280946)
|
||||
-- Dependencies: 177
|
||||
-- TOC entry 2051 (class 0 OID 0)
|
||||
-- Dependencies: 182
|
||||
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE SET; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('auto_incrementing_pk_id_seq', 46, true);
|
||||
SELECT pg_catalog.setval('auto_incrementing_pk_id_seq', 50, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2270 (class 0 OID 309050)
|
||||
-- Dependencies: 181
|
||||
-- TOC entry 2018 (class 0 OID 50941)
|
||||
-- Dependencies: 183
|
||||
-- Data for Name: compound_pk; Type: TABLE DATA; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2271 (class 0 OID 309053)
|
||||
-- Dependencies: 182
|
||||
-- TOC entry 2271 (class 0 OID 280949)
|
||||
-- Dependencies: 178
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2052 (class 0 OID 0)
|
||||
-- Dependencies: 185
|
||||
-- Name: has_fk_id_seq; Type: SEQUENCE SET; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('has_fk_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2021 (class 0 OID 50949)
|
||||
-- Dependencies: 186
|
||||
-- Data for Name: items; Type: TABLE DATA; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -386,8 +437,6 @@ INSERT INTO items (id) VALUES (15);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2301 (class 0 OID 0)
|
||||
-- Dependencies: 183
|
||||
-- Name: items_id_seq; Type: SEQUENCE SET; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -395,25 +444,17 @@ SELECT pg_catalog.setval('items_id_seq', 15, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2273 (class 0 OID 309058)
|
||||
-- Dependencies: 184
|
||||
-- Data for Name: menagerie; Type: TABLE DATA; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2274 (class 0 OID 309064)
|
||||
-- Dependencies: 185
|
||||
-- Data for Name: no_pk; Type: TABLE DATA; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2275 (class 0 OID 309070)
|
||||
-- Dependencies: 186
|
||||
-- Data for Name: simple_pk; Type: TABLE DATA; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
|
||||
@@ -421,8 +462,6 @@ SELECT pg_catalog.setval('items_id_seq', 15, true);
|
||||
SET search_path = dbapi, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2276 (class 0 OID 309076)
|
||||
-- Dependencies: 187
|
||||
-- Data for Name: auth; Type: TABLE DATA; Schema: dbapi; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -431,16 +470,11 @@ SET search_path = dbapi, pg_catalog;
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2277 (class 0 OID 309082)
|
||||
-- Dependencies: 188
|
||||
-- Data for Name: articles; Type: TABLE DATA; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2302 (class 0 OID 0)
|
||||
-- Dependencies: 189
|
||||
-- Name: articles_id_seq; Type: SEQUENCE SET; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -450,8 +484,15 @@ SELECT pg_catalog.setval('articles_id_seq', 1, false);
|
||||
SET search_path = "1", pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2146 (class 2606 OID 309094)
|
||||
-- Name: auto_incrementing_pk_pkey; Type: CONSTRAINT; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
-- Name: authors_only_pkey; Type: CONSTRAINT; Schema: 1; Owner: dbapi_test_author; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY authors_only
|
||||
ADD CONSTRAINT authors_only_pkey PRIMARY KEY (secret);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2144 (class 2606 OID 280990)
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY auto_incrementing_pk
|
||||
@@ -459,7 +500,6 @@ ALTER TABLE ONLY auto_incrementing_pk
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2148 (class 2606 OID 309096)
|
||||
-- Name: compound_pk_pkey; Type: CONSTRAINT; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -468,8 +508,7 @@ ALTER TABLE ONLY compound_pk
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2154 (class 2606 OID 309098)
|
||||
-- Name: contacts_pkey; Type: CONSTRAINT; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
-- TOC entry 1900 (class 2606 OID 50995)
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY simple_pk
|
||||
@@ -477,8 +516,14 @@ ALTER TABLE ONLY simple_pk
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2150 (class 2606 OID 309100)
|
||||
-- Name: items_pkey; Type: CONSTRAINT; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY has_fk
|
||||
ADD CONSTRAINT has_fk_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 1896 (class 2606 OID 50999)
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY items
|
||||
@@ -486,8 +531,6 @@ ALTER TABLE ONLY items
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2152 (class 2606 OID 309102)
|
||||
-- Name: menagerie_pkey; Type: CONSTRAINT; Schema: 1; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY menagerie
|
||||
@@ -497,7 +540,6 @@ ALTER TABLE ONLY menagerie
|
||||
SET search_path = dbapi, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2156 (class 2606 OID 309104)
|
||||
-- Name: auth_pkey; Type: CONSTRAINT; Schema: dbapi; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
@@ -508,8 +550,6 @@ ALTER TABLE ONLY auth
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2158 (class 2606 OID 309106)
|
||||
-- Name: articles_pkey; Type: CONSTRAINT; Schema: private; Owner: dbapi_test; Tablespace:
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY articles
|
||||
@@ -519,7 +559,6 @@ ALTER TABLE ONLY articles
|
||||
SET search_path = dbapi, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2159 (class 2620 OID 309108)
|
||||
-- Name: ensure_auth_role_exists; Type: TRIGGER; Schema: dbapi; Owner: dbapi_test
|
||||
--
|
||||
|
||||
@@ -529,117 +568,104 @@ CREATE CONSTRAINT TRIGGER ensure_auth_role_exists AFTER INSERT OR UPDATE ON auth
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2160 (class 2620 OID 309109)
|
||||
-- Name: articles_owner_track; Type: TRIGGER; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
CREATE TRIGGER articles_owner_track BEFORE INSERT OR UPDATE ON articles FOR EACH ROW EXECUTE PROCEDURE dbapi.update_owner();
|
||||
|
||||
|
||||
SET search_path = "1", pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2284 (class 0 OID 0)
|
||||
-- Dependencies: 10
|
||||
-- Name: 1; Type: ACL; Schema: -; Owner: dbapi_test
|
||||
-- TOC entry 1905 (class 2606 OID 51009)
|
||||
-- Name: has_fk_fk_fkey; Type: FK CONSTRAINT; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY has_fk
|
||||
ADD CONSTRAINT has_fk_fk_fkey FOREIGN KEY (auto_inc_fk) REFERENCES auto_incrementing_pk(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 1906 (class 2606 OID 51015)
|
||||
-- Name: has_fk_simple_fk_fkey; Type: FK CONSTRAINT; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY has_fk
|
||||
ADD CONSTRAINT has_fk_simple_fk_fkey FOREIGN KEY (simple_fk) REFERENCES simple_pk(k);
|
||||
|
||||
|
||||
|
||||
REVOKE ALL ON SCHEMA "1" FROM dbapi_test;
|
||||
GRANT ALL ON SCHEMA "1" TO dbapi_test;
|
||||
GRANT USAGE ON SCHEMA "1" TO dbapi_anonymous;
|
||||
|
||||
|
||||
SET search_path = "1", pg_catalog;
|
||||
--
|
||||
-- TOC entry 2036 (class 0 OID 0)
|
||||
-- Dependencies: 15
|
||||
-- Name: public; Type: ACL; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
REVOKE ALL ON SCHEMA public FROM PUBLIC;
|
||||
REVOKE ALL ON SCHEMA public FROM postgres;
|
||||
GRANT ALL ON SCHEMA public TO postgres;
|
||||
GRANT ALL ON SCHEMA public TO PUBLIC;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2288 (class 0 OID 0)
|
||||
-- Dependencies: 179
|
||||
|
||||
REVOKE ALL ON TABLE authors_only FROM dbapi_test_author;
|
||||
GRANT ALL ON TABLE authors_only TO dbapi_test_author;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2290 (class 0 OID 0)
|
||||
-- Dependencies: 175
|
||||
-- Name: auto_incrementing_pk; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE auto_incrementing_pk FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE auto_incrementing_pk FROM dbapi_test;
|
||||
GRANT ALL ON TABLE auto_incrementing_pk TO dbapi_test;
|
||||
GRANT ALL ON TABLE auto_incrementing_pk TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2290 (class 0 OID 0)
|
||||
-- Dependencies: 180
|
||||
-- Name: auto_incrementing_pk_id_seq; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON SEQUENCE auto_incrementing_pk_id_seq FROM PUBLIC;
|
||||
REVOKE ALL ON SEQUENCE auto_incrementing_pk_id_seq FROM dbapi_test;
|
||||
GRANT ALL ON SEQUENCE auto_incrementing_pk_id_seq TO dbapi_test;
|
||||
GRANT USAGE ON SEQUENCE auto_incrementing_pk_id_seq TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2291 (class 0 OID 0)
|
||||
-- Dependencies: 181
|
||||
-- Name: compound_pk; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE compound_pk FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE compound_pk FROM dbapi_test;
|
||||
GRANT ALL ON TABLE compound_pk TO dbapi_test;
|
||||
GRANT ALL ON TABLE compound_pk TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2292 (class 0 OID 0)
|
||||
-- Dependencies: 182
|
||||
-- Name: items; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE items FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE items FROM dbapi_test;
|
||||
GRANT ALL ON TABLE items TO dbapi_test;
|
||||
GRANT ALL ON TABLE items TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2294 (class 0 OID 0)
|
||||
-- Dependencies: 183
|
||||
-- Name: items_id_seq; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON SEQUENCE items_id_seq FROM PUBLIC;
|
||||
REVOKE ALL ON SEQUENCE items_id_seq FROM dbapi_test;
|
||||
GRANT ALL ON SEQUENCE items_id_seq TO dbapi_test;
|
||||
GRANT USAGE ON SEQUENCE items_id_seq TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2295 (class 0 OID 0)
|
||||
-- Dependencies: 184
|
||||
-- Name: menagerie; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE menagerie FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE menagerie FROM dbapi_test;
|
||||
GRANT ALL ON TABLE menagerie TO dbapi_test;
|
||||
GRANT ALL ON TABLE menagerie TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2296 (class 0 OID 0)
|
||||
-- Dependencies: 185
|
||||
-- Name: no_pk; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE no_pk FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE no_pk FROM dbapi_test;
|
||||
GRANT ALL ON TABLE no_pk TO dbapi_test;
|
||||
GRANT ALL ON TABLE no_pk TO dbapi_anonymous;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2297 (class 0 OID 0)
|
||||
-- Dependencies: 186
|
||||
-- Name: simple_pk; Type: ACL; Schema: 1; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE simple_pk FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE simple_pk FROM dbapi_test;
|
||||
GRANT ALL ON TABLE simple_pk TO dbapi_test;
|
||||
GRANT ALL ON TABLE simple_pk TO dbapi_anonymous;
|
||||
@@ -647,20 +673,8 @@ GRANT ALL ON TABLE simple_pk TO dbapi_anonymous;
|
||||
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
--
|
||||
-- TOC entry 2298 (class 0 OID 0)
|
||||
-- Dependencies: 188
|
||||
-- Name: articles; Type: ACL; Schema: private; Owner: dbapi_test
|
||||
--
|
||||
|
||||
REVOKE ALL ON TABLE articles FROM PUBLIC;
|
||||
REVOKE ALL ON TABLE articles FROM dbapi_test;
|
||||
GRANT ALL ON TABLE articles TO dbapi_test;
|
||||
|
||||
|
||||
-- Completed on 2014-10-07 15:55:44 PDT
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user