Use version number for schema in tests like anticipated use case

This commit is contained in:
Joe Nelson
2014-08-14 13:23:41 -07:00
parent 2da4451110
commit e9c232976e
3 changed files with 28 additions and 30 deletions
+2 -2
View File
@@ -4,7 +4,7 @@
module PgQuery where
import Data.Text (Text)
import Data.Text (Text, pack)
import Data.Functor ( (<$>) )
import Data.Maybe (fromMaybe)
import Data.List (intersperse, intercalate)
@@ -106,7 +106,7 @@ jsonArrayRows q =
insert :: Int -> Text -> SqlRow -> Connection -> IO BL.ByteString
insert schema table row conn = do
query <- populateSql conn ("insert into %I.%I ("++colIds++")", map toSql $ (show schema):table:cols)
query <- populateSql conn ("insert into %I.%I ("++colIds++")", map toSql $ (pack . show $ schema):table:cols)
stmt <- prepare conn (query ++ " values ("++phs++") returning *")
_ <- execute stmt values
commit conn
@@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
module PgQuerySpec where
module Unit.PgQuerySpec where
import Test.Hspec
@@ -14,8 +14,7 @@ loadFixture :: String -> IO Connection
loadFixture name = do
conn <- connectPostgreSQL "postgres://postgres:@localhost:5432/dbapi_test"
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
runRaw conn "drop schema if exists public cascade"
runRaw conn "create schema public"
runRaw conn "drop schema if exists \"1\" cascade"
runRaw conn sql
return conn
@@ -26,7 +25,7 @@ spec :: Spec
spec = beforeAll (loadFixture "schema") $ do
describe "insert" $
it "can insert into an empty table" $ \conn -> do
_ <- insert "public" "auto_incrementing_pk" (SqlRow [
_ <- insert 1 "auto_incrementing_pk" (SqlRow [
("non_nullable_string", toSql ("a string that isn't null" :: String))
]) conn
r <- quickQuery conn "select count(1) from auto_incrementing_pk" []
+23 -24
View File
@@ -4,7 +4,7 @@
-- Dumped from database version 9.3.4
-- Dumped by pg_dump version 9.3.1
-- Started on 2014-08-10 15:29:43 PDT
-- Started on 2014-08-14 13:19:39 PDT
SET statement_timeout = 0;
SET lock_timeout = 0;
@@ -13,6 +13,14 @@ SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- TOC entry 6 (class 2615 OID 226754)
-- Name: 1; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA "1";
--
-- TOC entry 172 (class 3079 OID 12018)
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
@@ -22,7 +30,7 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- TOC entry 2209 (class 0 OID 0)
-- TOC entry 2206 (class 0 OID 0)
-- Dependencies: 172
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
@@ -30,15 +38,15 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
SET search_path = "1", pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 171 (class 1259 OID 226379)
-- Name: auto_incrementing_pk; Type: TABLE; Schema: public; Owner: -; Tablespace:
-- TOC entry 170 (class 1259 OID 226755)
-- Name: auto_incrementing_pk; Type: TABLE; Schema: 1; Owner: -; Tablespace:
--
CREATE TABLE auto_incrementing_pk (
@@ -50,8 +58,8 @@ CREATE TABLE auto_incrementing_pk (
--
-- TOC entry 170 (class 1259 OID 226377)
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE; Schema: public; Owner: -
-- TOC entry 171 (class 1259 OID 226762)
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE; Schema: 1; Owner: -
--
CREATE SEQUENCE auto_incrementing_pk_id_seq
@@ -63,41 +71,32 @@ CREATE SEQUENCE auto_incrementing_pk_id_seq
--
-- TOC entry 2210 (class 0 OID 0)
-- Dependencies: 170
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
-- TOC entry 2207 (class 0 OID 0)
-- Dependencies: 171
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: 1; Owner: -
--
ALTER SEQUENCE auto_incrementing_pk_id_seq OWNED BY auto_incrementing_pk.id;
--
-- TOC entry 2090 (class 2604 OID 226382)
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
-- TOC entry 2091 (class 2604 OID 226764)
-- Name: id; Type: DEFAULT; Schema: 1; Owner: -
--
ALTER TABLE ONLY auto_incrementing_pk ALTER COLUMN id SET DEFAULT nextval('auto_incrementing_pk_id_seq'::regclass);
--
-- TOC entry 2211 (class 0 OID 0)
-- Dependencies: 170
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('auto_incrementing_pk_id_seq', 1, true);
--
-- TOC entry 2093 (class 2606 OID 226388)
-- Name: auto_incrementing_pk_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
-- TOC entry 2093 (class 2606 OID 226766)
-- Name: auto_incrementing_pk_pkey; Type: CONSTRAINT; Schema: 1; Owner: -; Tablespace:
--
ALTER TABLE ONLY auto_incrementing_pk
ADD CONSTRAINT auto_incrementing_pk_pkey PRIMARY KEY (id);
-- Completed on 2014-08-10 15:29:43 PDT
-- Completed on 2014-08-14 13:19:39 PDT
--
-- PostgreSQL database dump complete