MCPcopy
hub / github.com/drizzle-team/drizzle-orm / pushSQLiteSchema

Function pushSQLiteSchema

drizzle-kit/src/api.ts:270–327  ·  view source on GitHub ↗
(
	imports: Record<string, unknown>,
	drizzleInstance: LibSQLDatabase<any>,
)

Source from the content-addressed store, hash-verified

268};
269
270export const pushSQLiteSchema = async (
271 imports: Record<string, unknown>,
272 drizzleInstance: LibSQLDatabase<any>,
273) => {
274 const { applySqliteSnapshotsDiff } = await import('./snapshotsDiffer');
275 const { sql } = await import('drizzle-orm');
276
277 const db: SQLiteDB = {
278 query: async (query: string, params?: any[]) => {
279 const res = drizzleInstance.all<any>(sql.raw(query));
280 return res;
281 },
282 run: async (query: string) => {
283 return Promise.resolve(drizzleInstance.run(sql.raw(query))).then(
284 () => {},
285 );
286 },
287 };
288
289 const cur = await generateSQLiteDrizzleJson(imports);
290 const { schema: prev } = await sqlitePushIntrospect(db, []);
291
292 const validatedPrev = sqliteSchema.parse(prev);
293 const validatedCur = sqliteSchema.parse(cur);
294
295 const squashedPrev = squashSqliteScheme(validatedPrev, 'push');
296 const squashedCur = squashSqliteScheme(validatedCur, 'push');
297
298 const { statements, _meta } = await applySqliteSnapshotsDiff(
299 squashedPrev,
300 squashedCur,
301 tablesResolver,
302 columnsResolver,
303 sqliteViewsResolver,
304 validatedPrev,
305 validatedCur,
306 'push',
307 );
308
309 const { shouldAskForApprove, statementsToExecute, infoToPrint } = await logSuggestionsAndReturn(
310 db,
311 statements,
312 squashedPrev,
313 squashedCur,
314 _meta!,
315 );
316
317 return {
318 hasDataLoss: shouldAskForApprove,
319 warnings: infoToPrint,
320 statementsToExecute,
321 apply: async () => {
322 for (const dStmnt of statementsToExecute) {
323 await db.query(dStmnt);
324 }
325 },
326 };
327};

Callers

nothing calls this directly

Calls 9

sqlitePushIntrospectFunction · 0.90
squashSqliteSchemeFunction · 0.90
logSuggestionsAndReturnFunction · 0.90
applySqliteSnapshotsDiffFunction · 0.85
allMethod · 0.45
thenMethod · 0.45
runMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected