couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [2/3] couchdb-cassim git commit: Add manual security doc migration logic
Date Tue, 21 Jul 2015 20:47:33 GMT
Add manual security doc migration logic


Project: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/commit/14c66b8d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/tree/14c66b8d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/diff/14c66b8d

Branch: refs/heads/add-manual-migration-logic
Commit: 14c66b8dbee64a34725e1a93937e5494ec383164
Parents: e2ad37a
Author: Russell Branca <chewbranca@apache.org>
Authored: Fri Jun 26 22:17:01 2015 +0000
Committer: Russell Branca <chewbranca@apache.org>
Committed: Tue Jul 21 20:45:41 2015 +0000

----------------------------------------------------------------------
 src/cassim.erl                | 33 +++++++++++++++++++++++++++++++++
 src/cassim_metadata_cache.erl |  3 ++-
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-cassim/blob/14c66b8d/src/cassim.erl
----------------------------------------------------------------------
diff --git a/src/cassim.erl b/src/cassim.erl
index 3af0096..65d942c 100644
--- a/src/cassim.erl
+++ b/src/cassim.erl
@@ -37,6 +37,11 @@
     set_security/3
 ]).
 
+-export([
+    migrate_database/1,
+    migrate_databases/0
+]).
+
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -95,3 +100,31 @@ set_security(DbName, SecObj) ->
 
 set_security(DbName, SecObj, Options) ->
     cassim_security:set_security(DbName, SecObj, Options).
+
+
+migrate_databases() ->
+    {ok, Dbs} = fabric:all_dbs(),
+    lists:foldl(
+        fun(DbName, Errors) ->
+            try
+                MetaId = cassim_metadata_cache:security_meta_id(DbName),
+                case cassim_metadata_cache:fetch_cached_meta(MetaId) of
+                    undefined ->
+                        ok = migrate_database(DbName);
+                    _ ->
+                        ok
+                end,
+                Errors
+            catch Error:Reason ->
+                [{DbName, Error, Reason} | Errors]
+            end
+        end,
+        [],
+        Dbs
+    ).
+
+
+migrate_database(DbName) ->
+    SecProps = fabric:get_security(DbName),
+    {ok, _Props} = cassim_security:migrate_security_props(DbName, SecProps),
+    ok.

http://git-wip-us.apache.org/repos/asf/couchdb-cassim/blob/14c66b8d/src/cassim_metadata_cache.erl
----------------------------------------------------------------------
diff --git a/src/cassim_metadata_cache.erl b/src/cassim_metadata_cache.erl
index 002ee43..35b5dad 100644
--- a/src/cassim_metadata_cache.erl
+++ b/src/cassim_metadata_cache.erl
@@ -31,6 +31,7 @@
     load_meta/1,
     load_meta/2,
     load_meta/3,
+    fetch_cached_meta/1,
     metadata_db/0,
     metadata_db_exists/0,
     cleanup_old_docs/1
@@ -211,7 +212,7 @@ load_meta_from_db(DbName, MetaId) ->
             {error, timeout};
         Resp ->
             couch_log:notice(
-                "unexpected response retrieving metadata doc [~s/]~s: ~s",
+                "unexpected response retrieving metadata doc [~s/]~s: ~p",
                 [DbName, MetaId, Resp]),
             {error, Resp}
      end.


Mime
View raw message