Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(tagging-rules): add condition match mode to tagging rules (#601)

Corentin Thomasset16ae4617df26
diff --git a/.changeset/loud-apes-walk.md b/.changeset/loud-apes-walk.md
new file mode 100644
index 00000000..ea72b2f3
--- /dev/null
+++ b/.changeset/loud-apes-walk.md
@@ -0,0 +1,5 @@
+---
+"@papra/docker": patch
+---
+
+Added missing translations in the tagging rule form
diff --git a/.changeset/orange-readers-tap.md b/.changeset/orange-readers-tap.md
new file mode 100644
index 00000000..4952ec9d
--- /dev/null
+++ b/.changeset/orange-readers-tap.md
@@ -0,0 +1,5 @@
+---
+"@papra/docker": patch
+---
+
+Choose between `All conditions must match` and `Any condition must match` in tagging rules
diff --git a/apps/papra-client/src/locales/de.dictionary.ts b/apps/papra-client/src/locales/de.dictionary.ts
index b62d67a9..5d99b8ac 100644
--- a/apps/papra-client/src/locales/de.dictionary.ts
+++ b/apps/papra-client/src/locales/de.dictionary.ts
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Beispiel: Dokumente mit \'Rechnung\' im Namen taggen',
'tagging-rules.form.description.max-length': 'Die Beschreibung muss weniger als 256 Zeichen lang sein',
'tagging-rules.form.conditions.label': 'Bedingungen',
- 'tagging-rules.form.conditions.description': 'Definieren Sie die Bedingungen, die erfüllt sein müssen, damit die Regel angewendet wird. Alle Bedingungen müssen erfüllt sein, damit die Regel angewendet wird.',
+ 'tagging-rules.form.conditions.description': 'Definieren Sie die Bedingungen, die erfüllt sein müssen, damit die Regel angewendet wird. Keine Bedingungen bedeutet, dass die Regel auf alle Dokumente angewendet wird',
'tagging-rules.form.conditions.add-condition': 'Bedingung hinzufügen',
+ 'tagging-rules.form.conditions.connector.when': 'Wenn',
+ 'tagging-rules.form.conditions.connector.and': 'und',
+ 'tagging-rules.form.conditions.connector.or': 'oder',
+ 'tagging-rules.condition-match-mode.all': 'Alle Bedingungen müssen erfüllt sein',
+ 'tagging-rules.condition-match-mode.any': 'Mindestens eine Bedingung muss erfüllt sein',
'tagging-rules.form.conditions.no-conditions.title': 'Keine Bedingungen',
'tagging-rules.form.conditions.no-conditions.description': 'Sie haben dieser Regel keine Bedingungen hinzugefügt. Diese Regel wendet ihre Tags auf alle Dokumente an.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Regel ohne Bedingungen anwenden',
diff --git a/apps/papra-client/src/locales/en.dictionary.ts b/apps/papra-client/src/locales/en.dictionary.ts
index df0a1791..2383d2c5 100644
--- a/apps/papra-client/src/locales/en.dictionary.ts
+++ b/apps/papra-client/src/locales/en.dictionary.ts
@@ -385,8 +385,13 @@ export const translations = {
'tagging-rules.form.description.placeholder': 'Example: Tag documents with \'invoice\' in the name',
'tagging-rules.form.description.max-length': 'The description must be less than 256 characters',
'tagging-rules.form.conditions.label': 'Conditions',
- 'tagging-rules.form.conditions.description': 'Define the conditions that must be met for the rule to apply. All conditions must be met for the rule to apply.',
+ 'tagging-rules.form.conditions.description': 'Define the conditions that must be met for the rule to apply. No conditions means the rule will apply to all documents',
'tagging-rules.form.conditions.add-condition': 'Add condition',
+ 'tagging-rules.form.conditions.connector.when': 'When',
+ 'tagging-rules.form.conditions.connector.and': 'and',
+ 'tagging-rules.form.conditions.connector.or': 'or',
+ 'tagging-rules.condition-match-mode.all': 'All conditions must match',
+ 'tagging-rules.condition-match-mode.any': 'Any condition must match',
'tagging-rules.form.conditions.no-conditions.title': 'No conditions',
'tagging-rules.form.conditions.no-conditions.description': 'You didn\'t add any conditions to this rule. This rule will apply its tags to all documents.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Apply rule without conditions',
diff --git a/apps/papra-client/src/locales/es.dictionary.ts b/apps/papra-client/src/locales/es.dictionary.ts
index 4135bb3f..0c115fa8 100644
--- a/apps/papra-client/src/locales/es.dictionary.ts
+++ b/apps/papra-client/src/locales/es.dictionary.ts
@@ -356,8 +356,8 @@ export const translations: Partial<TranslationsDictionary> = {
// Tagging rules
- 'tagging-rules.field.name': 'nombre del documento',
- 'tagging-rules.field.content': 'contenido del documento',
+ 'tagging-rules.field.name': 'el nombre del documento',
+ 'tagging-rules.field.content': 'el contenido del documento',
'tagging-rules.operator.equals': 'es igual a',
'tagging-rules.operator.not-equals': 'no es igual a',
'tagging-rules.operator.contains': 'contiene',
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Ejemplo: Etiquetar documentos con \'factura\' en el nombre',
'tagging-rules.form.description.max-length': 'La descripción debe tener menos de 256 caracteres',
'tagging-rules.form.conditions.label': 'Condiciones',
- 'tagging-rules.form.conditions.description': 'Define las condiciones que deben cumplirse para que la regla se aplique. Todas las condiciones deben cumplirse.',
+ 'tagging-rules.form.conditions.description': 'Define las condiciones que deben cumplirse para que la regla se aplique. Sin condiciones significa que la regla se aplicará a todos los documentos',
'tagging-rules.form.conditions.add-condition': 'Añadir condición',
+ 'tagging-rules.form.conditions.connector.when': 'Cuando',
+ 'tagging-rules.form.conditions.connector.and': 'y que',
+ 'tagging-rules.form.conditions.connector.or': 'o que',
+ 'tagging-rules.condition-match-mode.all': 'Todas las condiciones deben coincidir',
+ 'tagging-rules.condition-match-mode.any': 'Cualquier condición debe coincidir',
'tagging-rules.form.conditions.no-conditions.title': 'Sin condiciones',
'tagging-rules.form.conditions.no-conditions.description': 'No añadiste ninguna condición a esta regla. Esta regla aplicará sus etiquetas a todos los documentos.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Aplicar regla sin condiciones',
diff --git a/apps/papra-client/src/locales/fr.dictionary.ts b/apps/papra-client/src/locales/fr.dictionary.ts
index f5d15dda..fb3e4ad0 100644
--- a/apps/papra-client/src/locales/fr.dictionary.ts
+++ b/apps/papra-client/src/locales/fr.dictionary.ts
@@ -356,8 +356,8 @@ export const translations: Partial<TranslationsDictionary> = {
// Tagging rules
- 'tagging-rules.field.name': 'nom du document',
- 'tagging-rules.field.content': 'contenu du document',
+ 'tagging-rules.field.name': 'le nom du document',
+ 'tagging-rules.field.content': 'le contenu du document',
'tagging-rules.operator.equals': 'égal à',
'tagging-rules.operator.not-equals': 'différent de',
'tagging-rules.operator.contains': 'contient',
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Exemple: Catégoriser les documents avec \'facture\' dans le nom',
'tagging-rules.form.description.max-length': 'La description doit contenir moins de 256 caractères',
'tagging-rules.form.conditions.label': 'Conditions',
- 'tagging-rules.form.conditions.description': 'Définissez les conditions que doivent remplir la règle pour qu\'elle s\'applique. Toutes les conditions doivent être remplies pour que la règle s\'applique.',
+ 'tagging-rules.form.conditions.description': 'Définissez les conditions que doivent remplir la règle pour qu\'elle s\'applique. Si aucune condition n\'est définie, la règle s\'appliquera à tous les documents.',
'tagging-rules.form.conditions.add-condition': 'Ajouter une condition',
+ 'tagging-rules.form.conditions.connector.when': 'Quand',
+ 'tagging-rules.form.conditions.connector.and': 'et que',
+ 'tagging-rules.form.conditions.connector.or': 'ou que',
+ 'tagging-rules.condition-match-mode.all': 'Toutes les conditions doivent correspondre',
+ 'tagging-rules.condition-match-mode.any': 'Au moins une condition doit correspondre',
'tagging-rules.form.conditions.no-conditions.title': 'Aucune condition',
'tagging-rules.form.conditions.no-conditions.description': 'Vous n\'avez pas ajouté de conditions à cette règle. Cette règle appliquera ses tags à tous les documents.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Appliquer la règle sans conditions',
diff --git a/apps/papra-client/src/locales/it.dictionary.ts b/apps/papra-client/src/locales/it.dictionary.ts
index f6946622..08cd9676 100644
--- a/apps/papra-client/src/locales/it.dictionary.ts
+++ b/apps/papra-client/src/locales/it.dictionary.ts
@@ -356,8 +356,8 @@ export const translations: Partial<TranslationsDictionary> = {
// Tagging rules
- 'tagging-rules.field.name': 'nome documento',
- 'tagging-rules.field.content': 'contenuto documento',
+ 'tagging-rules.field.name': 'il nome del documento',
+ 'tagging-rules.field.content': 'il contenuto del documento',
'tagging-rules.operator.equals': 'uguale a',
'tagging-rules.operator.not-equals': 'diverso da',
'tagging-rules.operator.contains': 'contiene',
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Esempio: Tagga i documenti con \'fattura\' nel nome',
'tagging-rules.form.description.max-length': 'La descrizione deve essere inferiore a 256 caratteri',
'tagging-rules.form.conditions.label': 'Condizioni',
- 'tagging-rules.form.conditions.description': 'Definisci le condizioni che devono essere soddisfatte affinché la regola si applichi. Tutte le condizioni devono essere soddisfatte.',
+ 'tagging-rules.form.conditions.description': 'Definisci le condizioni che devono essere soddisfatte affinché la regola si applichi. Nessuna condizione significa che la regola si applicherà a tutti i documenti',
'tagging-rules.form.conditions.add-condition': 'Aggiungi condizione',
+ 'tagging-rules.form.conditions.connector.when': 'Quando',
+ 'tagging-rules.form.conditions.connector.and': 'e che',
+ 'tagging-rules.form.conditions.connector.or': 'o che',
+ 'tagging-rules.condition-match-mode.all': 'Tutte le condizioni devono corrispondere',
+ 'tagging-rules.condition-match-mode.any': 'Qualsiasi condizione deve corrispondere',
'tagging-rules.form.conditions.no-conditions.title': 'Nessuna condizione',
'tagging-rules.form.conditions.no-conditions.description': 'Non hai aggiunto nessuna condizione a questa regola. Questa regola applicherà i suoi tag a tutti i documenti.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Applica regola senza condizioni',
diff --git a/apps/papra-client/src/locales/pl.dictionary.ts b/apps/papra-client/src/locales/pl.dictionary.ts
index 40d5bb0b..940ebd40 100644
--- a/apps/papra-client/src/locales/pl.dictionary.ts
+++ b/apps/papra-client/src/locales/pl.dictionary.ts
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Przykład: Oznacz dokumenty ze słowem \'faktura\' w nazwie',
'tagging-rules.form.description.max-length': 'Opis musi mieć mniej niż 256 znaków',
'tagging-rules.form.conditions.label': 'Warunki',
- 'tagging-rules.form.conditions.description': 'Zdefiniuj warunki, które muszą być spełnione, aby reguła mogła zostać zastosowana. Wszystkie warunki muszą być spełnione, aby reguła mogła zostać zastosowana.',
+ 'tagging-rules.form.conditions.description': 'Zdefiniuj warunki, które muszą być spełnione, aby reguła mogła zostać zastosowana. Brak warunków oznacza, że reguła zostanie zastosowana do wszystkich dokumentów',
'tagging-rules.form.conditions.add-condition': 'Dodaj warunek',
+ 'tagging-rules.form.conditions.connector.when': 'Kiedy',
+ 'tagging-rules.form.conditions.connector.and': 'i',
+ 'tagging-rules.form.conditions.connector.or': 'lub',
+ 'tagging-rules.condition-match-mode.all': 'Wszystkie warunki muszą być spełnione',
+ 'tagging-rules.condition-match-mode.any': 'Dowolny warunek musi być spełniony',
'tagging-rules.form.conditions.no-conditions.title': 'Brak warunków',
'tagging-rules.form.conditions.no-conditions.description': 'Nie dodałeś żadnych warunków do tej reguły. Ta reguła zastosuje swoje tagi do wszystkich dokumentów.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Zastosuj regułę bez warunków',
diff --git a/apps/papra-client/src/locales/pt-BR.dictionary.ts b/apps/papra-client/src/locales/pt-BR.dictionary.ts
index 56028cc9..ae96b310 100644
--- a/apps/papra-client/src/locales/pt-BR.dictionary.ts
+++ b/apps/papra-client/src/locales/pt-BR.dictionary.ts
@@ -356,8 +356,8 @@ export const translations: Partial<TranslationsDictionary> = {
// Tagging rules
- 'tagging-rules.field.name': 'nome do documento',
- 'tagging-rules.field.content': 'conteúdo do documento',
+ 'tagging-rules.field.name': 'o nome do documento',
+ 'tagging-rules.field.content': 'o conteúdo do documento',
'tagging-rules.operator.equals': 'é igual a',
'tagging-rules.operator.not-equals': 'é diferente de',
'tagging-rules.operator.contains': 'contém',
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Exemplo: Marcar documentos com \'fatura\' no nome',
'tagging-rules.form.description.max-length': 'A descrição deve ter menos de 256 caracteres',
'tagging-rules.form.conditions.label': 'Condições',
- 'tagging-rules.form.conditions.description': 'Defina as condições que devem ser atendidas para que a regra seja aplicada. Todas as condições devem ser atendidas.',
+ 'tagging-rules.form.conditions.description': 'Defina as condições que devem ser atendidas para que a regra seja aplicada. Sem condições significa que a regra será aplicada a todos os documentos',
'tagging-rules.form.conditions.add-condition': 'Adicionar condição',
+ 'tagging-rules.form.conditions.connector.when': 'Quando',
+ 'tagging-rules.form.conditions.connector.and': 'e que',
+ 'tagging-rules.form.conditions.connector.or': 'ou que',
+ 'tagging-rules.condition-match-mode.all': 'Todas as condições devem corresponder',
+ 'tagging-rules.condition-match-mode.any': 'Qualquer condição deve corresponder',
'tagging-rules.form.conditions.no-conditions.title': 'Nenhuma condição',
'tagging-rules.form.conditions.no-conditions.description': 'Você não adicionou nenhuma condição a esta regra. Ela será aplicada a todos os documentos.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Aplicar regra sem condições',
diff --git a/apps/papra-client/src/locales/pt.dictionary.ts b/apps/papra-client/src/locales/pt.dictionary.ts
index efa7471b..b66b04c5 100644
--- a/apps/papra-client/src/locales/pt.dictionary.ts
+++ b/apps/papra-client/src/locales/pt.dictionary.ts
@@ -356,8 +356,8 @@ export const translations: Partial<TranslationsDictionary> = {
// Tagging rules
- 'tagging-rules.field.name': 'nome do documento',
- 'tagging-rules.field.content': 'conteúdo do documento',
+ 'tagging-rules.field.name': 'o nome do documento',
+ 'tagging-rules.field.content': 'o conteúdo do documento',
'tagging-rules.operator.equals': 'igual a',
'tagging-rules.operator.not-equals': 'não igual a',
'tagging-rules.operator.contains': 'contém',
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Exemplo: Etiquetar documentos com \'fatura\' no nome',
'tagging-rules.form.description.max-length': 'A descrição deve ter menos de 256 caracteres',
'tagging-rules.form.conditions.label': 'Condições',
- 'tagging-rules.form.conditions.description': 'Defina as condições que devem ser cumpridas para a regra se aplicar. Todas as condições devem ser cumpridas para a regra se aplicar.',
+ 'tagging-rules.form.conditions.description': 'Defina as condições que devem ser cumpridas para a regra se aplicar. Sem condições significa que a regra será aplicada a todos os documentos',
'tagging-rules.form.conditions.add-condition': 'Adicionar condição',
+ 'tagging-rules.form.conditions.connector.when': 'Quando',
+ 'tagging-rules.form.conditions.connector.and': 'e que',
+ 'tagging-rules.form.conditions.connector.or': 'ou que',
+ 'tagging-rules.condition-match-mode.all': 'Todas as condições devem corresponder',
+ 'tagging-rules.condition-match-mode.any': 'Qualquer condição deve corresponder',
'tagging-rules.form.conditions.no-conditions.title': 'Sem condições',
'tagging-rules.form.conditions.no-conditions.description': 'Não adicionou nenhuma condição a esta regra. Esta regra aplicará as suas etiquetas a todos os documentos.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Aplicar regra sem condições',
diff --git a/apps/papra-client/src/locales/ro.dictionary.ts b/apps/papra-client/src/locales/ro.dictionary.ts
index e038cfec..dbb47c1d 100644
--- a/apps/papra-client/src/locales/ro.dictionary.ts
+++ b/apps/papra-client/src/locales/ro.dictionary.ts
@@ -356,8 +356,8 @@ export const translations: Partial<TranslationsDictionary> = {
// Tagging rules
- 'tagging-rules.field.name': 'nume document',
- 'tagging-rules.field.content': 'conținut document',
+ 'tagging-rules.field.name': 'numele documentului',
+ 'tagging-rules.field.content': 'conținutul documentului',
'tagging-rules.operator.equals': 'egal cu',
'tagging-rules.operator.not-equals': 'nu este egal cu',
'tagging-rules.operator.contains': 'conține',
@@ -387,8 +387,13 @@ export const translations: Partial<TranslationsDictionary> = {
'tagging-rules.form.description.placeholder': 'Exemplu: Etichetează documentele cu \'factură\' în nume',
'tagging-rules.form.description.max-length': 'Descrierea trebuie să aibă mai puțin de 256 de caractere',
'tagging-rules.form.conditions.label': 'Condiții',
- 'tagging-rules.form.conditions.description': 'Definește condițiile care trebuie îndeplinite pentru ca regula să se aplice. Toate condițiile trebuie îndeplinite pentru ca regula să se aplice.',
+ 'tagging-rules.form.conditions.description': 'Definește condițiile care trebuie îndeplinite pentru ca regula să se aplice. Fără condiții înseamnă că regula se va aplica tuturor documentelor',
'tagging-rules.form.conditions.add-condition': 'Adaugă condiție',
+ 'tagging-rules.form.conditions.connector.when': 'Când',
+ 'tagging-rules.form.conditions.connector.and': 'și că',
+ 'tagging-rules.form.conditions.connector.or': 'sau că',
+ 'tagging-rules.condition-match-mode.all': 'Toate condițiile trebuie îndeplinite',
+ 'tagging-rules.condition-match-mode.any': 'Orice condiție trebuie îndeplinită',
'tagging-rules.form.conditions.no-conditions.title': 'Nicio condiție',
'tagging-rules.form.conditions.no-conditions.description': 'Nu ai adăugat nicio condiție acestei reguli. Această regula va aplica etichetele sale tuturor documentelor.',
'tagging-rules.form.conditions.no-conditions.confirm': 'Aplică regula fara condiții',
diff --git a/apps/papra-client/src/modules/tagging-rules/components/tagging-rule-form.component.tsx b/apps/papra-client/src/modules/tagging-rules/components/tagging-rule-form.component.tsx
index a11e434d..b19ea361 100644
--- a/apps/papra-client/src/modules/tagging-rules/components/tagging-rule-form.component.tsx
+++ b/apps/papra-client/src/modules/tagging-rules/components/tagging-rule-form.component.tsx
@@ -1,6 +1,6 @@
import type { Component } from 'solid-js';
import type { TaggingRule, TaggingRuleForCreation } from '../tagging-rules.types';
-import { insert, remove, setValue } from '@modular-forms/solid';
+import { getValue, insert, remove, setValue } from '@modular-forms/solid';
import { A } from '@solidjs/router';
import { For, Show } from 'solid-js';
import * as v from 'valibot';
@@ -14,7 +14,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@
import { Separator } from '@/modules/ui/components/separator';
import { TextArea } from '@/modules/ui/components/textarea';
import { TextField, TextFieldLabel, TextFieldRoot } from '@/modules/ui/components/textfield';
-import { TAGGING_RULE_FIELDS, TAGGING_RULE_FIELDS_LOCALIZATION_KEYS, TAGGING_RULE_OPERATORS, TAGGING_RULE_OPERATORS_LOCALIZATION_KEYS } from '../tagging-rules.constants';
+import { CONDITION_MATCH_MODES, CONDITION_MATCH_MODES_LOCALIZATION_KEYS, TAGGING_RULE_FIELDS, TAGGING_RULE_FIELDS_LOCALIZATION_KEYS, TAGGING_RULE_OPERATORS, TAGGING_RULE_OPERATORS_LOCALIZATION_KEYS } from '../tagging-rules.constants';
export const TaggingRuleForm: Component<{
onSubmit: (args: { taggingRule: TaggingRuleForCreation }) => Promise<void> | void;
@@ -26,7 +26,7 @@ export const TaggingRuleForm: Component<{
const { confirm } = useConfirmModal();
const { form, Form, Field, FieldArray } = createForm({
- onSubmit: async ({ name, conditions = [], tagIds, description }) => {
+ onSubmit: async ({ name, conditions = [], tagIds, description, conditionMatchMode }) => {
if (conditions.length === 0) {
const confirmed = await confirm({
title: t('tagging-rules.form.conditions.no-conditions.title'),
@@ -45,7 +45,7 @@ export const TaggingRuleForm: Component<{
}
}
- props.onSubmit({ taggingRule: { name, conditions, tagIds, description } });
+ props.onSubmit({ taggingRule: { name, conditions, tagIds, description, conditionMatchMode } });
},
schema: v.object({
name: v.pipe(
@@ -57,6 +57,7 @@ export const TaggingRuleForm: Component<{
v.string(),
v.maxLength(256, t('tagging-rules.form.description.max-length')),
),
+ conditionMatchMode: v.optional(v.picklist(Object.values(CONDITION_MATCH_MODES))),
conditions: v.optional(
v.array(v.object({
field: v.picklist(Object.values(TAGGING_RULE_FIELDS)),
@@ -77,6 +78,7 @@ export const TaggingRuleForm: Component<{
tagIds: props.taggingRule?.actions.map(action => action.tagId) ?? [],
name: props.taggingRule?.name,
description: props.taggingRule?.description,
+ conditionMatchMode: props.taggingRule?.conditionMatchMode ?? CONDITION_MATCH_MODES.ALL,
},
});
@@ -88,6 +90,20 @@ export const TaggingRuleForm: Component<{
return t(TAGGING_RULE_FIELDS_LOCALIZATION_KEYS[field as keyof typeof TAGGING_RULE_FIELDS_LOCALIZATION_KEYS]);
};
+ const getConditionConnector = (index: number) => {
+ if (index === 0) {
+ return t('tagging-rules.form.conditions.connector.when');
+ }
+
+ const conditionMatchMode = getValue(form, 'conditionMatchMode');
+
+ if (conditionMatchMode === CONDITION_MATCH_MODES.ALL) {
+ return t('tagging-rules.form.conditions.connector.and');
+ }
+
+ return t('tagging-rules.form.conditions.connector.or');
+ };
+
return (
<Form>
<Field name="name">
@@ -126,13 +142,34 @@ export const TaggingRuleForm: Component<{
<p class="mb-1 font-medium">{t('tagging-rules.form.conditions.label')}</p>
<p class="mb-2 text-sm text-muted-foreground">{t('tagging-rules.form.conditions.description')}</p>
+ <Field name="conditionMatchMode">
+ {field => (
+ <Select
+ id="conditionMatchMode"
+ defaultValue={field.value ?? CONDITION_MATCH_MODES.ALL}
+ onChange={value => value && setValue(form, 'conditionMatchMode', value)}
+ options={Object.values(CONDITION_MATCH_MODES)}
+ itemComponent={props => (
+ <SelectItem item={props.item}>
+ {t(CONDITION_MATCH_MODES_LOCALIZATION_KEYS[props.item.rawValue as keyof typeof CONDITION_MATCH_MODES_LOCALIZATION_KEYS])}
+ </SelectItem>
+ )}
+ >
+ <SelectTrigger class="w-full mb-4">
+ <SelectValue<string>>{state => t(CONDITION_MATCH_MODES_LOCALIZATION_KEYS[state.selectedOption() as keyof typeof CONDITION_MATCH_MODES_LOCALIZATION_KEYS])}</SelectValue>
+ </SelectTrigger>
+ <SelectContent />
+ </Select>
+ )}
+ </Field>
+
<FieldArray name="conditions">
{fieldArray => (
<div>
<For each={fieldArray.items}>
{(_, index) => (
<div class="px-4 py-4 mb-1 flex gap-2 items-center bg-card border rounded-md">
- <div>When</div>
+ <div>{getConditionConnector(index())}</div>
<Field name={`conditions.${index()}.field`}>
{field => (
diff --git a/apps/papra-client/src/modules/tagging-rules/tagging-rules.constants.ts b/apps/papra-client/src/modules/tagging-rules/tagging-rules.constants.ts
index bbf28a78..66067ada 100644
--- a/apps/papra-client/src/modules/tagging-rules/tagging-rules.constants.ts
+++ b/apps/papra-client/src/modules/tagging-rules/tagging-rules.constants.ts
@@ -27,3 +27,13 @@ export const TAGGING_RULE_FIELDS_LOCALIZATION_KEYS: Record<(typeof TAGGING_RULE_
[TAGGING_RULE_FIELDS.DOCUMENT_NAME]: 'tagging-rules.field.name',
[TAGGING_RULE_FIELDS.DOCUMENT_CONTENT]: 'tagging-rules.field.content',
} as const;
+
+export const CONDITION_MATCH_MODES = {
+ ALL: 'all',
+ ANY: 'any',
+} as const;
+
+export const CONDITION_MATCH_MODES_LOCALIZATION_KEYS: Record<(typeof CONDITION_MATCH_MODES)[keyof typeof CONDITION_MATCH_MODES], TranslationKeys> = {
+ [CONDITION_MATCH_MODES.ALL]: 'tagging-rules.condition-match-mode.all',
+ [CONDITION_MATCH_MODES.ANY]: 'tagging-rules.condition-match-mode.any',
+} as const;
diff --git a/apps/papra-client/src/modules/tagging-rules/tagging-rules.types.ts b/apps/papra-client/src/modules/tagging-rules/tagging-rules.types.ts
index 5a329b53..8bac0e6c 100644
--- a/apps/papra-client/src/modules/tagging-rules/tagging-rules.types.ts
+++ b/apps/papra-client/src/modules/tagging-rules/tagging-rules.types.ts
@@ -1,8 +1,11 @@
-import type { TAGGING_RULE_FIELDS, TAGGING_RULE_OPERATORS } from './tagging-rules.constants';
+import type { CONDITION_MATCH_MODES, TAGGING_RULE_FIELDS, TAGGING_RULE_OPERATORS } from './tagging-rules.constants';
+
+export type ConditionMatchMode = (typeof CONDITION_MATCH_MODES)[keyof typeof CONDITION_MATCH_MODES];
export type TaggingRuleForCreation = {
name: string;
description: string;
+ conditionMatchMode?: ConditionMatchMode;
conditions: TaggingRuleCondition[];
tagIds: string[];
};
@@ -17,6 +20,7 @@ export type TaggingRule = {
id: string;
name: string;
description: string;
+ conditionMatchMode?: ConditionMatchMode;
conditions: TaggingRuleCondition[];
actions: { tagId: string }[];
organizationId: string;
diff --git a/apps/papra-server/package.json b/apps/papra-server/package.json
index 6376520d..d1c4acea 100644
--- a/apps/papra-server/package.json
+++ b/apps/papra-server/package.json
@@ -23,6 +23,7 @@
"test:int:pull-images": "tsx --env-file-if-exists=.env src/scripts/pull-test-container-images.script.ts | crowlog-pretty",
"typecheck": "tsc --noEmit",
"migrate:up": "tsx --env-file-if-exists=.env src/scripts/migrate-up.script.ts | crowlog-pretty",
+ "migrate:down": "tsx --env-file-if-exists=.env src/scripts/migrate-down.script.ts | crowlog-pretty",
"migrate:up:prod": "tsx src/scripts/migrate-up.script.ts",
"migrate:push": "drizzle-kit push",
"migrate:create": "sh -c 'drizzle-kit generate --name \"$1\" && tsx --env-file-if-exists=.env src/scripts/create-migration.ts \"$1\" | crowlog-pretty' --",
diff --git a/apps/papra-server/src/migrations/list/0012-tagging-rule-condition-match-mode.migration.ts b/apps/papra-server/src/migrations/list/0012-tagging-rule-condition-match-mode.migration.ts
new file mode 100644
index 00000000..cda9bcc6
--- /dev/null
+++ b/apps/papra-server/src/migrations/list/0012-tagging-rule-condition-match-mode.migration.ts
@@ -0,0 +1,20 @@
+import type { Migration } from '../migrations.types';
+import { sql } from 'drizzle-orm';
+
+export const taggingRuleConditionMatchModeMigration = {
+ name: 'tagging-rule-condition-match-mode',
+
+ up: async ({ db }) => {
+ const tableInfo = await db.run(sql`PRAGMA table_info(tagging_rules)`);
+ const existingColumns = tableInfo.rows.map(row => row.name);
+ const hasColumn = (columnName: string) => existingColumns.includes(columnName);
+
+ if (!hasColumn('condition_match_mode')) {
+ await db.run(sql`ALTER TABLE "tagging_rules" ADD "condition_match_mode" text DEFAULT 'all' NOT NULL;`);
+ }
+ },
+
+ down: async ({ db }) => {
+ await db.run(sql`ALTER TABLE "tagging_rules" DROP COLUMN "condition_match_mode";`);
+ },
+} satisfies Migration;
diff --git a/apps/papra-server/src/migrations/meta/0011_snapshot.json b/apps/papra-server/src/migrations/meta/0011_snapshot.json
new file mode 100644
index 00000000..166372ad
--- /dev/null
+++ b/apps/papra-server/src/migrations/meta/0011_snapshot.json
@@ -0,0 +1,2058 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "7407bb9b-b179-4a4c-89c6-ac869979f836",
+ "prevId": "1c4a2eb0-efbe-486d-a4ea-44768fbdfeff",
+ "tables": {
+ "document_activity_log": {
+ "name": "document_activity_log",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "document_id": {
+ "name": "document_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "event": {
+ "name": "event",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "event_data": {
+ "name": "event_data",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "tag_id": {
+ "name": "tag_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "document_activity_log_document_id_documents_id_fk": {
+ "name": "document_activity_log_document_id_documents_id_fk",
+ "tableFrom": "document_activity_log",
+ "tableTo": "documents",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "document_activity_log_user_id_users_id_fk": {
+ "name": "document_activity_log_user_id_users_id_fk",
+ "tableFrom": "document_activity_log",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ },
+ "document_activity_log_tag_id_tags_id_fk": {
+ "name": "document_activity_log_tag_id_tags_id_fk",
+ "tableFrom": "document_activity_log",
+ "tableTo": "tags",
+ "columnsFrom": [
+ "tag_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "documents": {
+ "name": "documents",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_by": {
+ "name": "created_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "original_name": {
+ "name": "original_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "original_size": {
+ "name": "original_size",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "original_storage_key": {
+ "name": "original_storage_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "original_sha256_hash": {
+ "name": "original_sha256_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mime_type": {
+ "name": "mime_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "file_encryption_key_wrapped": {
+ "name": "file_encryption_key_wrapped",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "file_encryption_kek_version": {
+ "name": "file_encryption_kek_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "file_encryption_algorithm": {
+ "name": "file_encryption_algorithm",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "deleted_at": {
+ "name": "deleted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "deleted_by": {
+ "name": "deleted_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "is_deleted": {
+ "name": "is_deleted",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ }
+ },
+ "indexes": {
+ "documents_organization_id_is_deleted_created_at_index": {
+ "name": "documents_organization_id_is_deleted_created_at_index",
+ "columns": [
+ "organization_id",
+ "is_deleted",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "documents_organization_id_is_deleted_index": {
+ "name": "documents_organization_id_is_deleted_index",
+ "columns": [
+ "organization_id",
+ "is_deleted"
+ ],
+ "isUnique": false
+ },
+ "documents_organization_id_original_sha256_hash_unique": {
+ "name": "documents_organization_id_original_sha256_hash_unique",
+ "columns": [
+ "organization_id",
+ "original_sha256_hash"
+ ],
+ "isUnique": true
+ },
+ "documents_original_sha256_hash_index": {
+ "name": "documents_original_sha256_hash_index",
+ "columns": [
+ "original_sha256_hash"
+ ],
+ "isUnique": false
+ },
+ "documents_organization_id_size_index": {
+ "name": "documents_organization_id_size_index",
+ "columns": [
+ "organization_id",
+ "original_size"
+ ],
+ "isUnique": false
+ },
+ "documents_file_encryption_kek_version_index": {
+ "name": "documents_file_encryption_kek_version_index",
+ "columns": [
+ "file_encryption_kek_version"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "documents_organization_id_organizations_id_fk": {
+ "name": "documents_organization_id_organizations_id_fk",
+ "tableFrom": "documents",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "documents_created_by_users_id_fk": {
+ "name": "documents_created_by_users_id_fk",
+ "tableFrom": "documents",
+ "tableTo": "users",
+ "columnsFrom": [
+ "created_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ },
+ "documents_deleted_by_users_id_fk": {
+ "name": "documents_deleted_by_users_id_fk",
+ "tableFrom": "documents",
+ "tableTo": "users",
+ "columnsFrom": [
+ "deleted_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "organization_invitations": {
+ "name": "organization_invitations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "inviter_id": {
+ "name": "inviter_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "organization_invitations_organization_email_unique": {
+ "name": "organization_invitations_organization_email_unique",
+ "columns": [
+ "organization_id",
+ "email"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "organization_invitations_organization_id_organizations_id_fk": {
+ "name": "organization_invitations_organization_id_organizations_id_fk",
+ "tableFrom": "organization_invitations",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "organization_invitations_inviter_id_users_id_fk": {
+ "name": "organization_invitations_inviter_id_users_id_fk",
+ "tableFrom": "organization_invitations",
+ "tableTo": "users",
+ "columnsFrom": [
+ "inviter_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "organization_members": {
+ "name": "organization_members",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "organization_members_user_organization_unique": {
+ "name": "organization_members_user_organization_unique",
+ "columns": [
+ "organization_id",
+ "user_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "organization_members_organization_id_organizations_id_fk": {
+ "name": "organization_members_organization_id_organizations_id_fk",
+ "tableFrom": "organization_members",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "organization_members_user_id_users_id_fk": {
+ "name": "organization_members_user_id_users_id_fk",
+ "tableFrom": "organization_members",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "organizations": {
+ "name": "organizations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "customer_id": {
+ "name": "customer_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "deleted_at": {
+ "name": "deleted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "deleted_by": {
+ "name": "deleted_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scheduled_purge_at": {
+ "name": "scheduled_purge_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "organizations_deleted_at_purge_at_index": {
+ "name": "organizations_deleted_at_purge_at_index",
+ "columns": [
+ "deleted_at",
+ "scheduled_purge_at"
+ ],
+ "isUnique": false
+ },
+ "organizations_deleted_by_deleted_at_index": {
+ "name": "organizations_deleted_by_deleted_at_index",
+ "columns": [
+ "deleted_by",
+ "deleted_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "organizations_deleted_by_users_id_fk": {
+ "name": "organizations_deleted_by_users_id_fk",
+ "tableFrom": "organizations",
+ "tableTo": "users",
+ "columnsFrom": [
+ "deleted_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "user_roles": {
+ "name": "user_roles",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "user_roles_role_index": {
+ "name": "user_roles_role_index",
+ "columns": [
+ "role"
+ ],
+ "isUnique": false
+ },
+ "user_roles_user_id_role_unique_index": {
+ "name": "user_roles_user_id_role_unique_index",
+ "columns": [
+ "user_id",
+ "role"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "user_roles_user_id_users_id_fk": {
+ "name": "user_roles_user_id_users_id_fk",
+ "tableFrom": "user_roles",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "documents_tags": {
+ "name": "documents_tags",
+ "columns": {
+ "document_id": {
+ "name": "document_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tag_id": {
+ "name": "tag_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "documents_tags_document_id_documents_id_fk": {
+ "name": "documents_tags_document_id_documents_id_fk",
+ "tableFrom": "documents_tags",
+ "tableTo": "documents",
+ "columnsFrom": [
+ "document_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "documents_tags_tag_id_tags_id_fk": {
+ "name": "documents_tags_tag_id_tags_id_fk",
+ "tableFrom": "documents_tags",
+ "tableTo": "tags",
+ "columnsFrom": [
+ "tag_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {
+ "documents_tags_pkey": {
+ "columns": [
+ "document_id",
+ "tag_id"
+ ],
+ "name": "documents_tags_pkey"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "tags": {
+ "name": "tags",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "tags_organization_id_name_unique": {
+ "name": "tags_organization_id_name_unique",
+ "columns": [
+ "organization_id",
+ "name"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "tags_organization_id_organizations_id_fk": {
+ "name": "tags_organization_id_organizations_id_fk",
+ "tableFrom": "tags",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "users": {
+ "name": "users",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email_verified": {
+ "name": "email_verified",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "image": {
+ "name": "image",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "max_organization_count": {
+ "name": "max_organization_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "users_email_unique": {
+ "name": "users_email_unique",
+ "columns": [
+ "email"
+ ],
+ "isUnique": true
+ },
+ "users_email_index": {
+ "name": "users_email_index",
+ "columns": [
+ "email"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "api_key_organizations": {
+ "name": "api_key_organizations",
+ "columns": {
+ "api_key_id": {
+ "name": "api_key_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_member_id": {
+ "name": "organization_member_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "api_key_organizations_api_key_id_api_keys_id_fk": {
+ "name": "api_key_organizations_api_key_id_api_keys_id_fk",
+ "tableFrom": "api_key_organizations",
+ "tableTo": "api_keys",
+ "columnsFrom": [
+ "api_key_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "api_key_organizations_organization_member_id_organization_members_id_fk": {
+ "name": "api_key_organizations_organization_member_id_organization_members_id_fk",
+ "tableFrom": "api_key_organizations",
+ "tableTo": "organization_members",
+ "columnsFrom": [
+ "organization_member_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "api_keys": {
+ "name": "api_keys",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "key_hash": {
+ "name": "key_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "prefix": {
+ "name": "prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_used_at": {
+ "name": "last_used_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "permissions": {
+ "name": "permissions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "all_organizations": {
+ "name": "all_organizations",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ }
+ },
+ "indexes": {
+ "api_keys_key_hash_unique": {
+ "name": "api_keys_key_hash_unique",
+ "columns": [
+ "key_hash"
+ ],
+ "isUnique": true
+ },
+ "key_hash_index": {
+ "name": "key_hash_index",
+ "columns": [
+ "key_hash"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "api_keys_user_id_users_id_fk": {
+ "name": "api_keys_user_id_users_id_fk",
+ "tableFrom": "api_keys",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "auth_accounts": {
+ "name": "auth_accounts",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "account_id": {
+ "name": "account_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "access_token": {
+ "name": "access_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refresh_token": {
+ "name": "refresh_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "access_token_expires_at": {
+ "name": "access_token_expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "refresh_token_expires_at": {
+ "name": "refresh_token_expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "id_token": {
+ "name": "id_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "auth_accounts_user_id_users_id_fk": {
+ "name": "auth_accounts_user_id_users_id_fk",
+ "tableFrom": "auth_accounts",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "auth_sessions": {
+ "name": "auth_sessions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ip_address": {
+ "name": "ip_address",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_agent": {
+ "name": "user_agent",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "active_organization_id": {
+ "name": "active_organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "auth_sessions_token_index": {
+ "name": "auth_sessions_token_index",
+ "columns": [
+ "token"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "auth_sessions_user_id_users_id_fk": {
+ "name": "auth_sessions_user_id_users_id_fk",
+ "tableFrom": "auth_sessions",
+ "tableTo": "users",
+ "columnsFrom": [
+ "user_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "auth_sessions_active_organization_id_organizations_id_fk": {
+ "name": "auth_sessions_active_organization_id_organizations_id_fk",
+ "tableFrom": "auth_sessions",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "active_organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "auth_verifications": {
+ "name": "auth_verifications",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "auth_verifications_identifier_index": {
+ "name": "auth_verifications_identifier_index",
+ "columns": [
+ "identifier"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "intake_emails": {
+ "name": "intake_emails",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "email_address": {
+ "name": "email_address",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "allowed_origins": {
+ "name": "allowed_origins",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "is_enabled": {
+ "name": "is_enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ }
+ },
+ "indexes": {
+ "intake_emails_email_address_unique": {
+ "name": "intake_emails_email_address_unique",
+ "columns": [
+ "email_address"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "intake_emails_organization_id_organizations_id_fk": {
+ "name": "intake_emails_organization_id_organizations_id_fk",
+ "tableFrom": "intake_emails",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "organization_subscriptions": {
+ "name": "organization_subscriptions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "customer_id": {
+ "name": "customer_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "plan_id": {
+ "name": "plan_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "seats_count": {
+ "name": "seats_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "current_period_end": {
+ "name": "current_period_end",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "current_period_start": {
+ "name": "current_period_start",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cancel_at_period_end": {
+ "name": "cancel_at_period_end",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "organization_subscriptions_organization_id_organizations_id_fk": {
+ "name": "organization_subscriptions_organization_id_organizations_id_fk",
+ "tableFrom": "organization_subscriptions",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "tagging_rule_actions": {
+ "name": "tagging_rule_actions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tagging_rule_id": {
+ "name": "tagging_rule_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tag_id": {
+ "name": "tag_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "tagging_rule_actions_tagging_rule_id_tagging_rules_id_fk": {
+ "name": "tagging_rule_actions_tagging_rule_id_tagging_rules_id_fk",
+ "tableFrom": "tagging_rule_actions",
+ "tableTo": "tagging_rules",
+ "columnsFrom": [
+ "tagging_rule_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "tagging_rule_actions_tag_id_tags_id_fk": {
+ "name": "tagging_rule_actions_tag_id_tags_id_fk",
+ "tableFrom": "tagging_rule_actions",
+ "tableTo": "tags",
+ "columnsFrom": [
+ "tag_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "tagging_rule_conditions": {
+ "name": "tagging_rule_conditions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tagging_rule_id": {
+ "name": "tagging_rule_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "field": {
+ "name": "field",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "operator": {
+ "name": "operator",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_case_sensitive": {
+ "name": "is_case_sensitive",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "tagging_rule_conditions_tagging_rule_id_tagging_rules_id_fk": {
+ "name": "tagging_rule_conditions_tagging_rule_id_tagging_rules_id_fk",
+ "tableFrom": "tagging_rule_conditions",
+ "tableTo": "tagging_rules",
+ "columnsFrom": [
+ "tagging_rule_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "tagging_rules": {
+ "name": "tagging_rules",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "condition_match_mode": {
+ "name": "condition_match_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'all'"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "tagging_rules_organization_id_organizations_id_fk": {
+ "name": "tagging_rules_organization_id_organizations_id_fk",
+ "tableFrom": "tagging_rules",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "webhook_deliveries": {
+ "name": "webhook_deliveries",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "webhook_id": {
+ "name": "webhook_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "event_name": {
+ "name": "event_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "request_payload": {
+ "name": "request_payload",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "response_payload": {
+ "name": "response_payload",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "response_status": {
+ "name": "response_status",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "webhook_deliveries_webhook_id_webhooks_id_fk": {
+ "name": "webhook_deliveries_webhook_id_webhooks_id_fk",
+ "tableFrom": "webhook_deliveries",
+ "tableTo": "webhooks",
+ "columnsFrom": [
+ "webhook_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "webhook_events": {
+ "name": "webhook_events",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "webhook_id": {
+ "name": "webhook_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "event_name": {
+ "name": "event_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "webhook_events_webhook_id_event_name_unique": {
+ "name": "webhook_events_webhook_id_event_name_unique",
+ "columns": [
+ "webhook_id",
+ "event_name"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "webhook_events_webhook_id_webhooks_id_fk": {
+ "name": "webhook_events_webhook_id_webhooks_id_fk",
+ "tableFrom": "webhook_events",
+ "tableTo": "webhooks",
+ "columnsFrom": [
+ "webhook_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "webhooks": {
+ "name": "webhooks",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "secret": {
+ "name": "secret",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "created_by": {
+ "name": "created_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "organization_id": {
+ "name": "organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "webhooks_created_by_users_id_fk": {
+ "name": "webhooks_created_by_users_id_fk",
+ "tableFrom": "webhooks",
+ "tableTo": "users",
+ "columnsFrom": [
+ "created_by"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ },
+ "webhooks_organization_id_organizations_id_fk": {
+ "name": "webhooks_organization_id_organizations_id_fk",
+ "tableFrom": "webhooks",
+ "tableTo": "organizations",
+ "columnsFrom": [
+ "organization_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {}
+ }
+}
diff --git a/apps/papra-server/src/migrations/meta/_journal.json b/apps/papra-server/src/migrations/meta/_journal.json
index e0613896..8c1a1632 100644
--- a/apps/papra-server/src/migrations/meta/_journal.json
+++ b/apps/papra-server/src/migrations/meta/_journal.json
@@ -78,6 +78,13 @@
"when": 1760016118956,
"tag": "0010_soft-delete-organizations",
"breakpoints": true
+ },
+ {
+ "idx": 11,
+ "version": "6",
+ "when": 1761645190314,
+ "tag": "0011_tagging-rule-condition-match-mode",
+ "breakpoints": true
}
]
}
diff --git a/apps/papra-server/src/migrations/migrations.registry.test.ts b/apps/papra-server/src/migrations/migrations.registry.test.ts
index 8e5a6fc3..902cc6e3 100644
--- a/apps/papra-server/src/migrations/migrations.registry.test.ts
+++ b/apps/papra-server/src/migrations/migrations.registry.test.ts
@@ -115,7 +115,7 @@ describe('migrations registry', () => {
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE "tagging_rule_actions" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "tagging_rule_id" text NOT NULL, "tag_id" text NOT NULL, FOREIGN KEY ("tagging_rule_id") REFERENCES "tagging_rules"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("tag_id") REFERENCES "tags"("id") ON UPDATE cascade ON DELETE cascade );
CREATE TABLE "tagging_rule_conditions" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "tagging_rule_id" text NOT NULL, "field" text NOT NULL, "operator" text NOT NULL, "value" text NOT NULL, "is_case_sensitive" integer DEFAULT false NOT NULL, FOREIGN KEY ("tagging_rule_id") REFERENCES "tagging_rules"("id") ON UPDATE cascade ON DELETE cascade );
- CREATE TABLE "tagging_rules" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "organization_id" text NOT NULL, "name" text NOT NULL, "description" text, "enabled" integer DEFAULT true NOT NULL, FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON UPDATE cascade ON DELETE cascade );
+ CREATE TABLE "tagging_rules" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "organization_id" text NOT NULL, "name" text NOT NULL, "description" text, "enabled" integer DEFAULT true NOT NULL, "condition_match_mode" text DEFAULT 'all' NOT NULL, FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON UPDATE cascade ON DELETE cascade );
CREATE TABLE "tags" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "organization_id" text NOT NULL, "name" text NOT NULL, "color" text NOT NULL, "description" text, FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON UPDATE cascade ON DELETE cascade );
CREATE TABLE "user_roles" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "user_id" text NOT NULL, "role" text NOT NULL, FOREIGN KEY ("user_id") REFERENCES "users"("id") ON UPDATE cascade ON DELETE cascade );
CREATE TABLE "users" ( "id" text PRIMARY KEY NOT NULL, "created_at" integer NOT NULL, "updated_at" integer NOT NULL, "email" text NOT NULL, "email_verified" integer DEFAULT false NOT NULL, "name" text, "image" text, "max_organization_count" integer );
diff --git a/apps/papra-server/src/migrations/migrations.registry.ts b/apps/papra-server/src/migrations/migrations.registry.ts
index de92b174..da7a862f 100644
--- a/apps/papra-server/src/migrations/migrations.registry.ts
+++ b/apps/papra-server/src/migrations/migrations.registry.ts
@@ -13,6 +13,7 @@ import { dropLegacyMigrationsMigration } from './list/0009-drop-legacy-migration
import { documentFileEncryptionMigration } from './list/0010-document-file-encryption.migration';
import { softDeleteOrganizationsMigration } from './list/0011-soft-delete-organizations.migration';
+import { taggingRuleConditionMatchModeMigration } from './list/0012-tagging-rule-condition-match-mode.migration';
export const migrations: Migration[] = [
initialSchemaSetupMigration,
@@ -26,4 +27,5 @@ export const migrations: Migration[] = [
dropLegacyMigrationsMigration,
documentFileEncryptionMigration,
softDeleteOrganizationsMigration,
+ taggingRuleConditionMatchModeMigration,
];
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.constants.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.constants.ts
index ca8f6aa1..b3516559 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.constants.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.constants.ts
@@ -17,3 +17,8 @@ export const TAGGING_RULE_FIELDS = {
DOCUMENT_NAME: 'name',
DOCUMENT_CONTENT: 'content',
} as const satisfies Record<string, keyof DbSelectableDocument>;
+
+export const CONDITION_MATCH_MODES = {
+ ALL: 'all',
+ ANY: 'any',
+} as const;
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.test.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.test.ts
index 3689a746..d898a0cb 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.test.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.test.ts
@@ -36,6 +36,7 @@ describe('tagging-rules repository', () => {
id: 'tr_1',
name: 'Enabled Rule 1',
organizationId: 'org_1',
+ conditionMatchMode: 'all',
updatedAt: new Date('2023-04-01T00:00:00.000Z'),
actions: [
{
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.ts
index 955f26d6..458158a1 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.repository.ts
@@ -1,5 +1,5 @@
import type { Database } from '../app/database/database.types';
-import type { DbInsertableTaggingRule, TaggingRuleField, TaggingRuleOperator } from './tagging-rules.types';
+import type { ConditionMatchMode, DbInsertableTaggingRule, TaggingRuleField, TaggingRuleOperator } from './tagging-rules.types';
import { injectArguments } from '@corentinth/chisels';
import { and, eq } from 'drizzle-orm';
import { createError } from '../shared/errors/errors';
@@ -103,17 +103,18 @@ async function updateOrganizationTaggingRule({
name: string;
description: string | undefined;
enabled: boolean | undefined;
+ conditionMatchMode: ConditionMatchMode | undefined;
conditions: { field: TaggingRuleField; operator: TaggingRuleOperator; value: string }[];
tagIds: string[];
};
db: Database;
}) {
- const { name, description, enabled, conditions, tagIds } = taggingRule;
+ const { name, description, enabled, conditionMatchMode, conditions, tagIds } = taggingRule;
await db.transaction(async (tx) => {
const [updatedTaggingRule] = await tx
.update(taggingRulesTable)
- .set(omitUndefined({ name, description, enabled }))
+ .set(omitUndefined({ name, description, enabled, conditionMatchMode }))
.where(and(
eq(taggingRulesTable.id, taggingRuleId),
eq(taggingRulesTable.organizationId, organizationId),
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.routes.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.routes.ts
index bd575b72..75dff3fe 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.routes.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.routes.ts
@@ -12,7 +12,7 @@ import { validateJsonBody, validateParams } from '../shared/validation/validatio
import { tagIdRegex } from '../tags/tags.constants';
import { TAGGING_RULE_FIELDS, TAGGING_RULE_OPERATORS } from './tagging-rules.constants';
import { createTaggingRulesRepository } from './tagging-rules.repository';
-import { taggingRuleIdSchema } from './tagging-rules.schemas';
+import { conditionMatchModeSchema, taggingRuleIdSchema } from './tagging-rules.schemas';
import { createTaggingRule } from './tagging-rules.usecases';
export function registerTaggingRulesRoutes(context: RouteDefinitionContext) {
@@ -61,6 +61,7 @@ function setupCreateTaggingRuleRoute({ app, db }: RouteDefinitionContext) {
name: z.string().min(1).max(64),
description: z.string().max(256).optional(),
enabled: z.boolean().optional(),
+ conditionMatchMode: conditionMatchModeSchema.optional(),
conditions: z.array(z.object({
field: z.enum(Object.values(TAGGING_RULE_FIELDS) as [TaggingRuleField, ...TaggingRuleField[]]), // casting since zod require non-empty array
operator: z.enum(Object.values(TAGGING_RULE_OPERATORS) as [TaggingRuleOperator, ...TaggingRuleOperator[]]), // casting since zod require non-empty array
@@ -72,14 +73,14 @@ function setupCreateTaggingRuleRoute({ app, db }: RouteDefinitionContext) {
const { userId } = getUser({ context });
const { organizationId } = context.req.valid('param');
- const { name, description, enabled, conditions, tagIds } = context.req.valid('json');
+ const { name, description, enabled, conditionMatchMode, conditions, tagIds } = context.req.valid('json');
const taggingRulesRepository = createTaggingRulesRepository({ db });
const organizationsRepository = createOrganizationsRepository({ db });
await ensureUserIsInOrganization({ userId, organizationId, organizationsRepository });
- await createTaggingRule({ name, description, enabled, conditions, tagIds, organizationId, taggingRulesRepository });
+ await createTaggingRule({ name, description, enabled, conditionMatchMode, conditions, tagIds, organizationId, taggingRulesRepository });
return context.body(null, 204);
},
@@ -150,6 +151,7 @@ function setupUpdateTaggingRuleRoute({ app, db }: RouteDefinitionContext) {
name: z.string().min(1).max(64),
description: z.string().max(256).optional(),
enabled: z.boolean().optional(),
+ conditionMatchMode: conditionMatchModeSchema.optional(),
conditions: z.array(z.object({
field: z.enum(Object.values(TAGGING_RULE_FIELDS) as [TaggingRuleField, ...TaggingRuleField[]]), // casting since zod require non-empty array
operator: z.enum(Object.values(TAGGING_RULE_OPERATORS) as [TaggingRuleOperator, ...TaggingRuleOperator[]]), // casting since zod require non-empty array
@@ -161,7 +163,7 @@ function setupUpdateTaggingRuleRoute({ app, db }: RouteDefinitionContext) {
const { userId } = getUser({ context });
const { organizationId, taggingRuleId } = context.req.valid('param');
- const { name, description, enabled, conditions, tagIds } = context.req.valid('json');
+ const { name, description, enabled, conditionMatchMode, conditions, tagIds } = context.req.valid('json');
const taggingRulesRepository = createTaggingRulesRepository({ db });
const organizationsRepository = createOrganizationsRepository({ db });
@@ -171,7 +173,7 @@ function setupUpdateTaggingRuleRoute({ app, db }: RouteDefinitionContext) {
await taggingRulesRepository.updateOrganizationTaggingRule({
organizationId,
taggingRuleId,
- taggingRule: { name, description, enabled, conditions, tagIds },
+ taggingRule: { name, description, enabled, conditionMatchMode, conditions, tagIds },
});
return context.body(null, 204);
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.ts
index 5a2fc970..14684308 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.schemas.ts
@@ -1,4 +1,6 @@
import { z } from 'zod';
-import { TAGGING_RULE_ID_REGEX } from './tagging-rules.constants';
+import { CONDITION_MATCH_MODES, TAGGING_RULE_ID_REGEX } from './tagging-rules.constants';
export const taggingRuleIdSchema = z.string().regex(TAGGING_RULE_ID_REGEX);
+
+export const conditionMatchModeSchema = z.enum([CONDITION_MATCH_MODES.ALL, CONDITION_MATCH_MODES.ANY]);
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.tables.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.tables.ts
index 9b3a967c..db9d8b09 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.tables.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.tables.ts
@@ -1,5 +1,6 @@
-import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
+import type { ConditionMatchMode } from './tagging-rules.types';
+import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { organizationsTable } from '../organizations/organizations.table';
import { createPrimaryKeyField, createTimestampColumns } from '../shared/db/columns.helpers';
import { tagsTable } from '../tags/tags.table';
@@ -15,6 +16,7 @@ export const taggingRulesTable = sqliteTable(
name: text('name').notNull(),
description: text('description'),
enabled: integer('enabled', { mode: 'boolean' }).notNull().default(true),
+ conditionMatchMode: text('condition_match_mode').notNull().default('all').$type<ConditionMatchMode>(),
},
);
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.types.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.types.ts
index 1d267e21..2e2545f5 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.types.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.types.ts
@@ -1,5 +1,5 @@
import type { Expand } from '@corentinth/chisels';
-import type { TAGGING_RULE_FIELDS, TAGGING_RULE_OPERATORS } from './tagging-rules.constants';
+import type { CONDITION_MATCH_MODES, TAGGING_RULE_FIELDS, TAGGING_RULE_OPERATORS } from './tagging-rules.constants';
import type { taggingRuleActionsTable, taggingRuleConditionsTable, taggingRulesTable } from './tagging-rules.tables';
export type DbInsertableTaggingRule = typeof taggingRulesTable.$inferInsert;
@@ -8,6 +8,7 @@ export type DbInsertableTaggingRuleAction = typeof taggingRuleActionsTable.$infe
export type TaggingRuleField = (typeof TAGGING_RULE_FIELDS)[keyof typeof TAGGING_RULE_FIELDS];
export type TaggingRuleOperator = (typeof TAGGING_RULE_OPERATORS)[keyof typeof TAGGING_RULE_OPERATORS];
+export type ConditionMatchMode = (typeof CONDITION_MATCH_MODES)[keyof typeof CONDITION_MATCH_MODES];
export type TaggingRule = Expand<typeof taggingRulesTable.$inferSelect>;
export type TaggingRuleCondition = Expand<typeof taggingRuleConditionsTable.$inferSelect>;
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.test.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.test.ts
index 4bc74b33..5549a9f9 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.test.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.test.ts
@@ -97,6 +97,34 @@ describe('tagging-rules usecases', () => {
expect(documentTags).to.eql([{ documentId: 'doc_1', tagId: 'tag_1' }]);
});
+ test('a rule without conditions and conditionMatchMode "any" applies tags to all documents', async () => {
+ const { db } = await createInMemoryDatabase({
+ organizations: [{ id: 'org_1', name: 'Org 1' }],
+ documents: [{ id: 'doc_1', organizationId: 'org_1', name: 'Doc 1', originalName: 'Doc 1', originalStorageKey: 'doc_1', originalSha256Hash: 'doc_1', mimeType: 'text/plain' }],
+ tags: [{ id: 'tag_1', name: 'Tag 1', color: '#000000', organizationId: 'org_1' }],
+ taggingRules: [{ id: 'tr_1', organizationId: 'org_1', name: 'Tagging Rule 1', conditionMatchMode: 'any' }],
+ taggingRuleActions: [{ id: 'tra_1', taggingRuleId: 'tr_1', tagId: 'tag_1' }],
+ });
+
+ const [document] = await db.select().from(documentsTable).where(eq(documentsTable.id, 'doc_1'));
+
+ if (isNil(document)) {
+ throw new Error('Document not found');
+ }
+
+ const taggingRulesRepository = createTaggingRulesRepository({ db });
+ const tagsRepository = createTagsRepository({ db });
+ const webhookRepository = createWebhookRepository({ db });
+ const documentActivityRepository = createDocumentActivityRepository({ db });
+
+ await applyTaggingRules({ document, taggingRulesRepository, tagsRepository, webhookRepository, documentActivityRepository });
+
+ const documentTags = await db.select().from(documentsTagsTable);
+
+ // Should still apply the tag even with conditionMatchMode 'any' and no conditions
+ expect(documentTags).to.eql([{ documentId: 'doc_1', tagId: 'tag_1' }]);
+ });
+
test('an organization with no tagging rules will not apply any tag to a document', async () => {
const { db } = await createInMemoryDatabase({
organizations: [{ id: 'org_1', name: 'Org 1' }],
@@ -121,6 +149,138 @@ describe('tagging-rules usecases', () => {
expect(documentTags).to.eql([]);
});
+
+ test('when conditionMatchMode is "any", tags are applied when at least one condition matches', async () => {
+ const { db } = await createInMemoryDatabase({
+ organizations: [{ id: 'org_1', name: 'Org 1' }],
+ tags: [{ id: 'tag_1', name: 'Tag 1', color: '#000000', organizationId: 'org_1' }],
+ documents: [{ id: 'doc_1', organizationId: 'org_1', name: 'Invoice 2024', originalName: 'Invoice 2024', originalStorageKey: 'doc_1', originalSha256Hash: 'doc_1', mimeType: 'text/plain' }],
+
+ taggingRules: [{ id: 'tr_1', organizationId: 'org_1', name: 'Tagging Rule 1', conditionMatchMode: 'any' }],
+ taggingRuleConditions: [
+ { id: 'trc_1', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Invoice' },
+ { id: 'trc_2', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Receipt' },
+ ],
+ taggingRuleActions: [{ id: 'tra_1', taggingRuleId: 'tr_1', tagId: 'tag_1' }],
+ });
+
+ const [document] = await db.select().from(documentsTable).where(eq(documentsTable.id, 'doc_1'));
+
+ if (isNil(document)) {
+ throw new Error('Document not found');
+ }
+
+ const taggingRulesRepository = createTaggingRulesRepository({ db });
+ const tagsRepository = createTagsRepository({ db });
+ const webhookRepository = createWebhookRepository({ db });
+ const documentActivityRepository = createDocumentActivityRepository({ db });
+
+ await applyTaggingRules({ document, taggingRulesRepository, tagsRepository, webhookRepository, documentActivityRepository });
+
+ const documentTags = await db.select().from(documentsTagsTable);
+
+ // Tag should be applied because one condition (Invoice) matches
+ expect(documentTags).to.eql([{ documentId: 'doc_1', tagId: 'tag_1' }]);
+ });
+
+ test('when conditionMatchMode is "any", tags are not applied when no conditions match', async () => {
+ const { db } = await createInMemoryDatabase({
+ organizations: [{ id: 'org_1', name: 'Org 1' }],
+ tags: [{ id: 'tag_1', name: 'Tag 1', color: '#000000', organizationId: 'org_1' }],
+ documents: [{ id: 'doc_1', organizationId: 'org_1', name: 'Contract 2024', originalName: 'Contract 2024', originalStorageKey: 'doc_1', originalSha256Hash: 'doc_1', mimeType: 'text/plain' }],
+
+ taggingRules: [{ id: 'tr_1', organizationId: 'org_1', name: 'Tagging Rule 1', conditionMatchMode: 'any' }],
+ taggingRuleConditions: [
+ { id: 'trc_1', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Invoice' },
+ { id: 'trc_2', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Receipt' },
+ ],
+ taggingRuleActions: [{ id: 'tra_1', taggingRuleId: 'tr_1', tagId: 'tag_1' }],
+ });
+
+ const [document] = await db.select().from(documentsTable).where(eq(documentsTable.id, 'doc_1'));
+
+ if (isNil(document)) {
+ throw new Error('Document not found');
+ }
+
+ const taggingRulesRepository = createTaggingRulesRepository({ db });
+ const tagsRepository = createTagsRepository({ db });
+ const webhookRepository = createWebhookRepository({ db });
+ const documentActivityRepository = createDocumentActivityRepository({ db });
+
+ await applyTaggingRules({ document, taggingRulesRepository, tagsRepository, webhookRepository, documentActivityRepository });
+
+ const documentTags = await db.select().from(documentsTagsTable);
+
+ // Tag should not be applied because no conditions match
+ expect(documentTags).to.eql([]);
+ });
+
+ test('when conditionMatchMode is "all" (default), tags are applied only when all conditions match', async () => {
+ const { db } = await createInMemoryDatabase({
+ organizations: [{ id: 'org_1', name: 'Org 1' }],
+ tags: [{ id: 'tag_1', name: 'Tag 1', color: '#000000', organizationId: 'org_1' }],
+ documents: [{ id: 'doc_1', organizationId: 'org_1', name: 'Invoice 2024', originalName: 'Invoice 2024', originalStorageKey: 'doc_1', originalSha256Hash: 'doc_1', mimeType: 'text/plain' }],
+
+ taggingRules: [{ id: 'tr_1', organizationId: 'org_1', name: 'Tagging Rule 1', conditionMatchMode: 'all' }],
+ taggingRuleConditions: [
+ { id: 'trc_1', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Invoice' },
+ { id: 'trc_2', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: '2024' },
+ ],
+ taggingRuleActions: [{ id: 'tra_1', taggingRuleId: 'tr_1', tagId: 'tag_1' }],
+ });
+
+ const [document] = await db.select().from(documentsTable).where(eq(documentsTable.id, 'doc_1'));
+
+ if (isNil(document)) {
+ throw new Error('Document not found');
+ }
+
+ const taggingRulesRepository = createTaggingRulesRepository({ db });
+ const tagsRepository = createTagsRepository({ db });
+ const webhookRepository = createWebhookRepository({ db });
+ const documentActivityRepository = createDocumentActivityRepository({ db });
+
+ await applyTaggingRules({ document, taggingRulesRepository, tagsRepository, webhookRepository, documentActivityRepository });
+
+ const documentTags = await db.select().from(documentsTagsTable);
+
+ // Tag should be applied because all conditions match
+ expect(documentTags).to.eql([{ documentId: 'doc_1', tagId: 'tag_1' }]);
+ });
+
+ test('when conditionMatchMode is "all" (default), tags are not applied when only some conditions match', async () => {
+ const { db } = await createInMemoryDatabase({
+ organizations: [{ id: 'org_1', name: 'Org 1' }],
+ tags: [{ id: 'tag_1', name: 'Tag 1', color: '#000000', organizationId: 'org_1' }],
+ documents: [{ id: 'doc_1', organizationId: 'org_1', name: 'Invoice 2024', originalName: 'Invoice 2024', originalStorageKey: 'doc_1', originalSha256Hash: 'doc_1', mimeType: 'text/plain' }],
+
+ taggingRules: [{ id: 'tr_1', organizationId: 'org_1', name: 'Tagging Rule 1', conditionMatchMode: 'all' }],
+ taggingRuleConditions: [
+ { id: 'trc_1', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Invoice' },
+ { id: 'trc_2', taggingRuleId: 'tr_1', field: 'name', operator: 'contains', value: 'Receipt' },
+ ],
+ taggingRuleActions: [{ id: 'tra_1', taggingRuleId: 'tr_1', tagId: 'tag_1' }],
+ });
+
+ const [document] = await db.select().from(documentsTable).where(eq(documentsTable.id, 'doc_1'));
+
+ if (isNil(document)) {
+ throw new Error('Document not found');
+ }
+
+ const taggingRulesRepository = createTaggingRulesRepository({ db });
+ const tagsRepository = createTagsRepository({ db });
+ const webhookRepository = createWebhookRepository({ db });
+ const documentActivityRepository = createDocumentActivityRepository({ db });
+
+ await applyTaggingRules({ document, taggingRulesRepository, tagsRepository, webhookRepository, documentActivityRepository });
+
+ const documentTags = await db.select().from(documentsTagsTable);
+
+ // Tag should not be applied because only one condition matches (Invoice, not Receipt)
+ expect(documentTags).to.eql([]);
+ });
});
describe('applyTaggingRuleToExistingDocuments', () => {
diff --git a/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.ts b/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.ts
index 0ce0a83e..863ad450 100644
--- a/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.ts
+++ b/apps/papra-server/src/modules/tagging-rules/tagging-rules.usecases.ts
@@ -7,7 +7,7 @@ import type { Tag } from '../tags/tags.types';
import type { WebhookRepository } from '../webhooks/webhook.repository';
import type { TaggingRuleOperatorValidatorRegistry } from './conditions/tagging-rule-conditions.registry';
import type { TaggingRulesRepository } from './tagging-rules.repository';
-import type { TaggingRuleField, TaggingRuleOperator } from './tagging-rules.types';
+import type { ConditionMatchMode, TaggingRuleField, TaggingRuleOperator } from './tagging-rules.types';
import { safely, safelySync } from '@corentinth/chisels';
import { uniq } from 'lodash-es';
import { createError } from '../shared/errors/errors';
@@ -15,12 +15,14 @@ import { createLogger } from '../shared/logger/logger';
import { isNil } from '../shared/utils';
import { addTagToDocument } from '../tags/tags.usecases';
import { createTaggingRuleOperatorValidatorRegistry } from './conditions/tagging-rule-conditions.registry';
+import { CONDITION_MATCH_MODES } from './tagging-rules.constants';
import { getDocumentFieldValue } from './tagging-rules.models';
export async function createTaggingRule({
name,
description,
enabled,
+ conditionMatchMode,
conditions,
tagIds,
organizationId,
@@ -30,6 +32,7 @@ export async function createTaggingRule({
name: string;
description: string | undefined;
enabled: boolean | undefined;
+ conditionMatchMode: ConditionMatchMode | undefined;
conditions: {
field: TaggingRuleField;
operator: TaggingRuleOperator;
@@ -45,6 +48,7 @@ export async function createTaggingRule({
name,
description,
enabled,
+ conditionMatchMode,
organizationId,
},
});
@@ -74,6 +78,7 @@ export async function applyTaggingRule({
document: Document;
taggingRule: {
id: string;
+ conditionMatchMode?: ConditionMatchMode;
conditions: Array<{
operator: string;
field: string;
@@ -90,24 +95,36 @@ export async function applyTaggingRule({
taggingRuleOperatorValidatorRegistry?: TaggingRuleOperatorValidatorRegistry;
logger?: Logger;
}): Promise<{ appliedTagIds: string[] }> {
- // Check if all conditions match
- const allConditionsMatch = taggingRule.conditions.every(({ operator, field, value: conditionValue, isCaseSensitive }) => {
- const { validate } = taggingRuleOperatorValidatorRegistry.getTaggingRuleOperatorValidator({ operator });
- const { fieldValue } = getDocumentFieldValue({ document, field });
+ // If there are no conditions, the rule always matches
- const [isValid, error] = safelySync(() => validate({ conditionValue, fieldValue, isCaseSensitive }));
+ const hasConditions = taggingRule.conditions.length > 0;
- if (error) {
- logger.error({ error, conditionValue, fieldValue, isCaseSensitive }, 'Failed to validate tagging rule condition');
- return false;
- }
+ if (hasConditions) {
+ // Validate each condition
+ const validateCondition = (condition: { operator: string; field: string; value: string; isCaseSensitive: boolean }) => {
+ const { operator, field, value: conditionValue, isCaseSensitive } = condition;
+ const { validate } = taggingRuleOperatorValidatorRegistry.getTaggingRuleOperatorValidator({ operator });
+ const { fieldValue } = getDocumentFieldValue({ document, field });
- return isValid;
- });
+ const [isValid, error] = safelySync(() => validate({ conditionValue, fieldValue, isCaseSensitive }));
+
+ if (error) {
+ logger.error({ error, conditionValue, fieldValue, isCaseSensitive }, 'Failed to validate tagging rule condition');
+ return false;
+ }
- // If conditions don't match, return empty array
- if (!allConditionsMatch) {
- return { appliedTagIds: [] };
+ return isValid;
+ };
+
+ // Check if conditions match based on match mode (default to 'all' for backwards compatibility)
+ const conditionsMatch = taggingRule.conditionMatchMode === CONDITION_MATCH_MODES.ANY
+ ? taggingRule.conditions.some(validateCondition)
+ : taggingRule.conditions.every(validateCondition);
+
+ // If conditions don't match, return empty array
+ if (!conditionsMatch) {
+ return { appliedTagIds: [] };
+ }
}
// Get tags to apply from the rule's actions
diff --git a/apps/papra-server/src/scripts/migrate-down.script.ts b/apps/papra-server/src/scripts/migrate-down.script.ts
new file mode 100644
index 00000000..c5c1b33e
--- /dev/null
+++ b/apps/papra-server/src/scripts/migrate-down.script.ts
@@ -0,0 +1,9 @@
+import { rollbackLastAppliedMigration } from '../migrations/migrations.usecases';
+import { runScriptWithDb } from './commons/run-script';
+
+await runScriptWithDb(
+ { scriptName: 'migrate-down' },
+ async ({ db }) => {
+ await rollbackLastAppliedMigration({ db });
+ },
+);