writeResult() — drizzle-orm Function Reference
Architecture documentation for the writeResult() function in migrate.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD cb2d3951_4fcb_d824_359b_9f044d2f7e6c["writeResult()"] b14d3855_8cce_38c9_8952_a9d014c2fb1b["migrate.ts"] cb2d3951_4fcb_d824_359b_9f044d2f7e6c -->|defined in| b14d3855_8cce_38c9_8952_a9d014c2fb1b d532b567_3dc6_7be3_0c7e_e6f3a15eddff["introspectPostgres()"] d532b567_3dc6_7be3_0c7e_e6f3a15eddff -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 395c56cc_0c49_0b4c_347d_abe47b81589f["introspectGel()"] 395c56cc_0c49_0b4c_347d_abe47b81589f -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 50854fb8_da44_d90e_33cd_3524dcf8268c["introspectMysql()"] 50854fb8_da44_d90e_33cd_3524dcf8268c -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 7d387948_d073_7138_a827_23cf000dc9bc["introspectSingleStore()"] 7d387948_d073_7138_a827_23cf000dc9bc -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 48e57773_0c49_6169_cb5a_31a468e64025["introspectSqlite()"] 48e57773_0c49_6169_cb5a_31a468e64025 -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 49e2c573_17ba_89fe_104a_c5be22a2db77["introspectLibSQL()"] 49e2c573_17ba_89fe_104a_c5be22a2db77 -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 285d7baa_1c76_20e1_0c68_26eaff3a4a05["prepareAndMigratePg()"] 285d7baa_1c76_20e1_0c68_26eaff3a4a05 -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 41b84052_7d33_8f63_3c95_ec57735ef60e["prepareAndMigrateMysql()"] 41b84052_7d33_8f63_3c95_ec57735ef60e -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c d3966aac_3570_4a25_bd4d_13770b298d13["prepareAndMigrateSingleStore()"] d3966aac_3570_4a25_bd4d_13770b298d13 -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c 34d42b06_7a19_f47a_1ff9_7b6752ce0bda["prepareAndMigrateSqlite()"] 34d42b06_7a19_f47a_1ff9_7b6752ce0bda -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c fb79a54b_99a5_2063_0a0c_a9cc728865a9["prepareAndMigrateLibSQL()"] fb79a54b_99a5_2063_0a0c_a9cc728865a9 -->|calls| cb2d3951_4fcb_d824_359b_9f044d2f7e6c dd999a0b_2e45_a358_d4ac_692136f9cd09["schema()"] cb2d3951_4fcb_d824_359b_9f044d2f7e6c -->|calls| dd999a0b_2e45_a358_d4ac_692136f9cd09 21a2b027_f99c_d889_2b99_967e43eec3c1["prepareMigrationMetadata()"] cb2d3951_4fcb_d824_359b_9f044d2f7e6c -->|calls| 21a2b027_f99c_d889_2b99_967e43eec3c1 style cb2d3951_4fcb_d824_359b_9f044d2f7e6c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/cli/commands/migrate.ts lines 1356–1458
export const writeResult = ({
cur,
sqlStatements,
journal,
_meta = {
columns: {},
schemas: {},
tables: {},
},
outFolder,
breakpoints,
name,
bundle = false,
type = 'none',
prefixMode,
driver,
}: {
cur: CommonSchema;
sqlStatements: string[];
journal: Journal;
_meta?: any;
outFolder: string;
breakpoints: boolean;
prefixMode: Prefix;
name?: string;
bundle?: boolean;
type?: 'introspect' | 'custom' | 'none';
driver?: Driver;
}) => {
if (type === 'none') {
console.log(schema(cur));
if (sqlStatements.length === 0) {
console.log('No schema changes, nothing to migrate 😴');
return;
}
}
// append entry to _migrations.json
// append entry to _journal.json->entries
// dialect in _journal.json
// append sql file to out folder
// append snapshot file to meta folder
const lastEntryInJournal = journal.entries[journal.entries.length - 1];
const idx = typeof lastEntryInJournal === 'undefined' ? 0 : lastEntryInJournal.idx + 1;
const { prefix, tag } = prepareMigrationMetadata(idx, prefixMode, name);
const toSave = JSON.parse(JSON.stringify(cur));
toSave['_meta'] = _meta;
// todo: save results to a new migration folder
const metaFolderPath = join(outFolder, 'meta');
const metaJournal = join(metaFolderPath, '_journal.json');
fs.writeFileSync(
join(metaFolderPath, `${prefix}_snapshot.json`),
JSON.stringify(toSave, null, 2),
);
const sqlDelimiter = breakpoints ? BREAKPOINT : '\n';
let sql = sqlStatements.join(sqlDelimiter);
if (type === 'introspect') {
sql =
`-- Current sql file was generated after introspecting the database\n-- If you want to run this migration please uncomment this code before executing migrations\n/*\n${sql}\n*/`;
}
if (type === 'custom') {
console.log('Prepared empty file for your custom SQL migration!');
sql = '-- Custom SQL migration file, put your code below! --';
}
journal.entries.push({
idx,
version: cur.version,
when: +new Date(),
tag,
breakpoints: breakpoints,
});
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does writeResult() do?
writeResult() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/migrate.ts.
Where is writeResult() defined?
writeResult() is defined in drizzle-kit/src/cli/commands/migrate.ts at line 1356.
What does writeResult() call?
writeResult() calls 3 function(s): embeddedMigrations, prepareMigrationMetadata, schema.
What calls writeResult()?
writeResult() is called by 11 function(s): introspectGel, introspectLibSQL, introspectMysql, introspectPostgres, introspectSingleStore, introspectSqlite, prepareAndMigrateLibSQL, prepareAndMigrateMysql, and 3 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free