_moveDataStatements() — drizzle-orm Function Reference
Architecture documentation for the _moveDataStatements() function in libSqlPushUtils.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 615e941b_9f5e_d8e2_86b7_7a83b56b1da5["_moveDataStatements()"] 0232777b_2a7f_2d05_d5d8_ae34939c6599["libSqlPushUtils.ts"] 615e941b_9f5e_d8e2_86b7_7a83b56b1da5 -->|defined in| 0232777b_2a7f_2d05_d5d8_ae34939c6599 3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7["libSqlLogSuggestionsAndReturn()"] 3fa496e9_2bff_7b59_f02a_4cc1a6cfcea7 -->|calls| 615e941b_9f5e_d8e2_86b7_7a83b56b1da5 style 615e941b_9f5e_d8e2_86b7_7a83b56b1da5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/cli/commands/libSqlPushUtils.ts lines 28–111
export const _moveDataStatements = (
tableName: string,
json: SQLiteSchemaSquashed,
dataLoss: boolean = false,
) => {
const statements: string[] = [];
const newTableName = `__new_${tableName}`;
// create table statement from a new json2 with proper name
const tableColumns = Object.values(json.tables[tableName].columns);
const referenceData = Object.values(json.tables[tableName].foreignKeys);
const compositePKs = Object.values(
json.tables[tableName].compositePrimaryKeys,
).map((it) => SQLiteSquasher.unsquashPK(it));
const checkConstraints = Object.values(json.tables[tableName].checkConstraints);
const fks = referenceData.map((it) => SQLiteSquasher.unsquashPushFK(it));
const mappedCheckConstraints: string[] = checkConstraints.map((it) =>
it.replaceAll(`"${tableName}".`, `"${newTableName}".`)
.replaceAll(`\`${tableName}\`.`, `\`${newTableName}\`.`)
.replaceAll(`${tableName}.`, `${newTableName}.`)
.replaceAll(`'${tableName}'.`, `\`${newTableName}\`.`)
);
// create new table
statements.push(
new SQLiteCreateTableConvertor().convert({
type: 'sqlite_create_table',
tableName: newTableName,
columns: tableColumns,
referenceData: fks,
compositePKs,
checkConstraints: mappedCheckConstraints,
}),
);
// move data
if (!dataLoss) {
const columns = Object.keys(json.tables[tableName].columns).map(
(c) => `"${c}"`,
);
statements.push(
`INSERT INTO \`${newTableName}\`(${
columns.join(
', ',
)
}) SELECT ${columns.join(', ')} FROM \`${tableName}\`;`,
);
}
statements.push(
new SQLiteDropTableConvertor().convert({
type: 'drop_table',
tableName: tableName,
schema: '',
}),
);
// rename table
statements.push(
new SqliteRenameTableConvertor().convert({
fromSchema: '',
tableNameFrom: newTableName,
tableNameTo: tableName,
toSchema: '',
type: 'rename_table',
}),
);
for (const idx of Object.values(json.tables[tableName].indexes)) {
statements.push(
new CreateSqliteIndexConvertor().convert({
type: 'create_index',
tableName: tableName,
schema: '',
data: idx,
}),
);
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _moveDataStatements() do?
_moveDataStatements() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/libSqlPushUtils.ts.
Where is _moveDataStatements() defined?
_moveDataStatements() is defined in drizzle-kit/src/cli/commands/libSqlPushUtils.ts at line 28.
What calls _moveDataStatements()?
_moveDataStatements() is called by 1 function(s): libSqlLogSuggestionsAndReturn.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free