Files
klz-cables.com/.pnpm-store/v10/files/9d/555ef3d7511a824a0a11c7fcbaa5a10f12ccf2bca8b98ae77e90e71c438b1c3248911db36e6e097312ca1831ef24473fbb34275a645a6dd83230f1d4ca9369
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

83 lines
3.2 KiB
Plaintext

import { dequal } from 'dequal';
import prompts from 'prompts';
const previousSchema = {
localeCodes: null,
rawTables: null
};
/**
* Pushes the development schema to the database using Drizzle.
*
* @param {DrizzleAdapter} adapter - The PostgresAdapter instance connected to the database.
* @returns {Promise<void>} - A promise that resolves once the schema push is complete.
*/ export const pushDevSchema = async (adapter)=>{
if (process.env.PAYLOAD_FORCE_DRIZZLE_PUSH !== 'true') {
const localeCodes = adapter.payload.config.localization && adapter.payload.config.localization.localeCodes;
const equal = dequal(previousSchema, {
localeCodes,
rawTables: adapter.rawTables
});
if (equal) {
if (adapter.logger) {
adapter.payload.logger.info('No changes detected in schema, skipping schema push.');
}
return;
} else {
previousSchema.localeCodes = localeCodes;
previousSchema.rawTables = adapter.rawTables;
}
}
const { pushSchema } = adapter.requireDrizzleKit();
const { extensions = {}, tablesFilter } = adapter;
// This will prompt if clarifications are needed for Drizzle to push new schema
const { apply, hasDataLoss, warnings } = await pushSchema(adapter.schema, adapter.drizzle, adapter.schemaName ? [
adapter.schemaName
] : undefined, tablesFilter, // Drizzle extensionsFilter supports only postgis for now
// https://github.com/drizzle-team/drizzle-orm/blob/83daf2d5cf023112de878bc2249ee2c41a2a5b1b/drizzle-kit/src/cli/validations/cli.ts#L26
extensions.postgis ? [
'postgis'
] : undefined);
if (warnings.length) {
let message = `Warnings detected during schema push: \n\n${warnings.join('\n')}\n\n`;
if (hasDataLoss) {
message += `DATA LOSS WARNING: Possible data loss detected if schema is pushed.\n\n`;
}
message += `Accept warnings and push schema to database?`;
const { confirm: acceptWarnings } = await prompts({
name: 'confirm',
type: 'confirm',
initial: false,
message
}, {
onCancel: ()=>{
process.exit(0);
}
});
// Exit if user does not accept warnings.
// Q: Is this the right type of exit for this interaction?
if (!acceptWarnings) {
process.exit(0);
}
}
await apply();
const migrationsTable = adapter.schemaName ? `"${adapter.schemaName}"."payload_migrations"` : '"payload_migrations"';
const drizzle = adapter.drizzle;
const result = await adapter.execute({
drizzle,
raw: `SELECT * FROM ${migrationsTable} WHERE batch = '-1'`
});
const devPush = result.rows;
if (!devPush.length) {
// Use drizzle for insert so $defaultFn's are called
await drizzle.insert(adapter.tables.payload_migrations).values({
name: 'dev',
batch: -1
});
} else {
await adapter.execute({
drizzle,
raw: `UPDATE ${migrationsTable} SET updated_at = CURRENT_TIMESTAMP WHERE batch = '-1'`
});
}
};
//# sourceMappingURL=pushDevSchema.js.map