Add text indexes to various schemas for improved search capabilities
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Introduced text indexes in invoice, payment, tax record, and multiple inventory and management schemas to enhance search functionality. - Updated schemas include invoice, payment, tax record, filament stock, order item, part stock, product stock, purchase order, shipment, stock audit, stock event, stock location, stock transfer, app password, audit log, courier, courier service, document job, document printer, document size, document template, filament, filament SKU, file, host, material, note type, part, part SKU, product, product category, product SKU, tax rate, user, vendor, gcode file, job, printer, subjob, client, listing, listing variant, and marketplace schemas. - Improved search performance and flexibility across the application by leveraging text indexing.
This commit is contained in:
parent
0d395d3cb0
commit
4b2f4c4bf8
@ -54,6 +54,8 @@ const invoiceSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
invoiceSchema.index({ orderType: 'text', fromType: 'text', toType: 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'draft',
|
||||
|
||||
@ -24,6 +24,8 @@ const paymentSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
paymentSchema.index({ paymentMethod: 'text', notes: 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'draft',
|
||||
|
||||
@ -19,6 +19,8 @@ const taxRecordSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
taxRecordSchema.index({ transactionType: 'text' });
|
||||
|
||||
taxRecordSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -49,6 +49,8 @@ const filamentStockSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
filamentStockSchema.index({ 'state.type': 'text' });
|
||||
|
||||
filamentStockSchema.pre('validate', async function () {
|
||||
if (!this.filament && this.filamentSku) {
|
||||
const sku = await mongoose
|
||||
|
||||
@ -69,6 +69,8 @@ const orderItemSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
orderItemSchema.index({ name: 'text', itemType: 'text', orderType: 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'shipped',
|
||||
|
||||
@ -43,6 +43,8 @@ const partStockSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
partStockSchema.index({ sourceType: 'text', 'state.type': 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'totalCurrentQuantity',
|
||||
|
||||
@ -49,6 +49,8 @@ const productStockSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
productStockSchema.index({ 'state.type': 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'totalCurrentQuantity',
|
||||
|
||||
@ -25,6 +25,8 @@ const purchaseOrderSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
purchaseOrderSchema.index({ 'state.type': 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'draft',
|
||||
|
||||
@ -34,6 +34,8 @@ const shipmentSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
shipmentSchema.index({ trackingNumber: 'text', orderType: 'text' });
|
||||
|
||||
shipmentSchema.statics.recalculate = async function (shipment, user) {
|
||||
if (shipment.orderType !== 'purchaseOrder' && shipment.orderType !== 'salesOrder') {
|
||||
return;
|
||||
|
||||
@ -28,6 +28,8 @@ const stockAuditSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
stockAuditSchema.index({ type: 'text', status: 'text', notes: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
stockAuditSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -32,6 +32,8 @@ const stockEventSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
stockEventSchema.index({ parentType: 'text', ownerType: 'text', unit: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
stockEventSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -21,6 +21,8 @@ const stockLocationSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
stockLocationSchema.index({ name: 'text' });
|
||||
|
||||
stockLocationSchema.statics.stats = async function () {
|
||||
const total = await this.countDocuments({});
|
||||
return { total: { count: total } };
|
||||
|
||||
@ -48,6 +48,8 @@ const stockTransferSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
stockTransferSchema.index({ name: 'text' });
|
||||
|
||||
stockTransferSchema.statics.stats = async function () {
|
||||
const [draft, posted] = await Promise.all([
|
||||
this.countDocuments({ 'state.type': 'draft' }),
|
||||
|
||||
@ -13,6 +13,8 @@ const appPasswordSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
appPasswordSchema.index({ name: 'text' });
|
||||
|
||||
appPasswordSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -36,6 +36,8 @@ const auditLogSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
auditLogSchema.index({ operation: 'text', parentType: 'text', ownerType: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
auditLogSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -14,6 +14,8 @@ const courierSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
courierSchema.index({ name: 'text', website: 'text', email: 'text', phone: 'text', contact: 'text', country: 'text' });
|
||||
|
||||
courierSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -15,6 +15,8 @@ const courierServiceSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
courierServiceSchema.index({ name: 'text', website: 'text' });
|
||||
|
||||
courierServiceSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -39,6 +39,8 @@ const documentJobSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
documentJobSchema.index({ name: 'text', objectType: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
documentJobSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -38,6 +38,8 @@ const documentPrinterSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
documentPrinterSchema.index({ name: 'text', tags: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
documentPrinterSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -29,6 +29,8 @@ const documentSizeSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
documentSizeSchema.index({ name: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
documentSizeSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -52,6 +52,8 @@ const documentTemplateSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
documentTemplateSchema.index({ name: 'text', tags: 'text', objectType: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
documentTemplateSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -18,6 +18,8 @@ const filamentSchema = new mongoose.Schema({
|
||||
costWithTax: { type: Number, required: false },
|
||||
}, { timestamps: true });
|
||||
|
||||
filamentSchema.index({ name: 'text', barcode: 'text', url: 'text' });
|
||||
|
||||
filamentSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -19,6 +19,8 @@ const filamentSkuSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
filamentSkuSchema.index({ name: 'text', barcode: 'text', description: 'text', color: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
filamentSkuSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -13,6 +13,8 @@ const fileSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
fileSchema.index({ name: 'text', type: 'text', extension: 'text' });
|
||||
|
||||
fileSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -63,6 +63,8 @@ const hostSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
hostSchema.index({ name: 'text', tags: 'text' });
|
||||
|
||||
hostSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -11,6 +11,8 @@ const materialSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
materialSchema.index({ name: 'text', url: 'text', tags: 'text' });
|
||||
|
||||
materialSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -23,6 +23,8 @@ const noteTypeSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
noteTypeSchema.index({ name: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
noteTypeSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -21,6 +21,8 @@ const partSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
partSchema.index({ name: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
partSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -25,6 +25,8 @@ const partSkuSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
partSkuSchema.index({ name: 'text', barcode: 'text', description: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
partSkuSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -23,6 +23,9 @@ const productSchema = new Schema(
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
productSchema.index({ name: 'text', tags: 'text', version: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
productSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -9,6 +9,8 @@ const productCategorySchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
productCategorySchema.index({ name: 'text' });
|
||||
|
||||
productCategorySchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -32,6 +32,8 @@ const productSkuSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
productSkuSchema.index({ name: 'text', barcode: 'text', description: 'text' });
|
||||
|
||||
// Add virtual id getter
|
||||
productSkuSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -16,6 +16,8 @@ const taxRateSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
taxRateSchema.index({ name: 'text', description: 'text', country: 'text' });
|
||||
|
||||
taxRateSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -15,6 +15,8 @@ const userSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
userSchema.index({ username: 'text', name: 'text', firstName: 'text', lastName: 'text', email: 'text' });
|
||||
|
||||
userSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -26,6 +26,8 @@ const vendorSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
vendorSchema.index({ name: 'text', website: 'text', email: 'text', phone: 'text', contact: 'text', country: 'text' });
|
||||
|
||||
vendorSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -30,7 +30,7 @@ gcodeFileSchema.pre('validate', async function () {
|
||||
}
|
||||
});
|
||||
|
||||
gcodeFileSchema.index({ name: 'text', brand: 'text' });
|
||||
gcodeFileSchema.index({ name: 'text', gcodeFileName: 'text' });
|
||||
|
||||
gcodeFileSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
|
||||
@ -32,6 +32,8 @@ const jobSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
jobSchema.index({ 'state.type': 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'queued',
|
||||
|
||||
@ -57,6 +57,8 @@ const printerSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
printerSchema.index({ name: 'text', tags: 'text', firmware: 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'standby',
|
||||
|
||||
@ -43,6 +43,8 @@ const subJobSchema = new mongoose.Schema({
|
||||
finishedAt: { required: false, type: Date, default: null },
|
||||
});
|
||||
|
||||
subJobSchema.index({ moonrakerJobId: 'text', 'state.type': 'text' });
|
||||
|
||||
subJobSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -26,6 +26,8 @@ const clientSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
clientSchema.index({ name: 'text', email: 'text', phone: 'text', country: 'text', tags: 'text' });
|
||||
|
||||
clientSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -26,6 +26,8 @@ const listingSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
listingSchema.index({ title: 'text', url: 'text' });
|
||||
|
||||
listingSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -25,6 +25,8 @@ const listingVarientSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
listingVarientSchema.index({ currency: 'text', 'state.type': 'text' });
|
||||
|
||||
listingVarientSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -28,6 +28,8 @@ const marketplaceSchema = new mongoose.Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
marketplaceSchema.index({ name: 'text', provider: 'text' });
|
||||
|
||||
marketplaceSchema.virtual('id').get(function () {
|
||||
return this._id;
|
||||
});
|
||||
|
||||
@ -30,6 +30,8 @@ const salesOrderSchema = new Schema(
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
salesOrderSchema.index({ 'state.type': 'text' });
|
||||
|
||||
const rollupConfigs = [
|
||||
{
|
||||
name: 'draft',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user