-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[base + modules] Issue #670 - Remove side effects in manage_schema functions #671
base: master
Are you sure you want to change the base?
Conversation
ping @mworrell |
@@ -168,9 +168,7 @@ manage_schema(_Version, Context) -> | |||
]} | |||
]} | |||
] | |||
}, | |||
z_datamodel:manage(?MODULE, Datamodel, Context), | |||
schema:create_identity_if_not_exists(editor_dev, "redacteur", "redacteur", Context). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've never used it, maybe @loetie has
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I completely agree, that struck me too.
@@ -168,9 +168,7 @@ manage_schema(_Version, Context) -> | |||
]} | |||
]} | |||
] | |||
}, | |||
z_datamodel:manage(?MODULE, Datamodel, Context), | |||
schema:create_identity_if_not_exists(editor_dev, "redacteur", "redacteur", Context). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context -> _Context (unused)
@@ -21,7 +21,7 @@ | |||
-include("zotonic.hrl"). | |||
|
|||
manage_schema(_Version, Context) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context -> _Context (unused)
@@ -16,7 +16,7 @@ | |||
]). | |||
|
|||
manage_schema(install, Context) -> | |||
Datamodel = #datamodel{ | |||
#datamodel{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context -> _Context (unused)
@@ -19,18 +19,20 @@ | |||
]). | |||
|
|||
manage_schema(install, Context) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version is install
?
Context -> _Context (unused)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version type signature is:
-type manage_schema() :: install
| {upgrade, integer()}.
@@ -168,9 +168,7 @@ manage_schema(_Version, Context) -> | |||
]} | |||
]} | |||
] | |||
}, | |||
z_datamodel:manage(?MODULE, Datamodel, Context), | |||
schema:create_identity_if_not_exists(editor_dev, "redacteur", "redacteur", Context). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've never used it, maybe @loetie has
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use manage_data/2
to update/install data after the schema has been installed.
From #670