#[non_exhaustive]pub struct Migration { /* private fields */ }Expand description
One migration: SQL to apply it and, optionally, SQL to undo it.
Usually generated from migrations/*.up.sql and *.down.sql by
renox::migrations!(). Names start with a timestamp and run in name order.
When SQL differs between databases, NAME.postgres.up.sql (and
.postgres.down.sql) or NAME.sqlite.up.sql replace the plain files on
that database; the plain file may then be left out if both are given.
By hand (in tests, say), it’s built with const methods:
use renox::db::Migration;
const NOTES: Migration = Migration::new(
"20300101000000_notes",
"CREATE TABLE notes (id INTEGER PRIMARY KEY AUTOINCREMENT, body TEXT NOT NULL)",
Some("DROP TABLE notes"),
)
.postgres(
"CREATE TABLE notes (id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, body TEXT NOT NULL)",
None, // the plain `down` above
);Implementations§
Source§impl Migration
impl Migration
Sourcepub const fn sqlite(self, up: &'static str, down: Option<&'static str>) -> Self
pub const fn sqlite(self, up: &'static str, down: Option<&'static str>) -> Self
SQLite’s own SQL, used instead of the plain up; down: None falls
back to the plain down.
Sourcepub const fn postgres(
self,
up: &'static str,
down: Option<&'static str>,
) -> Self
pub const fn postgres( self, up: &'static str, down: Option<&'static str>, ) -> Self
PostgreSQL’s own SQL, used instead of the plain up; down: None
falls back to the plain down.
Sourcepub const fn name(&self) -> &'static str
pub const fn name(&self) -> &'static str
The migration’s name, e.g. 20260101000000_create_products_table; names sort the runs.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Migration
impl RefUnwindSafe for Migration
impl Send for Migration
impl Sync for Migration
impl Unpin for Migration
impl UnsafeUnpin for Migration
impl UnwindSafe for Migration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more