How to setup database on server without mix

I am attempting to deploy a phoenix app to a vps. Im using multi stage ci cd to build the release and send only that code to the server. My container is erroring when trying to run migrations with the following error.

My server doesnt have mix installed. I tried to install mix/elixir just to run mix ecto.create but it doesnt work since my source code is not on the server. Note that i have a db running in postgres and my connection string is correct, i can connect to and use the db through psql just fine. I even tried creating the schema_migrations table myself replicating what it is normally built as.

How should I approach this deploy? I need to be able to run migrations frequently. I can run migrations without mix but how can I initialize the database?

1 Like

You create the database the same way you normally would on any server then make sure your config has the connection details for it.

if you have done a release you have to specify the environment variable, usually DATABASE_URL following the sample in <project-url>/config/runtime.exs,

@sanswork @odix67 the database connection works. I just get that error when I try to run migrations inside the docker container that is running the release. Based on the recommendation in the error message, it seems to be related to the fact that i created the database manually with psql instead of using mix ecto.create.

I also want to use this setup with a managed postgres provider. I was unable to get that setup working properly due to the same issue.



The error implies the connection isn’t working probably since it cannot find the database. Are you defining DATABASE_URL anywhere?

@sanswork I have the db url hardcoded in my runtime.exs for the repo config.

postgresql://(user):(password)@host.docker.internal:5432/surf_local_db

Using the same exact string I can connect to the db locally with psql.

@chris-menz is the db empty when you connect to it with psql?

psql runs fine from in the docker container too?

Hi @chris-menz,
Did you maybe try to set db url as ecto://user:pass@host:5432/local_db ?

@sanswork yes i tried with the db empty, i also tried recreating the schema_migrations table. From some local testing it seems like thats what ecto.create does.

Postgres is running just locally on my ubuntu machine, I’m not running it in docker. Maybe I can try also Dockerizing postgres and see if the connection works.

I still don’t think its the connection that’s the direct issue.