-
|
I have an existing application with several migration files built on SQLX and PostgreSQL. I'm considering migrating to sea-orm, but my concern is back-filling the existing migrations. Is there an API to generate migrations for an existing database? |
Beta Was this translation helpful? Give feedback.
Answered by
Huliiiiii
Dec 25, 2025
Replies: 2 comments 1 reply
-
|
You can use include_str to execute raw SQL in migrations. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
opeolluwa
-
|
for anyone looking for this I did use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
let query = include_str!("sqlx/20250705203826_create_playlist.sql");
let db = manager.get_connection();
db.execute_unprepared(query).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// Replace the sample below with your own migration scripts
manager
.drop_table(Table::drop().table("playlist").to_owned())
.await
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use include_str to execute raw SQL in migrations.