Skip to content
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

persist the default admin set id in the database #5263

Merged
merged 2 commits into from
Dec 3, 2021

Conversation

elrayle
Copy link
Contributor

@elrayle elrayle commented Dec 1, 2021

Fixes #5261

This also makes the default admin set and id accessible through Hyrax.config. The first time it is accessed, the default admin set will be created if it doesn’t already exist. If the default admin set id saved in the database changes, it will reset the instance variable in Hyrax.config that caches the default admin set.

Final Design

The final design is somewhat different than the one proposed in #5261.

It addresses challenges:

  • for existing apps, it will use the existing default admin set identified by DEFAULT_ID
  • allow the default admin set to be created with an assigned id (required for postgres adapter)
  • cache the default admin set and id so it doesn't have to be retrieved from the persistent store every time it is referenced
  • saves the id in the database so it is remembered between restarts of the system and other events that will wipe the cached version
  • the plumbing to allow for the identified default admin set to be changed is in place, but not surfaced in the UI. This is prep for having this functionality in the future.

Supporting changes:

  • persistance of the default admin set id is handled by model Hyrax::DefaultAdministrativeSet which saves the default admin set id in the database
  • runtime caching is handled by Hyrax.config.default_admin_set which caches the default admin set in @default_admin_set instance variable the first time it is accessed. It can be forced to update by calling Hyrax.config.reset_default_admin_set. Hyrax.config.default_admin_set_id` provides a shortcut to the default admin set's id.
  • Hyrax::AdminSetCreateService.find_or_create_default_admin_set uses Hyrax::DefaultAdministrativeSet to make sure the id is persisted. This maintains this method as "the" way to create the default admin set. Using this method, the persisted and cached versions of the default admin set will be refreshed if needed.

@samvera/hyrax-code-reviewers

@elrayle elrayle marked this pull request as draft December 1, 2021 21:41
@elrayle elrayle force-pushed the as_create_default_with_config branch 8 times, most recently from 695fe84 to a06fd26 Compare December 2, 2021 21:48
This also makes the default admin set and id accessible through `Hyrax.config`.  The first time it is accessed, the default admin set will be created if it doesn’t already exist.  If the default admin set id is saved in the database changes, it will reset the instance variable in `Hyrax.config` that caches the default admin set.

The adopted approach maintains `Hyrax::AdminSetCreateService.find_or_create_default_admin_set` as the place where the default admin set is created.  So all code using that method will continue to work.  Also, checking if an admin set is the default remained in `Hyrax::AdminSetCreateService.default_admin_set?`

Includes a new migration for the table saving the default admin set id, so the cache of the test app for CCI needed to be regenerated.

Remaining Work:
* update references to the default admin set and it’s id to use `Hyrax.config.default_admin_set` and `.default_admin_set_id`, respectively
@elrayle elrayle force-pushed the as_create_default_with_config branch from a06fd26 to d877d9c Compare December 2, 2021 22:07
The default_admin_set does not have to have the id saved, but it does have to exist with the `Hyrax::AdminSetCreateService::DEFAULT_ID` as the id if it is not saved.  This allows it to be found.

Since these tests are testing whether or not the create service can find the unsaved default admin set id, they were updated to create the default admin set and save the id using the factory.
@elrayle elrayle force-pushed the as_create_default_with_config branch from d877d9c to ba7a0bb Compare December 3, 2021 13:35
@elrayle elrayle marked this pull request as ready for review December 3, 2021 14:35
@elrayle
Copy link
Contributor Author

elrayle commented Dec 3, 2021

When run with the test app, the id continues to be assigned as the DEFAULT_ID.

Testing in nurax-pg with a freshly migrated database for both checks.

Check 1: creating with the rake task

This is the historical way to create default admin set for Hyrax apps.

$ bin/rails hyrax:default_admin_set:create
Successfully created default admin set

Confirm in rails console...

>> Hyrax::DefaultAdministrativeSet.first.default_admin_set_id
=> "5418df25-4cbd-4e2a-8bc7-c85e135bd5fc"
>> Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id.to_s
=> "5418df25-4cbd-4e2a-8bc7-c85e135bd5fc"
>> Hyrax.config.default_admin_set_id
=> "5418df25-4cbd-4e2a-8bc7-c85e135bd5fc"

Check 2: creating first time accessed when one doesn't exist

Cleared db before running second check.

Create and confirm in rails console...

>> Hyrax::DefaultAdministrativeSet.first
=> nil
>> Hyrax::AdminSetCreateService.find_or_create_default_admin_set.id
=> "7f0e2948-a90b-47ca-8871-424b81b07cb8"
>> Hyrax::DefaultAdministrativeSet.first.default_admin_set_id.to_s
=> "7f0e2948-a90b-47ca-8871-424b81b07cb8"
>> Hyrax.config.default_admin_set_id
=> "7f0e2948-a90b-47ca-8871-424b81b07cb8"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

create default admin set for non-wings adapters
2 participants