Skip to content

Conversation

@bo0tzz
Copy link

@bo0tzz bo0tzz commented Nov 20, 2025

No description provided.

@isaacharrisholt
Copy link
Contributor

Hey, thanks for this! Have you tested the migration works in both directions? From a cursory glance it looks like you might need a cascade on the drop schema.

Also, this will break the current migration CLI, I believe. I don't intend to force folks to use Cigogne if they're already using another tool for migrations.

@bo0tzz
Copy link
Author

bo0tzz commented Nov 20, 2025

Going down seems to work seamlessly:

~/git/immich/loopdedupe main ⇡3 ❯ gleam run -m cigogne down                                                                                    12s
  Resolving versions
   Compiled in 0.05s
    Running cigogne.main

Rolling back migration 20251120204050-m25

Migrations rolled back:
	20251120204050-m25

I'll admit I tunnel-visioned a bit and missed the existing migration CLI; I'm not entirely sure how to handle that, the first thing that comes to mind is to split on --- migration:down?

@isaacharrisholt
Copy link
Contributor

It's possible that Cigogne has something we can use to just get the text from the up migration. I haven't looked at the API for this for a while.

@bo0tzz
Copy link
Author

bo0tzz commented Nov 20, 2025

They do (https://hexdocs.pm/cigogne/cigogne.html#get_all_migrations), but it comes in a List(String) of queries so the CLI would need a bit of a rework.

@isaacharrisholt
Copy link
Contributor

That looks like a sensible approach

@bo0tzz
Copy link
Author

bo0tzz commented Nov 21, 2025

Done, if I haven't missed something.

@isaacharrisholt
Copy link
Contributor

Hey, apologies that I haven't gotten to this yet. I haven't forgotten, just been super busy. I'll try to get to it in the next couple of weeks.

@bo0tzz
Copy link
Author

bo0tzz commented Dec 9, 2025

No worries!

Copy link
Contributor

@isaacharrisholt isaacharrisholt left a comment

Choose a reason for hiding this comment

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

Ideally want to avoid breaking changes here.

Comment on lines +80 to +87
use config <- result.try(
config.get("m25")
|> result.map_error(fn(err) {
err
|> string.inspect
|> add_error_context("Failed to get migrations configuration")
}),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

When I run this:

gleam run -m m25 migrate --addr=postgres://postgres:postgres@localhost:5432/postgres

I get the following:

Getting migrations for m25 tables... Command failed with an error: Failed to get migrations to apply for m25 tables: Failed to create migrations engine: DatabaseError(EnvVarUnset("DATABASE_URL")

Requiring DATABASE_URL is a breaking change I'd prefer to avoid. I don't mind supporting it, but it has to be alongside the --addr flag, with the flag taking precedence. I think you could do this in the connection_string_flag function where the flag's default is:

result.unwrap(
  envoy.get("DATABSE_URL"),
  "postgresql://postgres:postgres@localhost:5432/postgres",
)

You'd need to always pass the configured DB URL into Cignogne then.

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