Skip to content

Multidb - sqlite support #510

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

Merged
merged 3 commits into from
Aug 5, 2020
Merged

Multidb - sqlite support #510

merged 3 commits into from
Aug 5, 2020

Conversation

tg44
Copy link
Contributor

@tg44 tg44 commented Jul 19, 2020

I recreated this PR; #256

Separated commits;

  • The first solves the transaction in transaction connection in connection problem in the migration, which causes problems on db-engines which has no multithread support (like sqlite3), also adds a minor refactor to the setup.js
  • The second adds a helper to the 'NOW()' sql function, bcs some db engines (like sqlite) has another syntax for this...
  • The third adds a new db-config option (knex-native) and let an experienced knex user to add some own knex-native configurations. Also, this commit showcases an sqlite3 config, and adds psql and sqlite3 libs.

Probably fixes #185 and fixes #200

Missing things;

  • document the sqlite config
  • try out the psql support

@tg44
Copy link
Contributor Author

tg44 commented Jul 19, 2020

I think it is a CI error and not an error with the code...


module.exports = function () {
return new Promise((resolve, reject) => {
return setupJwt(resolve, reject);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setupJwt is not a promise, so returning it as is will be async but won't reject on error properly. If it were a promise, you wouldn't need to wrap it in a Promise constructor either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I literally just extracted the code to a new function. I think if it has some logical error now, it had it in the past too.

Probably I could have moved the promise creation to the setupJwt too, but probably it is just a matter of taste.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh, or I just simply not need to write the "return" keyword in this case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, it just could be written differently but let's just get it through for now


return userModel
function setupDefaultSettings() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure why you took this from a Migration and put it here, you're not doing that to any other migrations...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only migration where the concept was broken. I didn't needed to do it in any other migration bcs all of the other migrations just modify the schemas, and not trying to insert things to it. (BTW; we insert users in the setup but we insert settings in a migration?)

As I understand when you run the migrations it connects to the db. And when you run the settingModel.query().insert() it tries to connect to the db again (while we still migrate). Which in multithreaded env (like pg or mysql) not a big deal, you can have multiple connections/connection pools to the same db. But in sqlite you hava a lock on the file, so while one connection is attached to the db, the other connection "can't" connect to it.

If you are interested in it deeper I referenced an issue in the commit message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I get your point about breaking the concept. All good.

To clarify, "migrations" should be changes that occur before the App really runs. It's used on the Knex layer and should not perform any logic on data and assumes the database is in a certain state prior to execution.

Setup users is part of the app because it has to check if there is an admin user and only when not found, it creates one. As this happens on startup each time, a migration is not the right place for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this, BUT if injecting users is a runtime check, inserting settings why not? Also if inserting settings is essential to start the app, I think the default user is essential to start the app too. It breaks the logic if one or the other handled differently. I think it's mostly a theoretical question if inserting default data is part of the db migration or not, and most of the JVM world would place them to the migrations (including myself), but here the code already introduced both ways, and I simply chose the comfy side.

@jc21
Copy link
Member

jc21 commented Jul 19, 2020

Docker Image for build 4 is available on DockerHub as jc21/nginx-proxy-manager:github-pr-510

@tg44
Copy link
Contributor Author

tg44 commented Jul 26, 2020

Starting from today I use this image on my home server.

@jc21 jc21 merged commit 04412f3 into NginxProxyManager:develop Aug 5, 2020
@tg44
Copy link
Contributor Author

tg44 commented Aug 5, 2020

Thanks the merge!

@tg44 tg44 deleted the multidb-re branch August 5, 2020 23:36
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.

2 participants