Skip to main content

Schema

Struct Schema 

Source
pub struct Schema<'a> { /* private fields */ }
Expand description

Emits DDL and runs it.

Implementations§

Source§

impl<'a> Schema<'a>

Source

pub fn new(db: &'a Database) -> Self

Source

pub async fn create( &self, table: &str, define: impl FnOnce(&mut Table), ) -> Result<()>

Create a table.

Source

pub async fn create_if_missing( &self, table: &str, define: impl FnOnce(&mut Table), ) -> Result<()>

Create the table unless it exists, safely under concurrent callers.

For a table an application creates on the way up rather than in a migration. Not has_table followed by create: two processes booting at once both see no table, both create, and one fails.

create table if not exists is sent where the dialect has it — and the error meaning “it exists” is accepted anyway, because PostgreSQL’s if not exists is not serialised against a concurrent create: two callers can both pass its check and the loser gets 42P07 relation already exists, or 23505 on pg_type_typname_nsp_index. That is documented PostgreSQL behaviour, and it was measured here: ten of eleven tests failed the first time a suite booted against an empty database. Indexes that already exist are accepted the same way.

Source

pub async fn alter( &self, table: &str, define: impl FnOnce(&mut Table), ) -> Result<()>

Add or drop columns on an existing table.

Source

pub async fn drop(&self, table: &str) -> Result<()>

Source

pub async fn rename(&self, from: &str, to: &str) -> Result<()>

Source

pub async fn has_table(&self, table: &str) -> Result<bool>

Whether a table exists — how the migration runner decides what to do.

Source

pub async fn has_column(&self, table: &str, column: &str) -> Result<bool>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Schema<'a>

§

impl<'a> !UnwindSafe for Schema<'a>

§

impl<'a> Freeze for Schema<'a>

§

impl<'a> Send for Schema<'a>

§

impl<'a> Sync for Schema<'a>

§

impl<'a> Unpin for Schema<'a>

§

impl<'a> UnsafeUnpin for Schema<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.