JNOSQL / nosql-endgame

Apache License 2.0
1 stars 3 forks source link

Fill the database with sample data on startup #3

Open teobais opened 4 years ago

teobais commented 4 years ago

At the moment, we need to manually run the following query (Spring Boot MongoDB example) once the server is up :

db.gods.insertMany([{ "_id" : ObjectId("5f789b086997ea37498ed9a2"), "name" : "Zeus", "power" : "justice" },{ "_id" : ObjectId("5f789b316997ea37498ed9a3"), "name" : "Hera", "power" : "childbirth", "_class" : "org.jnosql.demo.endgame.spring.data.God" },{ "_id" : ObjectId("5f789b806997ea37498ed9a4"), "name" : "Poseidon", "power" : "hurricane" },{ "_id" : ObjectId("5f789b926997ea37498ed9a5"), "name" : "Demeter", "power" : "harvest" }, { "_id" : ObjectId("5f789ba16997ea37498ed9a6"), "name" : "Athena", "power" : "wisdom" },{ "_id" : ObjectId("5f789bb16997ea37498ed9a7"), "name" : "Apollo", "power" : "light" },{ "_id" : ObjectId("5f78a318a8577a08354131b8"), "name" : "John Doe", "_class" : "org.jnosql.demo.endgame.spring.data.God" },{ "_id" : ObjectId("5f78a359a8577a08354131b9"), "name" : "Sally Doe", "_class" : "org.jnosql.demo.endgame.spring.data.God" }])

Same applies to the Sprint Neo4J example; we manually play the :movies step so it can fill in the database with some sample data once the server is started.

It would be nice to automate these steps so that the database has some initial data on startup.

keilw commented 4 years ago

Maybe with something like Liquibase, but not sure about its NoSQL support, see https://forum.liquibase.org/t/extending-liquibase-to-support-nosql-databases/2106/8

Tegridy commented 4 years ago

Hi, can i try this one ?

keilw commented 4 years ago

Sure, what do you wanna use?

Tegridy commented 4 years ago

I wanna use Mongock. Could you also assign me and add hacktoberfest label please ?

keilw commented 4 years ago

Ok, so it's only for MongoDB, why not. What's that label, I am not sure, if we need all those labels or is there a benefit like getting something by GitHub if we do that?

Tegridy commented 4 years ago

Its event on GitHub during October, and lets users win prizes by doing PR to Open Source so there is chance that more people will help with your project. Hactoberfest info

keilw commented 4 years ago

Ok if we can win something why not, but October is almost over, do you think you'd still qualify or have something to show before the end of next week?O;-)

keilw commented 4 years ago

@Tegridy It does not really matter adding it here, but you should add the "hacktoberfest" label to a PR which needs to come in and be merged before Oct 31.

Tegridy commented 4 years ago

Yes, I came up only with Spring+Mongo solution because i don't know the other frameworks so sorry if it is a problem.

keilw commented 4 years ago

@Tegridy Unfortunately mocking is not what @thodorisbais had in mind. It was more about an actual test data generation, any idea if you could come up with that, too?

ThirumlaDevi commented 3 years ago

@thodorisbais @keilw From this reference, I could infer that the local setup currently demands mongodb to be be installed and setup with basic test data. Why don't we dockerise mongo with volume (so that the user doesn't loose any data). docker-compose configs lets you run migrations after setting up a DB. Could you please let me know if this would solve your issue?

teobais commented 3 years ago

@ThirumlaDevi sounds like a good idea. I'd be happy to review a PR introducing this change. Is this something you could help us with?

ThirumlaDevi commented 3 years ago

@thodorisbais Sure. I'll be happy to and i'll get back to you in case of any queries. Also, could you please assign this issue to me?

teobais commented 3 years ago

You're all set @ThirumlaDevi !

ThirumlaDevi commented 3 years ago

Hi @thodorisbais. I have made the needed docker changes and I am able to migrate all data with a single command. But I am however facing issues with building and bringing up the spring boot project. This is my first time working with this framework. Could you please help me with building the spring-mongo project? This was the only reference I could find in your project. TIA.

keilw commented 3 years ago

@Tegridy @thodorisbais I'm a little confused, why would it need Docker? So far the demos are all independent from Docker and I hope they also stay that way. Mongock sounds reasonable because it is a bit like Liquibase for MongoDB, but squeezing Docker in for no good reason I would not do that.

ThirumlaDevi commented 3 years ago

@keilw I just thought that the project needed a local mongodb setup with pre-fiiled data and that runs on any OS platform. Hence, as per my knowledge I suggested that a docker setup would satisfy this. I did not look into Mongock as you pointed out here that this is not what you were looking for.

keilw commented 3 years ago

@ThirumlaDevi No, it's the opposite, I said here earlier "Maybe with something like Liquibase" and Mongock sounds platform-neutral while Docker is tied to Linux, please let's not blow up the example with it that way I know, some think it's cool "Yes, great let's get Docker into everything" but it makes it harder to run those demos when we need them in a quick time, so please let's not add any burden here. All those Spring Boot Starters including the ones @thodorisbais and others used as a basis or https://github.com/okta/okta-spring-boot just to take one example do not require Docker, so let's not overcomplicate things here either.

@ThirumlaDevi I only mentioned we should not use mocking, but I hope you even looked at Mongock which is

a java MongoDB tool for tracking, managing and applying database schema changes accross all your environments based on a coding approach.

And that's exactly what we could need here, not Docker. Looking at https://github.com/JNOSQL/nosql-endgame/pull/4 it seems there was no Docker pollution there, so please why not continue @Tegridy's PR and forget about the Dockerization because it would make the examples more complicated. And if neither Spring, nor Helidon or Quarkus mandate it there's probably a good reason why;-)

Check out the Quarkus guides where some have an optional use of Docker. There must not be a mandatory use of Docker here,

ThirumlaDevi commented 3 years ago

@keilw Thank you for explaining your concern with my solution and providing some references for understanding purpose. As you pointed out @Tegridy's PR doesn't have any Docker intervention. But, there seems to be few information missing from local dummy date setup missing in PR #4. As I am not familiar with spring boot to further help you with this issue, I'll un-assign myself from this issue. Thanks for both of your time.

keilw commented 3 years ago

@ThirumlaDevi Thanks for your understanding. If you are not familiar with Spring Boot or Spring Data it may be better. Thanks for trying to help.