-
Notifications
You must be signed in to change notification settings - Fork 37
WIP: Bootstrap relational database from fixtures #775
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: develop
Are you sure you want to change the base?
Conversation
85a5919 to
dfdb146
Compare
src/main/java/org/fairdatapoint/config/properties/BootstrapProperties.java
Outdated
Show resolved
Hide resolved
|
Hi @MarekSuchanek there's a typo in the package name: |
|
@MarekSuchanek some general comments/requests:
|
src/main/java/org/fairdatapoint/service/bootstrap/components/AbstractBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/AbstractBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/AbstractBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/MembershipBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/AbstractBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/MetadataRecordsBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/MetadataRecordsBootstrapper.java
Outdated
Show resolved
Hide resolved
|
Another general question: |
src/main/java/org/fairdatapoint/service/bootstrap/components/MetadataRecordsBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/MetadataRecordsBootstrapper.java
Outdated
Show resolved
Hide resolved
|
@MarekSuchanek Another general question: Looks like the fixture classes in This also relates to the way the fixtures are stored, e.g. as separate files for each object vs a single file with an array of objects. |
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.
Hi @MarekSuchanek,
This looks pretty good, but I've got the feeling it can be simplified considerably.
Perhaps you could take a look at the detailed comments so far and clarify some things?
To summarize:
- Please provide explanatory comments in the code, explaining what things are intended to do and especially why they are done in a certain way (at least indicating the patterns used)
- What would be the general workflow for overriding/extending default fixtures (using docker)?
- Could we use spring data repository populators, so we don't need separate fixture classes and corresponding mapper methods? (basically loading fixtures directly into entities)
- Related to the above, there's the option to define multiple related fixture objects in a json array, as opposed to separate files for each object.
- Related entities should get their own fixtures.
- Would it not be possible to use a single bootstrapper for all fixtures? The trick should be the same every time, except maybe for the records (which use the triple store).
It would be great if you could clarify this.
Also could you check if we can merge #778?
src/main/java/org/fairdatapoint/service/bootstrap/fixtures/UserFixture.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/fixtures/UserFixture.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/fixtures/MembershipFixture.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/bootstrap/components/MembershipBootstrapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/fairdatapoint/service/membership/MembershipMapper.java
Outdated
Show resolved
Hide resolved
Thanks for the review, some of the things are mistakes (like the typo or
|
I agree , that |
|
Thanks for the quick response @MarekSuchanek ! 🙂
Not sure about the general consensus, but in my opinion fixtures should be bound to the structure of DB entities.
I think the advantage is uniformity. You can do the same trick every time, without needing special handling for objects with relations. Of course you do need to ensure relational integrity yourself when creating the fixture files. Also the order of fixture loading is important. This is also how it is done in Python/Django, and in my experience that works really well. W.r.t "manage more files", with populators you could have an array of objects, so fewer files. E.g. a single |
Ok thanks. I guess it is also a matter of providing good documentation for this. :) |
|
@dennisvang I tried Populators with your example prototype and it would indeed simplify how to reach this functionality and make it more "universal". At the same time, two issues I spot and want to make sure it is OK or if we need to deal with that somehow:
|
Hi @MarekSuchanek thanks for giving the prototype a try. I'm sure a proper implementation would need a lot more work, but I would be happy to contribute to that.
I would prefer only to allow hashed passwords in the fixtures. Of course we would need to provide some instructions for how to generate a hashed password. Currently the FDP is configured to use bcrypt:
Afaik bcrypt and argon2id hashes are fully portable, i.e. they contain all information needed for verification. For scrypt you would still need to know the correct parameters. In any case users should be able to use any (offline) tool to generate a hash. This can be done on the linux command line using the appropriate package. Languages and frameworks also have their solutions, such as the spring boot cli encodepassword command. There are online tools as well, but better not use those, I think. Another alternative would be to fire up a local fdp, create the user(s) manually, then dump the resulting database content into a json file. Note While we're at it, perhaps the v2 release would also be a good opportunity to upgrade the hashing algorithm to argon2id, as I believe that is the current best practice. For example,from OWASP:
For example we can echo "mypassword" | argon2 applysomerandomsalthere -id -k 19456 -t 2 -p 1Even better would be to use a DelegatingPasswordEncoder to make this future-proof. Changing the password encoder would be a separate PR of course.
I think it would be good to have a clear separation between the loading of relational db fixtures and RDF (Turtle) fixtures. The RDF would need a dedicated loader anyway, I suppose. I discussed this with @luizbonino recently, and we were thinking of storing the actual "metadata schema SHACL definitions" directly in a separate repository in the triple store. The fixtures for the relational db could then just contain the URI of the metadata schema. What are your thoughts on that?
Could you clarify?
EDIT: On second thought, you're right: Indeed it would still be necessary to remember which fixtures have been applied, to prevent overwriting changes. For example, if we populate user accounts from fixtures, then any changes made to those accounts by the user, such as a password reset, would be reverted whenever the app restarts. |
Co-authored-by: dennisvang <29799340+dennisvang@users.noreply.github.com>
a14e339 to
b41a40e
Compare
|
Hi @dennisvang , so I switched from custom to populators with the last commit (and closed the discussions that are no longer relevant due to that):
Done, we still need to find suitable spot for declaring how to create the hashed password. Maybe docs?
That would be good; however, that should be separate issue as that will get some tricky parts as well probably (esp. with different versions of metadata schemas, updates, etc.).
JSON schemas that I tried to prepare for the custom JSON files. Let's keep it simple now.
True, but not sure how that should work for metadata records being loaded from fixtures. So, could you check and eventually propose changes wrt populators? And then we need to still resolve the records (aside RDF we need information if it is for draft or main repository (can be decided based on file location?) and we probably want the replacement variable with persistent URL as I suggested somehow... |
this is more consistent with e.g. the 'locations' option for flyway
This allows us to include the prefix in the config, which is more flexible. For example, we can set file:fixtures for the default fixtures, which need to be overridable in the docker container, and we can set classpath:test-fixtures for the test fixtures, which can then be included in the test/resources dir. Moreover, this approach is similar to the way flyway.locations are specified.
the populator is done, but that does not necessarily mean any repositories were actually populated
This reverts commit 1ac2639.
* include root logger AppenderRef, so we only need to change the log level, when required * rename test logging config file for clarity and conformance to log4j2 best practices
…ault 02xx fixtures
this enables us to specify simple directories, specific files, filters like 'fixtures/02*.json', and wildcards like 'fixtures/**/*.json'
the Path methods caused errors on windows if the location included ':' or '*' characters
description said Nikola Tesla, but uuid was for Albert Einstein
…ure data changed uuid and type for SearchSavedQuery objects to minimize interference with the existing acceptance tests
Due to the addition of DatabaseBootstrapTests, fixture 0130_test-users-with-api-keys-and-saved-queries.json now includes two new SearchSavedQuery objects. One of these new objects replaces the other, so the total number of SearchSavedQuery objects expected in the test database is increased by one.
Although I prefer .org, existing docs and tests expect .com. Also it will likely lead to confusion because people will keep trying to log in using the .com addresses.
…t-data-migrations Bootstrap test data from JSON fixtures instead of SQL migrations
Description
A new feature to support bootstrapping the relational database (postgresql) from JSON fixtures.
Also see follow-up #785
Checklist
TODO:
src/main/resources/dev/db/migration(add separate set of dev fixtures, or just use the default ones?) (Use JSON fixtures instead of SQL migrations in development profile #790)