Skip to content
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

Embedded database support #13

Closed
sugoidogo opened this issue Sep 17, 2022 · 3 comments
Closed

Embedded database support #13

sugoidogo opened this issue Sep 17, 2022 · 3 comments
Labels

Comments

@sugoidogo
Copy link
Contributor

While browsing this repo I noticed from the compose.prod.yaml that expanse is a node.js application who's only dependency outside the NodeJS ecosystem is postgres, a database application. It looks to me like docker is used to run an instance of postgres as a dependency of expanse, but npm also has various embedded database libraries, and there's even embedded-postgres. Using one of these would allow the removal of docker as a requirement, which opens up many more options for packaging expanse, especially using existing automated tools for nodejs packaging. Using an embedded database by default and allowing the user to configure an external database at their preference provides a much higher degree of portability to the software that self-hosters like myself would much appreciate.

@jc9108 jc9108 added the request label Sep 18, 2022
@sugoidogo
Copy link
Contributor Author

sugoidogo commented Sep 20, 2022

I tried to implement these changes myself, but I hit a bit of a wall. I added the dotenv library and moved the environment variables previously in the launch commands to the .env_example to get cross-platform environment variable loading. Since the port was there I also made the bind ip configurable, so hosters can change that to localhost/127.0.0.1 if they only want expanse accessible on their local pc. I gave the connection string the same treatment, adding the POSTGRES_PORT variable and a POSTGRES_EMBEDDED variable to determine if that info should be used to create the postgres server or not. My issue appeared once I tried to actually use the embedded-postgres library.

sugoidogo@dev:~/expanse/backend$ npm run prod

> prod
> node -r dotenv/config controller/server.mjs dotenv_config_path=.env_prod

file:///home/sugoidogo/expanse/backend/model/sql.mjs:12
    const pg = new EmbeddedPostgres({
               ^

TypeError: EmbeddedPostgres is not a constructor
    at init_db_embedded (file:///home/sugoidogo/expanse/backend/model/sql.mjs:12:16)
    at Module.init_db (file:///home/sugoidogo/expanse/backend/model/sql.mjs:32:9)
    at file:///home/sugoidogo/expanse/backend/controller/server.mjs:31:11

I don't think it's an issue with the library, but there's not much documentation on the npm package. I don't have a lot of experience with nodejs or successfully using es6 libraries so maybe you can point out what I've done wrong here.

@sugoidogo
Copy link
Contributor Author

Figured out my issue, it's a commonjs module. Have to initialize with EmbeddedPostgres.default, don't know why. Tried that before, but assumed it didn't work because the dev misspelled the function as initialise() in their code and then again as inititialize() on their only doc page. PR coming shortly.

@jc9108
Copy link
Owner

jc9108 commented Sep 20, 2022

sorry, im not really considering adding this as the app already has docker support and ive resolved #12 earlier to allow using external dbs by providing your own connection string.

if you want to use expanse without docker just run npm ci in both backend/ and frontend/, run npm run build in frontend/, then run npm run prod in backend/. with your dotenv changes this will work. (also the app needs the apt package postgresql-client to create backups).

also note that this embedded-postgres package is made for testing, it says specifically on their homepage.

so im not going to accept the PR but of course you can keep it in your own fork if it's useful to you.

@jc9108 jc9108 closed this as completed Sep 20, 2022
@jc9108 jc9108 added the wontfix This will not be worked on label Sep 20, 2022
@jc9108 jc9108 removed the wontfix This will not be worked on label Dec 11, 2022
@jc9108 jc9108 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants