]> gitweb.factorcode.org Git - factor.git/commitdiff
Change postgresql test database to prepend the cpu string so that running two builder...
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 4 Sep 2011 21:52:44 +0000 (16:52 -0500)
committererg <erg@ubuntu.(none)>
Wed, 7 Sep 2011 00:51:46 +0000 (17:51 -0700)
basis/db/errors/errors.factor
basis/db/errors/postgresql/postgresql.factor
basis/db/postgresql/postgresql-tests.factor
basis/db/queries/queries.factor
basis/db/tester/tester.factor

index 23dae627ac11db09e672ed610c72553a3c465823..88dc755b0adfb7de643d6ba740e5537b006dfbe3 100644 (file)
@@ -38,6 +38,11 @@ TUPLE: sql-function-missing < sql-error message ;
     \ sql-function-missing new
         swap >>message ;
 
+TUPLE: sql-database-exists < sql-error message ;
+: <sql-database-exists> ( message -- error )
+    \ sql-database-exists new
+        swap >>message ;
+
 : ignore-error ( quot word -- )
     '[ dup _ execute [ drop ] [ rethrow ] if ] recover ; inline
 
@@ -52,3 +57,6 @@ TUPLE: sql-function-missing < sql-error message ;
 
 : ignore-function-missing ( quot -- )
     \ sql-function-missing? ignore-error ; inline
+
+: ignore-database-exists ( quot -- )
+    \ sql-database-exists? ignore-error ; inline
index 9f64a278738bd7b4045290cada917557f1ef982c..1a866f52bf5c14be4519c1940eb76a3b376a935c 100644 (file)
@@ -15,6 +15,10 @@ TableError =
     | Error ("relation "|"table ")(!(" does not exist").)+:table " does not exist"
         => [[ table >string unquote <sql-table-missing> ]]
 
+DatabaseError =
+    Error ("database")(!(" already exists").)+:database " already exists"
+        => [[ database >string <sql-database-exists> ]]
+
 FunctionError =
     Error "function" (!(" already exists").)+:table " already exists"
         => [[ table >string <sql-function-exists> ]]
@@ -29,7 +33,7 @@ SyntaxError =
 
 UnknownError = .* => [[ >string <sql-unknown-error> ]]
 
-PostgresqlSqlError = (TableError | FunctionError | SyntaxError | UnknownError) 
+PostgresqlSqlError = (TableError | DatabaseError | FunctionError | SyntaxError | UnknownError) 
 
 ;EBNF
 
index 266337b8c8fbf0f9b85ff0cb8752d6cfd18b3064..eb1370fc748c1cac655085892b58667e4688e56c 100644 (file)
@@ -3,7 +3,9 @@ prettyprint sequences namespaces tools.test db db.private
 db.tuples db.types unicode.case accessors system db.tester ;
 IN: db.postgresql.tests
 
+
 os windows? cpu x86.64? and [
+    ! Ensure the table exists
     [ ] [ postgresql-test-db [ ] with-db ] unit-test
 
     [ ] [
index 3ff93f49c67f42f461159c6446fa7b6c91f36453..118ac73c3e38920c3e25929a91b1ef7134ae3f72 100644 (file)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel math namespaces make sequences random
-strings math.parser math.intervals combinators math.bitwise
-nmake db db.tuples db.types classes words shuffle arrays
-destructors continuations db.tuples.private prettyprint
-db.private byte-arrays ;
+USING: accessors arrays byte-arrays classes combinators
+continuations db db.errors db.private db.tuples
+db.tuples.private db.types destructors kernel make math
+math.bitwise math.intervals math.parser namespaces nmake
+prettyprint random sequences shuffle strings words fry ;
 IN: db.queries
 
 GENERIC: where ( specs obj -- )
@@ -208,3 +208,9 @@ M: db-connection <count-statement> ( query -- statement )
 
 : drop-index ( index-name -- )
     [ "drop index " % % ] "" make sql-command ;
+
+: create-database ( string -- )
+    "create database " ";" surround sql-command ;
+
+: ensure-database ( string -- )
+    '[ _ create-database ] ignore-database-exists ;
index d0ea6cbcf12eee933beefc083c1c12fa8664e67a..d885f6f01655c0c4d5e4590b47731c4eaf54363a 100644 (file)
@@ -3,20 +3,30 @@
 USING: concurrency.combinators db.pools db.sqlite db.tuples
 db.types kernel math random threads tools.test db sequences
 io prettyprint db.postgresql accessors io.files.temp
-namespaces fry system math.parser ;
+namespaces fry system math.parser db.queries assocs ;
 IN: db.tester
 
+: postgresql-test-db-name ( -- string )
+    cpu name>> "-" "factor-test" 3append
+    H{ { CHAR: - CHAR: _ } { CHAR: . CHAR: _ } } substitute ;
+
 : postgresql-test-db ( -- postgresql-db )
     <postgresql-db>
         "localhost" >>host
         "postgres" >>username
         "thepasswordistrust" >>password
-        "factor-test" >>database ;
+        postgresql-test-db-name >>database ;
+
+: postgresql-template1-db ( -- postgresql-db )
+    <postgresql-db>
+        "localhost" >>host
+        "postgres" >>username
+        "thepasswordistrust" >>password
+        "template1" >>database ;
 
 : sqlite-test-db ( -- sqlite-db )
     "tuples-test.db" temp-file <sqlite-db> ;
 
-
 ! These words leak resources, but are useful for interactivel testing
 : set-sqlite-db ( -- )
     sqlite-db db-open db-connection set ;
@@ -31,6 +41,10 @@ IN: db.tester
     ] call ; inline
 
 : test-postgresql ( quot -- )
+    postgresql-template1-db [
+        postgresql-test-db-name ensure-database
+    ] with-db
+
     '[
         os windows? cpu x86.64? and [
             [ ] [ postgresql-test-db _ with-db ] unit-test