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

feat: add migration_table name option #2725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kriswuollett
Copy link

Add migration_table option to enable sharing a database among multiple apps/clients. It is the responsibility of the user to ensure database permissions for the database role performing the migration is not able affect other co-hosted apps/clients done in separate migration "partitions".

@kriswuollett
Copy link
Author

Tested locally with sqlite by cargo install the cli with --git flag for this branch.

@kriswuollett
Copy link
Author

Does this seem like a reasonable approach to quickly satisfy the needs outlined in the use cases before I do more things like add tests?

If more migration options, or some more refactoring is needed later, it may be warranted to look at refactoring the relationship between the migration and the database connection. They seem too tightly bound when the database connection is required to know about the migration table, _sqlx_migrations, when it may be more reasonable to just have a function to ask if a table exists, select from it, etc. -- currently the migration table name is hard-coded in every database connection implementation, e.g., postgres:

impl Migrate for PgConnection {
fn ensure_migrations_table(&mut self) -> BoxFuture<'_, Result<(), MigrateError>> {
Box::pin(async move {
// language=SQL
self.execute(
r#"
CREATE TABLE IF NOT EXISTS _sqlx_migrations (
version BIGINT PRIMARY KEY,
description TEXT NOT NULL,
installed_on TIMESTAMPTZ NOT NULL DEFAULT now(),
success BOOLEAN NOT NULL,
checksum BYTEA NOT NULL,
execution_time BIGINT NOT NULL
);
"#,
)
.await?;
Ok(())
})
}

@IgnisDa
Copy link

IgnisDa commented Sep 28, 2023

Hey @kriswuollett any updates on this? I would like to see this merged too.

@kriswuollett
Copy link
Author

@abonander, are you willing to work with an externally contributed PR to implement a migration table name option? I assume I'd need to add in schema/table name validation for the new option. Is there some other approach that would be preferred to the rather direct way I implemented the PR?

@bilemon
Copy link

bilemon commented Jan 17, 2024

+1 @abonander is there any interest on getting @kriswuollett's change reviewed and merged, or potentially helping define what you'd prefer to see? Or is this a non-priority at the moment for launchbadge (which is fine too)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants