anchor.diff:  validate_app(App) when is_record(App, app) -> validate_app(record_info(fields, app), App).
   validate_app([], App) ->  App;
   
  -% Validate the branch
  -validate_app([branch|Rest], #app{branch = undefined} = App) -> validate_app(Rest, App#app{branch = "master"});
  -validate_app([branch|Rest], #app{branch = _V} = App) -> validate_app(Rest, App);
  -% Validate the url
  -validate_app([url|Rest], #app{url = _Url} = App) -> validate_app(Rest, App);
  -% Validate the type, it can only be either static or dynamic
  -validate_app([vcs_type|Rest], #app{vcs_type = git} = App) -> validate_app(Rest, App);
  -validate_app([vcs_type|Rest], #app{vcs_type = _Else} = App) -> validate_app(Rest, App#app{vcs_type = git});
  -% Validate the timeout
  -validate_app([timeout|Rest], #app{timeout = undefined} = App) -> validate_app(Rest, App#app{timeout = 10*1000});
  -validate_app([timeout|Rest], #app{timeout = V} = App) -> validate_app(Rest, App#app{timeout = misc_utils:to_integer(V)*1000});
  -% Validate the sticky parameter
  -validate_app([sticky|Rest], #app{sticky = "true"} = App) -> validate_app(Rest, App#app{sticky = true});
  -validate_app([sticky|Rest], #app{sticky = _Else} = App) -> validate_app(Rest, App#app{sticky = false});
  -% Validate min/max instances
  -validate_app([min_instances|Rest], #app{min_instances = undefined} = App) -> validate_app(Rest, App#app{min_instances = 1});
  -validate_app([min_instances|Rest], #app{min_instances = V} = App) -> validate_app(Rest, App#app{min_instances = misc_utils:to_integer(V)});
  -validate_app([max_instances|Rest], #app{max_instances = undefined} = App) -> validate_app(Rest, App#app{max_instances = 1});
  -validate_app([max_instances|Rest], #app{max_instances = V} = App) -> validate_app(Rest, App#app{max_instances = misc_utils:to_integer(V)});
  -% Validate the template
  -validate_app([template|Rest], #app{template = undefined} = App) -> validate_app(Rest, App#app{template = default});
  -validate_app([template|Rest], #app{template = Val} = App) -> validate_app(Rest, App#app{template = misc_utils:to_atom(Val)});
  -% Validate the routing parameter
  -validate_app([routing_param|Rest], #app{routing_param = undefined} = App) -> validate_app(Rest, App#app{routing_param = 'Host'});
  -validate_app([routing_param|Rest], #app{routing_param = V} = App) -> validate_app(Rest, App#app{routing_param = misc_utils:to_atom(V)});
  -% Validate others?
  +%% Validate the branch
  +validate_app([branch|Rest], #app{branch = undefined} = App) ->
  +  validate_app(Rest, App#app{branch = "master"});
  +validate_app([branch|Rest], #app{branch = _V} = App) ->
  +  validate_app(Rest, App);
  +%% Validate the url
  +validate_app([url|Rest], #app{url = _Url} = App) ->
  +  validate_app(Rest, App);
  +%% Validate the type, it can only be either static or dynamic
  +validate_app([vcs_type|Rest], #app{vcs_type = git} = App) ->
  +  validate_app(Rest, App);
  +validate_app([vcs_type|Rest], #app{vcs_type = _Else} = App) ->
  +  validate_app(Rest, App#app{vcs_type = git});
  +%% Validate the timeout
  +validate_app([timeout|Rest], #app{timeout = undefined} = App) ->
  +  validate_app(Rest, App#app{timeout = 10*1000});
  +validate_app([timeout|Rest], #app{timeout = V} = App) ->
  +  validate_app(Rest, App#app{timeout = misc_utils:to_integer(V)*1000});
  +%% Validate the sticky parameter
  +validate_app([sticky|Rest], #app{sticky = "true"} = App) ->
  +  validate_app(Rest, App#app{sticky = true});
  +validate_app([sticky|Rest], #app{sticky = _Else} = App) ->
  +  validate_app(Rest, App#app{sticky = false});
  +%% Validate min/max instances
  +validate_app([min_instances|Rest], #app{min_instances = undefined} = App) ->
  +  validate_app(Rest, App#app{min_instances = 1});
  +validate_app([min_instances|Rest], #app{min_instances = V} = App) ->
  +  validate_app(Rest, App#app{min_instances = misc_utils:to_integer(V)});
  +validate_app([max_instances|Rest], #app{max_instances = undefined} = App) ->
  +  validate_app(Rest, App#app{max_instances = 1});
  +validate_app([max_instances|Rest], #app{max_instances = V} = App) ->
  +  validate_app(Rest, App#app{max_instances = misc_utils:to_integer(V)});
  +%% Validate the template
  +validate_app([template|Rest], #app{template = undefined} = App) ->
  +  validate_app(Rest, App#app{template = default});
  +validate_app([template|Rest], #app{template = Val} = App) ->
  +  validate_app(Rest, App#app{template = misc_utils:to_atom(Val)});
  +%% Validate the routing parameter
  +validate_app([routing_param|Rest], #app{routing_param = undefined} = App) ->
  +  validate_app(Rest, App#app{routing_param = 'Host'});
  +validate_app([routing_param|Rest], #app{routing_param = V} = App) ->
  +  validate_app(Rest, App#app{routing_param = misc_utils:to_atom(V)});
  +%% Validate others?
   validate_app([_H|Rest], App) -> validate_app(Rest, App).
   
   
  
positive.code: -include ("beehive.hrl").
  -include ("common.hrl").
  
  % DATABASE STUFF
  -export ([
    create/1,
    read/1,
    save/1,
    update/2,
    delete/1,
    find_by_name/1,
    find_all_by_name/1,
    exist/1,
    all/0
  ]).
  
  -export ([
    new/1,
    update_by_name/1,
    restart_by_name/1,
    expand_by_name/1
  ]).
  
  % APPLICATION STUFF
  -export ([
    to_proplist/1,
    build_app_env/2
  ]).
  
  -define (DB, beehive_db_srv).
  
  
negative.code:     [N] -> App#app{name = generate_unique_name(N, 5)};
      [A,B] -> App#app{name = generate_unique_name(A, 5), branch = B}
    end.
  
  %%-------------------------------------------------------------------
  %% @spec (Name) ->    {ok, Value}
  %% @doc Generate a unique name based on a given name
  