Skip to main content

Blueprint

Struct Blueprint 

Source
pub struct Blueprint { /* private fields */ }
Expand description

The columns and commands (indexes, keys, renames, drops) of a table, in the order they were added.

Implementations§

Source§

impl Blueprint

Source

pub fn id(&mut self) -> &mut Column

An auto-incrementing 64-bit primary key named id. In schema::table SQLite cannot add it, as SQLite cannot add a primary key column to an existing table.

Source

pub fn string(&mut self, name: &str) -> &mut Column

A VARCHAR(255); TEXT on SQLite. Change the length with .length(n).

Source

pub fn text(&mut self, name: &str) -> &mut Column

A TEXT column.

Source

pub fn integer(&mut self, name: &str) -> &mut Column

An INTEGER column.

Source

pub fn big_integer(&mut self, name: &str) -> &mut Column

A BIGINT column; INTEGER on SQLite, whose integers are 64-bit already.

Source

pub fn boolean(&mut self, name: &str) -> &mut Column

A boolean: BOOLEAN on PostgreSQL, TINYINT(1) elsewhere.

Source

pub fn date_time(&mut self, name: &str) -> &mut Column

A date and time without a time zone: DATETIME, or TIMESTAMP(0) on PostgreSQL. Set fractional seconds with .precision(p) and a default of the current time with .use_current().

Source

pub fn timestamp(&mut self, name: &str) -> &mut Column

A timestamp, as Laravel’s timestamp: TIMESTAMP on MySQL, TIMESTAMP(0) WITHOUT TIME ZONE on PostgreSQL, DATETIME on SQLite. Set fractional seconds with .precision(p) and a default of the current time with .use_current().

On MySQL and MariaDB with explicit_defaults_for_timestamp off (the MariaDB default before 10.10), the first TIMESTAMP column of a table that is NOT NULL and has no default gets DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP from the server. Laravel’s columns get the same. Add .nullable() or a default to avoid it.

Source

pub fn binary(&mut self, name: &str) -> &mut Column

A column of raw bytes, as Laravel’s binary: BLOB, or BYTEA on PostgreSQL.

Source

pub fn timestamps(&mut self)

Nullable created_at and updated_at columns.

Source

pub fn unique<I, S>(&mut self, columns: I) -> &mut Index
where I: IntoIterator<Item = S>, S: AsRef<str>,

A unique constraint over columns, named {table}_{columns}_unique unless .name() gives another name.

Source

pub fn index<I, S>(&mut self, columns: I) -> &mut Index
where I: IntoIterator<Item = S>, S: AsRef<str>,

A plain index over columns, named {table}_{columns}_index unless .name() gives another name.

Source

pub fn primary<I, S>(&mut self, columns: I)
where I: IntoIterator<Item = S>, S: AsRef<str>,

A primary key over columns, as Laravel’s $table->primary(['a', 'b']): the table constraint PRIMARY KEY (a, b). For a key of one column, .primary() on the column does the same. In schema::table SQLite cannot add it: it is Error::Unsupported there.

Source

pub fn foreign(&mut self, column: &str) -> &mut ForeignKey

A foreign key on column, named {table}_{column}_foreign unless .name() gives another name. In schema::table SQLite renders nothing, as SQLite cannot add a constraint to an existing table.

Source

pub fn rename_column(&mut self, from: &str, to: &str)

Renames the column from to to: ALTER TABLE ... RENAME COLUMN. Only in schema::table.

RENAME COLUMN needs MySQL 8.0.3 or later, or MariaDB 10.5.2 or later. On older servers Laravel falls back to CHANGE old new <definition>; Orbit does not, and the server reports a syntax error.

Source

pub fn drop_column(&mut self, name: &str)

Drops the column name: ALTER TABLE ... DROP COLUMN. Only in schema::table. SQLite needs version 3.35 or later.

Source

pub fn drop_index(&mut self, name: &str)

Drops the index name, as Laravel’s dropIndex('name'). Only in schema::table.

On MySQL it drops a unique index too. On SQLite it drops a unique only when unique added it in schema::table: a unique declared in schema::create is an inline constraint there and cannot be dropped this way. On PostgreSQL unique always adds a constraint, and DROP INDEX cannot drop the index of a constraint. Orbit has no drop_unique (Laravel’s dropUnique).

Source

pub fn drop_foreign(&mut self, name: &str)

Drops the foreign key name, as Laravel’s dropForeign('name'). Only in schema::table. SQLite renders nothing, as it cannot drop a constraint from an existing table and foreign added none there.

Trait Implementations§

Source§

impl Clone for Blueprint

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Blueprint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Blueprint

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more