-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for arbirary database connection string #5
Comments
@ColdenCullen Interesting idea, I didn't realize it would be so straight forward to support in sqlx. I'll take a peek at this (maybe today or tomorrow if I can). Out of curiosity, how are you running the Docker container? FWIW, I think you might need to run |
Ah, it's a bit of a problem, it looks like -- the query macros don't support the Any connection type. (launchbadge/sqlx#964) That means that there are a handful of other paths forward:
I really like how trivial it is to spin up an instance with sqlite, and performance wise it seems totally reasonable for smaller query volumes (we're ~30-40 developers and it seems relatively low load -- plus we run it in our own Kubernetes cluster, rather than on e.g. AWS Elastic Container Service, so we would actually have to spin up a db for it), so that third option is probably off the table. |
This all makes sense to me! We run our container on an EC2 machine (not ECS) deployed by a CDK stack. The problem is that sometimes the CDK can decide that a machine requires replacement if there's been a significant enough OS update. The advantage of also having our CDK stack spin up an RDS instance to connect this to is that the machine running RUGS can be completely ephemeral, and we can apply a backup strategy only to the database, and not care if the machine running RUGS itself goes up, down, or sideways, since it can be trivially re-created. Let me know if there's anything else I can do to help make this work! |
Hm, interesting. Does it not persist Docker volumes when it replaces the container? That seems a little scary! I figured the whole point of using Docker-managed volumes (and not the bind mounts) was that the volumes were separate from the container and managed by the Docker tools. Do you have a sense for which database backend you'd want to use it with? |
It does persist docker volumes between container, but CDK will sometimes replace the entire EC2 instance. The idea is that the instance piece is just ephemeral compute for data stored elsewhere. That isn’t always a practical model, but it’s the model we’re stuck with if we want easy infrastructure-as-code. We default to Postgres on RDS unless we have a reason to use something else, so Postgres as the engine would be my first choice. |
Ok! Looking into this a little more, I think a potential path forward is to switch to SeaORM. It specifically abstracts it away in a manner where it supports dynamically picking the database connection at runtime. Overall I don't think the conversion will be too bad, since we use so few queries in RUGS, but I need to figure out a good way to handle migrations from existing databases -- creating a matching schema, then making sure that SeaORM doesn't think it needs migrating further. I also need to remove the dependency on the sqlite-specific |
It would be nice to be able to pass
DATABASE_URL
as an environment variable to the docker container in order to use an external database for enhanced robustness. This would allow us to run this tool in the cloud without requiring any on-disk persistence.It seems like this should be possible by:
sqlx::SqlitePool
withsqlx::AnyPool
sqlite:
ENV
entry to the Dockerfile to set a default and allow for overridesI gave it a shot locally, but I don't know enough about sqlx to make the swap. I ran into issues with the
query_scalar
macro returning a QueryScalar for the Sqlite driver and not the Any driver (I think this has to do with the files in the .sqlx folder?).The text was updated successfully, but these errors were encountered: