March Docs

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

fncreate_tablecreate_table(name, columns)#

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 }) })

fnalter_tablealter_table(name, changes)#
fndrop_tabledrop_table(name)#

Generate a DROP TABLE statement.

Depot.Migration.drop_table("old_table")

fncreate_indexcreate_index(table, columns, opts)#

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 })

fncreate_index_simplecreate_index_simple(table, columns)#

Generate a CREATE INDEX with no options.

Depot.Migration.create_index_simple("users", ["name", "email"])

fndrop_indexdrop_index(name)#

Generate a DROP INDEX statement.

Depot.Migration.drop_index("users_email_index")

fnreferencesreferences(table, opts)#

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" })

fnrename_tablerename_table(from_name, to_name)#

Generate a RENAME TABLE statement.

Depot.Migration.rename_table("old_name", "new_name")

fnrename_columnrename_column(table, from_col, to_col)#

Generate a RENAME COLUMN statement.

Depot.Migration.rename_column("users", "name", "full_name")

fnexecuteexecute(sql)#

Log raw SQL to the migration log.

Depot.Migration.execute("INSERT INTO settings VALUES ('key', 'val')")

fnmigrations_tablemigrations_table()#

Generate the SQL to create the schema_migrations tracking table.

Depot.Migration.migrations_table()

fnrecord_migrationrecord_migration(version)#

Record a migration version as applied.

Depot.Migration.record_migration(20240101120000)

fnapplied_migrationsapplied_migrations()#

Return the list of applied migration versions.

Depot.Migration.applied_migrations()

fnis_appliedis_applied(version)#

Check if a migration version has been applied.

Depot.Migration.is_applied(20240101120000)