Expand description
Type-Safe Database Migrations System
This module provides a compile-time validated migrations system inspired by Django, where:
- Invalid migrations fail to compile (missing columns, wrong types, etc.)
- Operations are reversible with typed
up()anddown()methods - SQL generation is dialect-aware
§Example
use oxide_sql_core::migrations::{
Migration, Operation, CreateTableBuilder,
bigint, varchar, timestamp, boolean,
};
pub struct Migration0001;
impl Migration for Migration0001 {
const ID: &'static str = "0001_create_users";
fn up() -> Vec<Operation> {
vec![
CreateTableBuilder::new()
.name("users")
.column(bigint("id").primary_key().autoincrement().build())
.column(varchar("username", 255).not_null().unique().build())
.column(varchar("email", 255).build())
.column(timestamp("created_at").not_null().default_expr("CURRENT_TIMESTAMP").build())
.build()
.into(),
]
}
fn down() -> Vec<Operation> {
vec![
Operation::drop_table("users"),
]
}
}Re-exports§
pub use dialect::DuckDbDialect;pub use dialect::MigrationDialect;pub use dialect::PostgresDialect;pub use dialect::SqliteDialect;pub use diff::AmbiguousChange;pub use diff::SchemaDiff;pub use diff::auto_diff_schema;pub use diff::auto_diff_table;pub use introspect::Introspect;pub use snapshot::ColumnSnapshot;pub use snapshot::SchemaSnapshot;pub use snapshot::TableSnapshot;
Modules§
- dialect
- Dialect-specific SQL generation for migrations.
- diff
- Schema diff engine for auto-migration generation.
- introspect
- Schema introspection trait.
- snapshot
- Schema snapshot types for diff-based migration generation.
Structs§
- AddColumn
Op - Add column operation.
- AddForeign
KeyOp - Add foreign key operation.
- Alter
Column Op - Alter column operation.
- Column
Builder - Type-safe column definition builder.
- Column
Definition - A complete column definition for migrations.
- Create
Index Op - Create index operation.
- Create
Table Builder - Type-safe CREATE TABLE builder.
- Create
Table Op - Create table operation.
- Drop
Column Op - Drop column operation.
- Drop
Foreign KeyOp - Drop foreign key operation.
- Drop
Index Op - Drop index operation.
- Drop
Table Builder - Builder for DROP TABLE operations.
- Drop
Table Op - Drop table operation.
- Foreign
KeyRef - A reference to a foreign key in another table.
- HasColumns
- Marker: table has at least one column.
- HasName
- Marker: table has a name set.
- Migration
Runner - Runs migrations in dependency order.
- Migration
State - Tracks which migrations have been applied.
- Migration
Status - Status of a migration.
- NoColumns
- Marker: table has no columns.
- NoName
- Marker: table has no name set.
- RawSql
Op - Raw SQL operation.
- Rename
Column Op - Rename column operation.
- Rename
Table Op - Rename table operation.
Enums§
- Alter
Column Change - Column alteration type.
- Default
Value - Default value for a column.
- Index
Type - Index type.
- Operation
- All possible migration operations.
Traits§
- Migration
- A database migration with typed up/down operations.
Functions§
- bigint
- Creates a BIGINT column builder.
- binary
- Creates a BINARY column builder.
- blob
- Creates a BLOB column builder.
- boolean
- Creates a BOOLEAN column builder.
- char
- Creates a CHAR column builder.
- date
- Creates a DATE column builder.
- datetime
- Creates a DATETIME column builder.
- decimal
- Creates a DECIMAL column builder.
- double
- Creates a DOUBLE column builder.
- integer
- Creates an INTEGER column builder.
- numeric
- Creates a NUMERIC column builder.
- real
- Creates a REAL column builder.
- smallint
- Creates a SMALLINT column builder.
- text
- Creates a TEXT column builder.
- time
- Creates a TIME column builder.
- timestamp
- Creates a TIMESTAMP column builder.
- varbinary
- Creates a VARBINARY column builder.
- varchar
- Creates a VARCHAR column builder.