prepareAlterColumnsMysql() — drizzle-orm Function Reference
Architecture documentation for the prepareAlterColumnsMysql() function in jsonStatements.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 7b55cf7f_6d2b_2fa4_a8ff_81bae7f0b9c9["prepareAlterColumnsMysql()"] 6139f734_8ada_c641_9fec_9a55cfdf376f["jsonStatements.ts"] 7b55cf7f_6d2b_2fa4_a8ff_81bae7f0b9c9 -->|defined in| 6139f734_8ada_c641_9fec_9a55cfdf376f a5972ffc_ff1b_9523_2495_5373af710e65["applyMysqlSnapshotsDiff()"] a5972ffc_ff1b_9523_2495_5373af710e65 -->|calls| 7b55cf7f_6d2b_2fa4_a8ff_81bae7f0b9c9 d4992b27_bf78_8099_5134_750cef1c518c["applySingleStoreSnapshotsDiff()"] d4992b27_bf78_8099_5134_750cef1c518c -->|calls| 7b55cf7f_6d2b_2fa4_a8ff_81bae7f0b9c9 5fbcc7ce_945a_7e2d_e12d_559fa5000971["warning()"] 7b55cf7f_6d2b_2fa4_a8ff_81bae7f0b9c9 -->|calls| 5fbcc7ce_945a_7e2d_e12d_559fa5000971 style 7b55cf7f_6d2b_2fa4_a8ff_81bae7f0b9c9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/jsonStatements.ts lines 1362–1715
export const prepareAlterColumnsMysql = (
tableName: string,
schema: string,
columns: AlteredColumn[],
// TODO: remove?
json1: CommonSquashedSchema,
json2: CommonSquashedSchema,
action?: 'push' | undefined,
): JsonAlterColumnStatement[] => {
let statements: JsonAlterColumnStatement[] = [];
let dropPkStatements: JsonAlterColumnDropPrimaryKeyStatement[] = [];
let setPkStatements: JsonAlterColumnSetPrimaryKeyStatement[] = [];
for (const column of columns) {
const columnName = typeof column.name !== 'string' ? column.name.new : column.name;
const table = json2.tables[tableName];
const snapshotColumn = table.columns[columnName];
const columnType = snapshotColumn.type;
const columnDefault = snapshotColumn.default;
const columnOnUpdate = 'onUpdate' in snapshotColumn ? snapshotColumn.onUpdate : undefined;
const columnNotNull = table.columns[columnName].notNull;
const columnAutoIncrement = 'autoincrement' in snapshotColumn
? snapshotColumn.autoincrement ?? false
: false;
const columnPk = table.columns[columnName].primaryKey;
if (column.autoincrement?.type === 'added') {
statements.push({
type: 'alter_table_alter_column_set_autoincrement',
tableName,
columnName,
schema,
newDataType: columnType,
columnDefault,
columnOnUpdate,
columnNotNull,
columnAutoIncrement,
columnPk,
});
}
if (column.autoincrement?.type === 'changed') {
const type = column.autoincrement.new
? 'alter_table_alter_column_set_autoincrement'
: 'alter_table_alter_column_drop_autoincrement';
statements.push({
type,
tableName,
columnName,
schema,
newDataType: columnType,
columnDefault,
columnOnUpdate,
columnNotNull,
columnAutoIncrement,
columnPk,
});
}
if (column.autoincrement?.type === 'deleted') {
statements.push({
type: 'alter_table_alter_column_drop_autoincrement',
tableName,
columnName,
schema,
newDataType: columnType,
columnDefault,
columnOnUpdate,
columnNotNull,
columnAutoIncrement,
columnPk,
});
}
}
for (const column of columns) {
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does prepareAlterColumnsMysql() do?
prepareAlterColumnsMysql() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/jsonStatements.ts.
Where is prepareAlterColumnsMysql() defined?
prepareAlterColumnsMysql() is defined in drizzle-kit/src/jsonStatements.ts at line 1362.
What does prepareAlterColumnsMysql() call?
prepareAlterColumnsMysql() calls 1 function(s): warning.
What calls prepareAlterColumnsMysql()?
prepareAlterColumnsMysql() is called by 2 function(s): applyMysqlSnapshotsDiff, applySingleStoreSnapshotsDiff.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free