sebastienros / yessql

A .NET document database working on any RDBMS
MIT License
1.17k stars 195 forks source link

SQLite: Do not create database if not found automatically #530

Closed Skrypt closed 5 months ago

Skrypt commented 5 months ago

It should create a database in the context of a setup. But if the SQLite filename is different than the file standing in the folder then it should not try to create a new database. Just throw an exception that the Database was not found.

sebastienros commented 5 months ago

But if the SQLite filename is different than the file standing in the folder

Teh connection string contains a filename. If the file doesn't exist sqlite will create it. How could it work differently, should "Sqlite" look for any sqlite file (*.db ?) and just not create a new one ;) Or did I miss the point of your suggestion?

Skrypt commented 5 months ago

Yes, right now it will create it and only add the document table to that DB because it won't even execute a full OC setup on it. That's the whole point why we we're not allowing this name to be dynamic. Also, if I change the DatabaseName I don't get to a setup page, I get to a 404 page.

I don't think it makes sense to allow to set a DatabaseName for that matter but then if it can't be fixed in YesSQL by any mean then why are we doing this?

And, I don't really buy the argument that it is the responsibility of the dev to make sure it is set to the proper DatabaseName. We allow this to be changed then it will happen that someone does rename it and then make a tenant fail to load. Then, you don't get any logs ... you get a 404 which is hard for an IT guys to diagnose what is this issue happening.

Skrypt commented 5 months ago

At least we could log that it created a new db. Then we would know what happened.

Skrypt commented 5 months ago

Or YesSQL should know that we are in the context of an OC setup or not. Just trying to find a way to do this by throwing stupid ideas :wink:

Skrypt commented 5 months ago

SQLite has a param in it's connection string to not automatically create the DB

https://www.connectionstrings.com/sqlite/ https://www.connectionstrings.com/sqlite-net-provider/disable-create-database-behaviour/

Maybe that's the path that we should investigate. Leaving the responsibilty to the OC setup to create the Db file. Then, if we try to connect to a DatabaseName that is not in that folder it should throw an exception instead of creating the file.