LionWeb-io / lionweb-repository

Reference implementation of LionWeb repository
Apache License 2.0
2 stars 1 forks source link

How should be the database initialized? #61

Closed ftomassetti closed 3 months ago

ftomassetti commented 3 months ago

We used to have scripts we could run to create the database and then populate the database. Now these scripts cannot be run from the command line as this code has been commented out. It seems to me that the logic to create the database is defined in this constant: https://github.com/LionWeb-io/lionweb-repository/blob/4afed926a5e85e82e7b7f654dfa90a3df1ff2398/packages/dbadmin/src/tools/create-database-sql.ts#L3-L20

Which is used only here: https://github.com/LionWeb-io/lionweb-repository/blob/4afed926a5e85e82e7b7f654dfa90a3df1ff2398/packages/dbadmin/src/controllers/DBAdminApi.ts#L17-L24

Therefore, if I want to create the database and then initialize it, I need to make a post request to /createDatabase first and then to either /init or /initWithoutHistory.

I also think that these operations are defined in a way that I can safely call them multiple times. If I call them more than once they will be no-op.

Is this correct? If so, should we:

  1. Remove the commented out code from https://github.com/LionWeb-io/lionweb-repository/blob/4afed926a5e85e82e7b7f654dfa90a3df1ff2398/packages/dbadmin/src/tools/database.ts
  2. Update the README to explain this behavior

Also, would it make sense to have an optional to automatically call these methods internally (i.e., not through post requests) at startup time?

joswarmer commented 3 months ago

Hi, I removed the code because the way it was done ensured the create database would always run automatically at server startup because it loads all the code. That is not what it should do. It should either not run, or at least run optional (as you suggest).

In a separate branch I have made the server multi-repository, meaning that you can have multiple repositories (multiple fully independent models). To support this, each request to the server gets an optional repository name. If not given it will use the default repository which is as it currently does.

We could make the server to optionally create the database and initialise zero or more repositories. This can be done through parameters to the server startup, something like:

start-server --create-database --init-default-repository --init-repositories <list of repository names>
start-server --create-database --init-default-repository
start-server --create-database --init-repositories <list of repository names>

or through a server-startup-config file (as property file or JSON file):

create-database = true
init-repositories = repo1, repo2
joswarmer commented 3 months ago

Right now create database and init repository override any existing one. I agree that this should be changed to a no-op, returning a "fail" message.

joswarmer commented 3 months ago

In the multi-repo branch I changed the init repository to do nothing if the repository already exists. I added a deleteRepository request, This is needed for the tests to delete the repository between tests.

ftomassetti commented 3 months ago

I like the idea of the configuration file

joswarmer commented 3 months ago

Initialization is done though a configuration file now. Either one with a default name, or one given with the --config <filename> parameter at startup