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 Fri, 26 Jun 2015 22:40:41 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/1e381e6b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/tree/1e381e6b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/diff/1e381e6b

Branch: refs/heads/add-manual-migration-logic
Commit: 1e381e6b7e8384a2f5ce53c802214957d5da04cb
Parents: d84fc55
Author: Russell Branca <chewbranca@apache.org>
Authored: Fri Jun 26 22:17:01 2015 +0000
Committer: Russell Branca <chewbranca@apache.org>
Committed: Fri Jun 26 22:31:06 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/1e381e6b/src/cassim.erl
----------------------------------------------------------------------
diff --git a/src/cassim.erl b/src/cassim.erl
index 2cede38..7c5a0f2 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/1e381e6b/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