You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2016/05/18 14:47:03 UTC
[1/2] couch commit: updated refs/heads/master to 514a447
Repository: couchdb-couch
Updated Branches:
refs/heads/master 23f188096 -> 514a44775
Support create_if_missing option in couch_db:open
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/9c349b9b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/9c349b9b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/9c349b9b
Branch: refs/heads/master
Commit: 9c349b9b18456bc75486defb87b205c38da4a05d
Parents: 23f1880
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue May 17 16:44:13 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue May 17 16:44:13 2016 -0700
----------------------------------------------------------------------
src/couch_server.erl | 4 ++++
test/couch_db_tests.erl | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9c349b9b/src/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_server.erl b/src/couch_server.erl
index b9a5077..2634bbf 100644
--- a/src/couch_server.erl
+++ b/src/couch_server.erl
@@ -81,10 +81,14 @@ open(DbName, Options0) ->
{ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
_ ->
Timeout = couch_util:get_value(timeout, Options, infinity),
+ Create = couch_util:get_value(create_if_missing, Options, false),
case gen_server:call(couch_server, {open, DbName, Options}, Timeout) of
{ok, #db{fd=Fd} = Db} ->
update_lru(DbName, Options),
{ok, Db#db{user_ctx=Ctx, fd_monitor=erlang:monitor(process,Fd)}};
+ {not_found, no_db_file} when Create ->
+ couch_log:warning("creating missing database: ~s", [DbName]),
+ couch_server:create(DbName, Options);
Error ->
Error
end
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9c349b9b/test/couch_db_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_db_tests.erl b/test/couch_db_tests.erl
index f614102..c57a0d4 100644
--- a/test/couch_db_tests.erl
+++ b/test/couch_db_tests.erl
@@ -39,6 +39,18 @@ create_delete_db_test_()->
}
}.
+open_db_test_()->
+ {
+ "Database open tests",
+ {
+ setup,
+ fun setup/0, fun test_util:stop_couch/1,
+ fun(_) ->
+ [should_create_db_if_missing()]
+ end
+ }
+ }.
+
should_create_db() ->
DbName = ?tempdb(),
@@ -98,6 +110,13 @@ should_create_delete_database_continuously() ->
?_assert(loop(DbName, N))}}
|| N <- [10, 100]].
+should_create_db_if_missing() ->
+ DbName = ?tempdb(),
+ {ok, Db} = couch_db:open(DbName, [{create_if_missing, true}]),
+ ok = couch_db:close(Db),
+ {ok, AllDbs} = couch_server:all_databases(),
+ ?_assert(lists:member(DbName, AllDbs)).
+
loop(_, 0) ->
true;
loop(DbName, N) ->
[2/2] couch commit: updated refs/heads/master to 514a447
Posted by ii...@apache.org.
Merge remote branch 'cloudant:create_db_if_missing'
This closes #174
Signed-off-by: ILYA Khlopotov <ii...@ca.ibm.com>
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/514a4477
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/514a4477
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/514a4477
Branch: refs/heads/master
Commit: 514a447751440ba230e04ea680f446e72e7f04cd
Parents: 23f1880 9c349b9
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed May 18 07:46:46 2016 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed May 18 07:46:46 2016 -0700
----------------------------------------------------------------------
src/couch_server.erl | 4 ++++
test/couch_db_tests.erl | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
----------------------------------------------------------------------