Depot.Migration
Depot.Migration: migration DDL module for generating SQL statements.
Functions generate SQL DDL strings and log operations to a Vault-backed migration log. No real DB yet — functions return the SQL they would execute.
Usage:
Depot.Migration.create_table("users", { id = ("UUID", { primary_key = true }), name = "String", email = ("String", { null = false }), role = ("String", { default = "user" }) })
Depot.Migration.create_index("users", ["email"], { unique = true }) Depot.Migration.drop_table("old_table")
Functions
Generate a CREATE TABLE statement.
columns is a record where each field is either a bare type string like "String" or a tuple ("String", { null = false, default = "user" }).
Depot.Migration.create_table("users", { id = ("UUID", { primary_key = true }), name = "String", email = ("String", { null = false }) })
Generate a DROP TABLE statement.
Depot.Migration.drop_table("old_table")
Generate a CREATE INDEX statement.
columns is a list of column name strings. opts is a record with optional fields: unique — Bool (default false) name — custom index name string
Depot.Migration.create_index("users", ["email"], { unique = true })
Generate a CREATE INDEX with no options.
Depot.Migration.create_index_simple("users", ["name", "email"])
Generate a DROP INDEX statement.
Depot.Migration.drop_index("users_email_index")
Build a foreign key references descriptor record.
Returns a record with table, column, on_delete, on_update fields, merged with any overrides from opts.
let ref = Depot.Migration.references("posts", { column = "post_id", on_delete = "CASCADE" })
Generate a RENAME TABLE statement.
Depot.Migration.rename_table("old_name", "new_name")
Generate a RENAME COLUMN statement.
Depot.Migration.rename_column("users", "name", "full_name")
Log raw SQL to the migration log.
Depot.Migration.execute("INSERT INTO settings VALUES ('key', 'val')")
Generate the SQL to create the schema_migrations tracking table.
Depot.Migration.migrations_table()
Record a migration version as applied.
Depot.Migration.record_migration(20240101120000)
Return the list of applied migration versions.
Depot.Migration.applied_migrations()
Check if a migration version has been applied.
Depot.Migration.is_applied(20240101120000)