[base + modules] Issue #670 - Remove side effects in manage_schema functions#671
[base + modules] Issue #670 - Remove side effects in manage_schema functions#671robvandenbogaard wants to merge 2 commits intomasterfrom
Conversation
|
ping @mworrell |
| ] | ||
| }, | ||
| z_datamodel:manage(?MODULE, Datamodel, Context), | ||
| schema:create_identity_if_not_exists(editor_dev, "redacteur", "redacteur", Context). |
There was a problem hiding this comment.
Proposal to remove the automatic creation of editor_dev. If we need one we should provide it in fixtures.
There was a problem hiding this comment.
There is also an manage_data/2 function. That is called after the manage_schema/2 has been handled.
See https://test.zotonic.com/page/1353/modules
manage_data(_Version, Context) ->
%% Whatever data needs to be installed after the datamodel
%% has been installed.
ok.There was a problem hiding this comment.
Good point, thanks.
There was a problem hiding this comment.
BTW schema is a dangerous name for a module. I can imagine that other projects will also try to use this generic name. Better prefix it with ginger_, as it is a Ginger-only module.
There was a problem hiding this comment.
Yes, I completely agree, that struck me too.
| ] | ||
| }, | ||
| z_datamodel:manage(?MODULE, Datamodel, Context), | ||
| schema:create_identity_if_not_exists(editor_dev, "redacteur", "redacteur", Context). |
There was a problem hiding this comment.
It went nowhere, as I think it is not used / we should not use it (here) and rethink it when we need it.
There was a problem hiding this comment.
Use manage_data/2, it is called after manage_schema/2
manage_data(_Version, Context) ->
%% Whatever data needs to be installed after the datamodel
%% has been installed.
ok.| @@ -14,12 +14,11 @@ | |||
| ]). | |||
|
|
|||
| manage_schema(_Version, Context) -> | |||
There was a problem hiding this comment.
Context -> _Context (unused)
| @@ -21,7 +21,7 @@ | |||
| -include("zotonic.hrl"). | |||
|
|
|||
| manage_schema(_Version, Context) -> | |||
There was a problem hiding this comment.
Context -> _Context (unused)
|
|
||
| manage_schema(install, Context) -> | ||
| Datamodel = #datamodel{ | ||
| #datamodel{ |
There was a problem hiding this comment.
Context -> _Context (unused)
| @@ -19,18 +19,20 @@ | |||
| ]). | |||
|
|
|||
| manage_schema(install, Context) -> | |||
There was a problem hiding this comment.
Version is install?
Context -> _Context (unused)
There was a problem hiding this comment.
Version type signature is:
-type manage_schema() :: install
| {upgrade, integer()}.
| ] | ||
| }, | ||
| z_datamodel:manage(?MODULE, Datamodel, Context), | ||
| schema:create_identity_if_not_exists(editor_dev, "redacteur", "redacteur", Context). |
| z_datamodel:manage(?MODULE, Datamodel, Context), | ||
|
|
||
| %% TODO: Legacy code ahead! This function must not have side effects; | ||
| %% it should only return the data model. |
There was a problem hiding this comment.
We should look into this case to see if it is still necessary to keep this here, or if it could be in a better place.
There was a problem hiding this comment.
Use manage_data/2 to update/install data after the schema has been installed.
From #670