How to deal with sqlx migrate and schema that already exists?

I'm just starting to learn about database migrations so in an attempt to use the insights I learned, I used pg_dump to add the schema of an existing Postgres database into a migration file. However, there's a problem when I do sqlx migrate run because the schema already exists in the database. So without having to reset the database and reapply the migrations is there anything I can do about it? I have an extensive amount of data stored so I can't afford losing it all.

Did you use sqlx-cli to generate the migration files?

Yeah, you can see it from when I run sqlx migrate info. initialize has my database's current schema:

20241231035027/pending initialize

I started another discussion on Reddit and thanks to user spiralenator all I had to do was to modify my create statements to incorporate IF NOT EXISTS. I also got some functions so I'll just follow as discussed here.

1 Like