-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add example for referencing complex migration in another migra…
…tion using virtual migration Signed-off-by: Saurav Sharma <[email protected]>
- Loading branch information
1 parent
bef860f
commit 18ef121
Showing
6 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use sqlx::{MySql, MySqlConnection}; | ||
use sqlx_migrator::error::Error; | ||
use sqlx_migrator::migration::Migration; | ||
use sqlx_migrator::operation::Operation; | ||
|
||
pub(crate) struct M0005Operation; | ||
|
||
#[async_trait::async_trait] | ||
impl Operation<MySql> for M0005Operation { | ||
async fn up(&self, connection: &mut MySqlConnection) -> Result<(), Error> { | ||
sqlx::query("INSERT INTO sample (id, name) VALUES (888, 'complex')") | ||
.execute(connection) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, connection: &mut MySqlConnection) -> Result<(), Error> { | ||
sqlx::query("DELETE FROM sample WHERE id = 888") | ||
.execute(connection) | ||
.await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub(crate) struct M0005Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl Migration<MySql> for M0005Migration { | ||
fn app(&self) -> &'static str { | ||
"main" | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"m0005_reference_complex" | ||
} | ||
|
||
fn parents(&self) -> Vec<Box<dyn Migration<MySql>>> { | ||
vec![Box::new(("main", "m0004_complex_operation"))] | ||
} | ||
|
||
fn operations(&self) -> Vec<Box<dyn Operation<MySql>>> { | ||
vec![Box::new(M0005Operation)] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use sqlx::{PgConnection, Postgres}; | ||
use sqlx_migrator::error::Error; | ||
use sqlx_migrator::migration::Migration; | ||
use sqlx_migrator::operation::Operation; | ||
|
||
pub(crate) struct M0005Operation; | ||
|
||
#[async_trait::async_trait] | ||
impl Operation<Postgres> for M0005Operation { | ||
async fn up(&self, connection: &mut PgConnection) -> Result<(), Error> { | ||
sqlx::query("INSERT INTO sample (id, name) VALUES (888, 'complex')") | ||
.execute(connection) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, connection: &mut PgConnection) -> Result<(), Error> { | ||
sqlx::query("DELETE FROM sample WHERE id = 888") | ||
.execute(connection) | ||
.await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub(crate) struct M0005Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl Migration<Postgres> for M0005Migration { | ||
fn app(&self) -> &'static str { | ||
"main" | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"m0005_reference_complex" | ||
} | ||
|
||
fn parents(&self) -> Vec<Box<dyn Migration<Postgres>>> { | ||
vec![Box::new(("main", "m0004_complex_operation"))] | ||
} | ||
|
||
fn operations(&self) -> Vec<Box<dyn Operation<Postgres>>> { | ||
vec![Box::new(M0005Operation)] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use sqlx::{Sqlite, SqliteConnection}; | ||
use sqlx_migrator::error::Error; | ||
use sqlx_migrator::migration::Migration; | ||
use sqlx_migrator::operation::Operation; | ||
|
||
pub(crate) struct M0005Operation; | ||
|
||
#[async_trait::async_trait] | ||
impl Operation<Sqlite> for M0005Operation { | ||
async fn up(&self, connection: &mut SqliteConnection) -> Result<(), Error> { | ||
sqlx::query("INSERT INTO sample (id, name) VALUES (888, 'complex')") | ||
.execute(connection) | ||
.await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down(&self, connection: &mut SqliteConnection) -> Result<(), Error> { | ||
sqlx::query("DELETE FROM sample WHERE id = 888") | ||
.execute(connection) | ||
.await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub(crate) struct M0005Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl Migration<Sqlite> for M0005Migration { | ||
fn app(&self) -> &'static str { | ||
"main" | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"m0005_reference_complex" | ||
} | ||
|
||
fn parents(&self) -> Vec<Box<dyn Migration<Sqlite>>> { | ||
vec![Box::new(("main", "m0004_complex_operation"))] | ||
} | ||
|
||
fn operations(&self) -> Vec<Box<dyn Operation<Sqlite>>> { | ||
vec![Box::new(M0005Operation)] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters