pub struct Blueprint { /* private fields */ }Expand description
A table being created — Laravel’s Blueprint.
Implementations§
Source§impl Blueprint
impl Blueprint
Sourcepub fn create(
table: impl Into<String>,
build: impl FnOnce(&mut Blueprint),
) -> Blueprint
pub fn create( table: impl Into<String>, build: impl FnOnce(&mut Blueprint), ) -> Blueprint
Describe table with build, and hand back the blueprint.
Sourcepub fn strict(&mut self) -> &mut Blueprint
pub fn strict(&mut self) -> &mut Blueprint
Emit a plain CREATE TABLE, so creating one that exists is an error
rather than a no-op.
The default is IF NOT EXISTS, which makes a migration safe to re-run
by hand against a database somebody has already touched.
Sourcepub fn column(
&mut self,
name: impl Into<String>,
kind: ColumnKind,
) -> &mut Column
pub fn column( &mut self, name: impl Into<String>, kind: ColumnKind, ) -> &mut Column
A column of any kind. The typed helpers below all come through here.
Sourcepub fn big_increments(&mut self, name: impl Into<String>) -> &mut Column
pub fn big_increments(&mut self, name: impl Into<String>) -> &mut Column
An auto-incrementing 64-bit primary key.
Sourcepub fn increments(&mut self, name: impl Into<String>) -> &mut Column
pub fn increments(&mut self, name: impl Into<String>) -> &mut Column
An auto-incrementing 32-bit primary key.
Sourcepub fn text(&mut self, name: impl Into<String>) -> &mut Column
pub fn text(&mut self, name: impl Into<String>) -> &mut Column
Unbounded text.
Not indexable on MySQL without a prefix length, so reach for
string for anything you will search or sort by.
Sourcepub fn big_integer(&mut self, name: impl Into<String>) -> &mut Column
pub fn big_integer(&mut self, name: impl Into<String>) -> &mut Column
A 64-bit signed integer.
Sourcepub fn unsigned_integer(&mut self, name: impl Into<String>) -> &mut Column
pub fn unsigned_integer(&mut self, name: impl Into<String>) -> &mut Column
A 32-bit unsigned integer.
Sourcepub fn unsigned_big_integer(&mut self, name: impl Into<String>) -> &mut Column
pub fn unsigned_big_integer(&mut self, name: impl Into<String>) -> &mut Column
A 64-bit unsigned integer.
Sourcepub fn foreign_id(&mut self, name: impl Into<String>) -> &mut Column
pub fn foreign_id(&mut self, name: impl Into<String>) -> &mut Column
A foreign key column: unsigned 64-bit and indexed, ready for
constrained_on.
table.foreign_id("author_id").constrained_on("users").cascade_on_delete();Sourcepub fn boolean(&mut self, name: impl Into<String>) -> &mut Column
pub fn boolean(&mut self, name: impl Into<String>) -> &mut Column
A boolean. An integer on SQLite and MySQL, which have no boolean type.
Sourcepub fn double(&mut self, name: impl Into<String>) -> &mut Column
pub fn double(&mut self, name: impl Into<String>) -> &mut Column
A double-precision float. Not for money — see
decimal.
Sourcepub fn decimal(
&mut self,
name: impl Into<String>,
precision: u32,
scale: u32,
) -> &mut Column
pub fn decimal( &mut self, name: impl Into<String>, precision: u32, scale: u32, ) -> &mut Column
A fixed-point number, for money and anything else that must not round.
Read ColumnKind::Decimal before using it on SQLite, which has no
fixed-point type and will store a float.
Sourcepub fn timestamps(&mut self) -> &mut Blueprint
pub fn timestamps(&mut self) -> &mut Blueprint
created_at and updated_at, both nullable.
Nullable because nothing here writes them for you — a row inserted by a
migration or by hand would otherwise fail. A model that always sets
them can declare its own NOT NULL columns instead.
Sourcepub fn soft_deletes(&mut self) -> &mut Column
pub fn soft_deletes(&mut self) -> &mut Column
A nullable deleted_at, for soft deletes.
Sourcepub fn primary<I, S>(&mut self, columns: I) -> &mut Blueprint
pub fn primary<I, S>(&mut self, columns: I) -> &mut Blueprint
A composite primary key.
What a pivot table wants: the pair is the key, so the same link cannot be inserted twice.
Sourcepub fn index<I, S>(&mut self, columns: I) -> &mut IndexDef
pub fn index<I, S>(&mut self, columns: I) -> &mut IndexDef
A secondary index, named by convention.
Sourcepub fn unique<I, S>(&mut self, columns: I) -> &mut IndexDef
pub fn unique<I, S>(&mut self, columns: I) -> &mut IndexDef
A UNIQUE index over one or more columns.
Sourcepub fn to_statement(&self) -> TableCreateStatement
pub fn to_statement(&self) -> TableCreateStatement
The CREATE TABLE statement, before rendering.
Sourcepub fn to_sql(&self, dialect: Dialect) -> Vec<String>
pub fn to_sql(&self, dialect: Dialect) -> Vec<String>
Every statement that creates this table on dialect, in order: the
table, then its indexes.
Sourcepub fn to_reverse_sql(&self, dialect: Dialect) -> Vec<String>
pub fn to_reverse_sql(&self, dialect: Dialect) -> Vec<String>
The statements that undo it: drop the table.
The indexes go with it — no engine keeps an index on a table that is no longer there — so one statement is the whole reversal.