Databases
sql.mysql.ddl
import sql.mysql.ddl
Zuri
sqldoes not re-export this module, so it is reached only by importing it directly.
Schema changes for MySQL and MariaDB.
Both commit after every statement that changes a table's definition, whatever transaction is open, so a schema change here is never rolled back. Each statement is permanent once it has run.
Tables are created with InnoDB, the storage engine that enforces foreign
keys, and with utf8mb4, the character set that can hold all of
Unicode. Indexes are declared inside create table, so if_not_exists
applies to them as well as to the table. A text, binary or JSON column
can only have a default that's an expression, so its default is written
in parentheses.
Classes
MySqlDdl
class sql.mysql.ddl.MySqlDdl < DdlAdapter
ZuriTurns blueprints into the statements MySQL and MariaDB share.
MySqlDdl.type_name()
sql.mysql.ddl.MySqlDdl.type_name(column) -> string
ZuriParameters
column(Column)
Returns string
MySqlDdl.key_definition()
sql.mysql.ddl.MySqlDdl.key_definition(column) -> string
ZuriParameters
column(Column)
Returns string
MySqlDdl.exact_collation()
sql.mysql.ddl.MySqlDdl.exact_collation() -> string
ZuriReturns string
MySqlDdl.boolean_literal()
sql.mysql.ddl.MySqlDdl.boolean_literal(value: bool) -> string
ZuriParameters
value(bool)
Returns string
MySqlDdl.string_literal()
sql.mysql.ddl.MySqlDdl.string_literal(text: string) -> string
ZuriA string as a literal. One holding a backslash is written as hex with a character set, which reads the same whether or not the server treats a backslash as an escape.
Parameters
text(string)
Returns string
MySqlDdl.current_default()
sql.mysql.ddl.MySqlDdl.current_default(column) -> string
ZuriParameters
column(Column)
Returns string
MySqlDdl.table_suffix()
sql.mysql.ddl.MySqlDdl.table_suffix() -> string
ZuriReturns string
MySqlDdl.parenthesised_default()
sql.mysql.ddl.MySqlDdl.parenthesised_default(column) -> bool
ZuriParameters
column(Column)
Returns bool
MySqlDdl.inline_indexes()
sql.mysql.ddl.MySqlDdl.inline_indexes() -> bool
ZuriReturns bool
MySqlDdl.check_index()
sql.mysql.ddl.MySqlDdl.check_index(table: string, columns: list, described: list)
ZuriRefuses an index on a text, binary or JSON column described alongside it, which MySQL cannot index whole.
Parameters
table(string)columns(list[string])described(list[Column])
Raises NotSupportedError for such a column.
MySqlDdl.add_column()
sql.mysql.ddl.MySqlDdl.add_column(connection, table: string, column)
ZuriAdds a column, but refuses to add a required column with no default while the table has rows. MySQL would fill the existing rows with a value of its own choosing, but the other engines refuse, and so does this.
Parameters
connection(Connection)table(string)column(Column)
Raises NotNullViolation for a required column with no default on a
table with rows.
MySqlDdl.change_column()
sql.mysql.ddl.MySqlDdl.change_column(connection, table: string, column) -> list[string]
ZuriParameters
connection(Connection)table(string)column(Column)
Returns list[string]
MySqlDdl.drop_column()
sql.mysql.ddl.MySqlDdl.drop_column(connection, table: string, name: string) -> list[string]
ZuriDrops the foreign keys and indexes that the column is part of, before dropping the column. Otherwise, MySQL would refuse while a key uses the column, and would remove the column from a composite index instead of dropping the index.
Parameters
connection(Connection)table(string)name(string)
Returns list[string]
MySqlDdl.drop_index()
sql.mysql.ddl.MySqlDdl.drop_index(connection, table: string, name: string) -> list[string]
ZuriParameters
connection(Connection)table(string)name(string)
Returns list[string]
MySqlDdl.drop_foreign()
sql.mysql.ddl.MySqlDdl.drop_foreign(connection, table: string, name: string) -> list[string]
ZuriDrops the key, and the index of the same name InnoDB made for it when the key was added, so what is left is what the other engines leave.
Parameters
connection(Connection)table(string)name(string)
Returns list[string]
MySqlDdl.drop_primary()
sql.mysql.ddl.MySqlDdl.drop_primary(connection, table: string) -> list[string]
ZuriParameters
connection(Connection)table(string)
Returns list[string]
MySqlDdl.drop_table()
sql.mysql.ddl.MySqlDdl.drop_table(connection, table: string, options: dict)
ZuriParameters
connection(Connection)table(string)options(dict)
MySqlDdl.rename_table()
sql.mysql.ddl.MySqlDdl.rename_table(connection, from: string, to: string)
ZuriParameters
connection(Connection)from(string)to(string)
MySqlDdl.migration_lock()
sql.mysql.ddl.MySqlDdl.migration_lock(connection, name: string, body: function) -> any
ZuriHolds the named lock that GET_LOCK takes while body runs, waiting as
long as necessary for another session holding it to release it.
Parameters
connection(Connection)name(string)body(function)
Returns any — Whatever body returned.
Raises QueryError if the server answers the request for the lock
with an error, in which case body never runs.
2026, Richard Ore and Zuri contributors