From 7f4092971de293881ab29444fa505ee0653a7ea3 Mon Sep 17 00:00:00 2001 From: seb Date: Sun, 11 Oct 2026 17:26:11 +0200 Subject: [PATCH] u --- API.attributevalue.md | 41 + API.md | 3 + generate-api-doc.js | 1 + generate-schema-graph.js | 2 +- schema-graph.dot | 225 +- schema-graph.svg | 5054 +++++++++-------- scripts/test-attributevalue-pic.js | 115 + src/index.js | 4 + src/providers/mssql/purgeSql.js | 1 + .../mssql/queries/attributevaluepic.js | 23 + src/providers/mssql/queries/pic.js | 10 + src/providers/mssql/schema.js | 17 + .../sqlite3/queries/attributevaluepic.js | 5 + src/providers/sqlite3/schema.js | 14 + src/store/attributevalue/addImage.js | 118 + src/store/attributevalue/deleteImage.js | 37 + .../resolveAttributeValueAccess.js | 22 + 17 files changed, 3076 insertions(+), 2616 deletions(-) create mode 100644 scripts/test-attributevalue-pic.js create mode 100644 src/providers/mssql/queries/attributevaluepic.js create mode 100644 src/providers/sqlite3/queries/attributevaluepic.js create mode 100644 src/store/attributevalue/addImage.js create mode 100644 src/store/attributevalue/deleteImage.js create mode 100644 src/store/attributevalue/resolveAttributeValueAccess.js diff --git a/API.attributevalue.md b/API.attributevalue.md index 0dd9a61..373a6a6 100644 --- a/API.attributevalue.md +++ b/API.attributevalue.md @@ -2,6 +2,25 @@ This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`. +## `attributevalue.addImage` + +*Source: `src/store/attributevalue/addImage.js`* + +Adds an image to an attribute value, processing full, thumb, and 32px-edge small-thumb AVIF variants. + +**Parameters** + +| Name | Type | Description | +| --- | --- | --- | +| `googleAuthId` | `number` | The id of the Google auth user. | +| `attributeValueId` | `number` | The id of the attribute value. | +| `image` | `Buffer` | The source image buffer. | +| `[tx]` | `object` | Optional transaction to run within. | + +**Returns** + +`Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array}>` + ## `attributevalue.create` *Source: `src/store/attributevalue/create.js`* @@ -49,6 +68,28 @@ Deletes an attribute value. `Error` — If attribute value not found or in use. +## `attributevalue.deleteImage` + +*Source: `src/store/attributevalue/deleteImage.js`* + +Deletes the image of an attribute value. + +**Parameters** + +| Name | Type | Description | +| --- | --- | --- | +| `googleAuthId` | `number` | The id of the Google auth user. | +| `attributeValueId` | `number` | The id of the attribute value. | +| `[tx]` | `object` | Optional transaction. | + +**Returns** + +`Promise<{id: number, thumbW: null, thumbH: null, thumbHash: null, pics: Array}>` + +**Throws** + +`Error` — If attribute value not found or image not found. + ## `attributevalue.listByAttributeId` *Source: `src/store/attributevalue/listByAttributeId.js`* diff --git a/API.md b/API.md index bc13072..f211ab9 100644 --- a/API.md +++ b/API.md @@ -20,6 +20,7 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met - **articletext**: `id PK, article_id->article, language_id->language, name:s(255), slug:s(255), seo?:txt, desc?:txt, UQ(article_id, language_id)` - **attributename**: `id PK, company_id->company, name:s(255), sort:i=0, exclusive:b=0, UQ(company_id, name)` - **attributevalue**: `id PK, attribute_id->attributename, value:s(255), sort:i=0, UQ(attribute_id, value)` +- **attributevaluepic**: `id PK, attributevalue_id->attributevalue, pic_id->pic, sort:i=0, UQ(attributevalue_id, pic_id), UQ(attributevalue_id, sort)` - **brand**: `id PK, company_id->company, name:s(255), gsprpinfo?:txt, UQ(company_id, name)` - **brandpic**: `id PK, brand_id->brand, pic_id->pic, sort:i=0, UQ(brand_id, pic_id), UQ(brand_id, sort)` - **category**: `id PK, parent_id?->category, sort:i=0` @@ -264,8 +265,10 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met - `order(googleAuthId: number, input: {attributenameIds: Array}, tx?: object): Promise<{attributenameIds: Array}>` - `update(googleAuthId: number, id: number, input: {name?: string, sort?: number, exclusive?: boolean}, tx?: object): Promise<{id: number, name: string, sort: number, exclusive: boolean, values: Array}>` - [attributevalue](API.attributevalue.md) + - `addImage(googleAuthId: number, attributeValueId: number, image: Buffer, tx?: object): Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array}>` - `create(googleAuthId: number, attributeId: number, input: {value: string, sort?: number}, tx?: object): Promise<{id: number, attributeId: number, value: string, sort: number}>` - `delete(googleAuthId: number, id: number, tx?: object): Promise` + - `deleteImage(googleAuthId: number, attributeValueId: number, tx?: object): Promise<{id: number, thumbW: null, thumbH: null, thumbHash: null, pics: Array}>` - `listByAttributeId(googleAuthId: number, attributeId: number, tx?: object): Promise>` - `order(googleAuthId: number, attributeId: number, input: {attributevalueIds: Array}, tx?: object): Promise<{attributevalueIds: Array}>` - `update(googleAuthId: number, id: number, input: {value?: string, sort?: number}, tx?: object): Promise<{id: number, attributeId: number, value: string, sort: number}>` diff --git a/generate-api-doc.js b/generate-api-doc.js index c51ffac..8e698a4 100644 --- a/generate-api-doc.js +++ b/generate-api-doc.js @@ -331,6 +331,7 @@ const SCHEMA_TABLES = [ ['articletext', 'id PK, article_id->article, language_id->language, name:s(255), slug:s(255), seo?:txt, desc?:txt, UQ(article_id, language_id)'], ['attributename', 'id PK, company_id->company, name:s(255), sort:i=0, exclusive:b=0, UQ(company_id, name)'], ['attributevalue', 'id PK, attribute_id->attributename, value:s(255), sort:i=0, UQ(attribute_id, value)'], + ['attributevaluepic', 'id PK, attributevalue_id->attributevalue, pic_id->pic, sort:i=0, UQ(attributevalue_id, pic_id), UQ(attributevalue_id, sort)'], ['brand', 'id PK, company_id->company, name:s(255), gsprpinfo?:txt, UQ(company_id, name)'], ['brandpic', 'id PK, brand_id->brand, pic_id->pic, sort:i=0, UQ(brand_id, pic_id), UQ(brand_id, sort)'], ['category', 'id PK, parent_id?->category, sort:i=0'], diff --git a/generate-schema-graph.js b/generate-schema-graph.js index c2ea98c..755388e 100644 --- a/generate-schema-graph.js +++ b/generate-schema-graph.js @@ -365,7 +365,7 @@ const CLUSTERS = [ { id: 'media', label: 'Media', - tables: ['pic', 'articlepic', 'categorypic', 'brandpic', 'file'], + tables: ['pic', 'articlepic', 'categorypic', 'brandpic', 'attributevaluepic', 'file'], }, { id: 'manifests', diff --git a/schema-graph.dot b/schema-graph.dot index 618d329..cb82844 100644 --- a/schema-graph.dot +++ b/schema-graph.dot @@ -9,11 +9,11 @@ digraph schema { label="Identity & Company"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - meta [label=<
meta
keyNVARCHAR(255)
valueNVARCHAR(MAX)
>]; customergroup [label=<
customergroup
idINT PK
company_id?INT FK
nameNVARCHAR(255)
sortINT
updated_atDATETIME2
>]; - company [label=<
company
idINT PK
default_language_id?INT FK
taxrate?INT FK
reducedtaxrate?INT FK
taxfreerate?INT FK
root_category_id?INT FK
poscustomergroup_idINT FK
nameNVARCHAR(255)
>]; - entityaddress [label=<
entityaddress
idINT PK
entity_idINT FK
first_name?NVARCHAR(255)
name?NVARCHAR(255)
street?NVARCHAR(255)
streetnumber?NVARCHAR(50)
zip?NVARCHAR(50)
city?NVARCHAR(255)
county?NVARCHAR(255)
addresstypeNVARCHAR(50)
sortINT
>]; + company [label=<
company
idINT PK
root_category_id?INT FK
taxrate?INT FK
reducedtaxrate?INT FK
taxfreerate?INT FK
default_language_id?INT FK
poscustomergroup_idINT FK
nameNVARCHAR(255)
>]; + meta [label=<
meta
keyNVARCHAR(255)
valueNVARCHAR(MAX)
>]; companyhistory [label=<
companyhistory
idINT PK
company_idINT FK
companyuser_id?INT FK
dateDATETIME2
textNVARCHAR(MAX)
>]; + entityaddress [label=<
entityaddress
idINT PK
entity_idINT FK
first_name?NVARCHAR(255)
name?NVARCHAR(255)
street?NVARCHAR(255)
streetnumber?NVARCHAR(50)
zip?NVARCHAR(50)
city?NVARCHAR(255)
county?NVARCHAR(255)
addresstypeNVARCHAR(50)
sortINT
>]; entity [label=<
entity
idINT PK
customergroup_idINT FK
first_name?NVARCHAR(255)
nameNVARCHAR(255)
number?NVARCHAR(100)
created_atDATETIME2
updated_atDATETIME2
>]; numbers [label=<
numbers
idINT PK
company_idINT FK
typeNVARCHAR(100)
prefixNVARCHAR(50)
paddingINT
nextINT
>]; entitycontact [label=<
entitycontact
idINT PK
entity_idINT FK
contacttypeNVARCHAR(50)
contactNVARCHAR(255)
sortINT
>]; @@ -27,56 +27,57 @@ digraph schema { style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; language [label=<
language
idINT PK
iso639NVARCHAR(10)
>]; + articletext [label=<
articletext
idINT PK
article_idINT FK
language_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; + categorytext [label=<
categorytext
idINT PK
category_idINT FK
language_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; unittext [label=<
unittext
idINT PK
language_idINT FK
unit_idINT FK
symbolNVARCHAR(50)
nameNVARCHAR(255)
>]; - categorytext [label=<
categorytext
idINT PK
language_idINT FK
category_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; - articletext [label=<
articletext
idINT PK
language_idINT FK
article_idINT FK
nameNVARCHAR(255)
slugNVARCHAR(255)
seo?NVARCHAR(MAX)
desc?NVARCHAR(MAX)
>]; } subgraph cluster_catalog { label="Catalog"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - categoryarticle [label=<
categoryarticle
idINT PK
category_idINT FK
article_idINT FK
>]; - category [label=<
category
idINT PK
parent_id?INT FK
sortINT
updated_atDATETIME2
>]; - articlehistory [label=<
articlehistory
idINT PK
article_idINT FK
companyuser_id?INT FK
dateDATETIME2
textNVARCHAR(MAX)
>]; - article [label=<
article
idINT PK
parentattributename_id?INT FK
unit_idINT FK
parentarticle_id?INT FK
articlelist_id?INT FK
optionslist_id?INT FK
brand_id?INT FK
company_idINT FK
sku?NVARCHAR(100)
unitamountFLOAT
weightFLOAT
track_stockBIT
is_parentBIT
parentsortINT
created_atDATETIME2
updated_atDATETIME2
>]; - articleean [label=<
articleean
idINT PK
article_idINT FK
eanNVARCHAR(50)
>]; - articlesupplier [label=<
articlesupplier
idINT PK
tax_id?INT FK
article_idINT FK
entity_idINT FK
net?FLOAT
sku?NVARCHAR(100)
stock?FLOAT
puFLOAT
sortINT
>]; - articlelist [label=<
articlelist
idINT PK
>]; - articlelistarticle [label=<
articlelistarticle
idINT PK
article_idINT FK
articlelist_idINT FK
countINT
sortINT
>]; - optionslist [label=<
optionslist
idINT PK
>]; - optionslistarticle [label=<
optionslistarticle
idINT PK
article_idINT FK
optionslist_idINT FK
countINT
sortINT
mandatedBIT
>]; brand [label=<
brand
idINT PK
company_idINT FK
nameNVARCHAR(255)
gsprpinfo?NVARCHAR(MAX)
>]; articletombstone [label=<
articletombstone
idINT PK
company_idINT FK
article_id?INT
sku?NVARCHAR(100)
name?NVARCHAR(255)
taxrate?DECIMAL(18,4)
net?FLOAT
deleted_atDATETIME2
>]; + articlelist [label=<
articlelist
idINT PK
>]; + articlelistarticle [label=<
articlelistarticle
idINT PK
articlelist_idINT FK
article_idINT FK
countINT
sortINT
>]; + optionslist [label=<
optionslist
idINT PK
>]; + optionslistarticle [label=<
optionslistarticle
idINT PK
optionslist_idINT FK
article_idINT FK
countINT
sortINT
mandatedBIT
>]; + articlehistory [label=<
articlehistory
idINT PK
article_idINT FK
companyuser_id?INT FK
dateDATETIME2
textNVARCHAR(MAX)
>]; + articleean [label=<
articleean
idINT PK
article_idINT FK
eanNVARCHAR(50)
>]; + article [label=<
article
idINT PK
brand_id?INT FK
articlelist_id?INT FK
optionslist_id?INT FK
parentarticle_id?INT FK
unit_idINT FK
parentattributename_id?INT FK
company_idINT FK
sku?NVARCHAR(100)
unitamountFLOAT
weightFLOAT
track_stockBIT
is_parentBIT
parentsortINT
created_atDATETIME2
updated_atDATETIME2
>]; + articlesupplier [label=<
articlesupplier
idINT PK
article_idINT FK
tax_id?INT FK
entity_idINT FK
net?FLOAT
sku?NVARCHAR(100)
stock?FLOAT
puFLOAT
sortINT
>]; + category [label=<
category
idINT PK
parent_id?INT FK
sortINT
updated_atDATETIME2
>]; + categoryarticle [label=<
categoryarticle
idINT PK
article_idINT FK
category_idINT FK
>]; } subgraph cluster_media { label="Media"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - pic [label=<
pic
idINT PK
wINT
hINT
sizeBIGINT
hashNVARCHAR(64)
thumbwINT
thumbhINT
thumbhashNVARCHAR(64)
smallthumbwINT
smallthumbhINT
sourceNVARCHAR(MAX)
fullbinaryVARBINARY(MAX)
thumbbinaryVARBINARY(MAX)
smallthumbbinaryVARBINARY(MAX)
>]; + pic [label=<
pic
idINT PK
wINT
hINT
sizeBIGINT
hashNVARCHAR(64)
thumbwINT
thumbhINT
thumbhashNVARCHAR(64)
smallthumbwINT
smallthumbhINT
sourceNVARCHAR(MAX)
fullbinaryVARBINARY(MAX)
thumbbinaryVARBINARY(MAX)
smallthumbbinaryVARBINARY(MAX)
>]; + brandpic [label=<
brandpic
idINT PK
brand_idINT FK
pic_idINT FK
sortINT
>]; articlepic [label=<
articlepic
idINT PK
pic_idINT FK
article_idINT FK
sortINT
>]; categorypic [label=<
categorypic
idINT PK
pic_idINT FK
category_idINT FK
sortINT
>]; - brandpic [label=<
brandpic
idINT PK
pic_idINT FK
brand_idINT FK
sortINT
>]; + attributevaluepic [label=<
attributevaluepic
idINT PK
pic_idINT FK
attributevalue_idINT FK
sortINT
>]; file [label=<
file
idINT PK
hashNVARCHAR(64)
mimetypeNVARCHAR(255)
nameNVARCHAR(255)
sizeBIGINT
createdDATETIME2
modifiedDATETIME2
contentVARBINARY(MAX)
thumbavif?VARBINARY(MAX)
thumbx?INT
thumby?INT
meta?NVARCHAR(MAX)
>]; } subgraph cluster_manifests { label="Documents & Shipping"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - manifestarticle [label=<
manifestarticle
idINT PK
manifest_idINT FK
sku?NVARCHAR(100)
name?NVARCHAR(255)
puFLOAT
amountFLOAT
netFLOAT
comment?NVARCHAR(MAX)
rebateFLOAT
taxrateFLOAT
>]; - ledger [label=<
ledger
idINT PK
manifestarticle_idINT FK
warehouse_id?INT FK
transaction_typeNVARCHAR(100)
amountFLOAT
transaction_textNVARCHAR(MAX)
hash_versionINT
prev_hash?NVARCHAR(128)
created_atDATETIME2
>]; - manifestattachment [label=<
manifestattachment
idINT PK
file_idINT FK
manifest_idINT FK
sortINT
>]; - package [label=<
package
idINT PK
shipping_idINT FK
entityaddress_idINT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
stateNVARCHAR(100)
details?NVARCHAR(MAX)
>]; - manifest [label=<
manifest
idINT PK
company_idINT FK
entity_id?INT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
external_number?NVARCHAR(100)
dateDATETIME2
created_atDATETIME2
>]; - shipping [label=<
shipping
idINT PK
manifest_idINT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
stateNVARCHAR(100)
>]; warehouse [label=<
warehouse
idINT PK
company_idINT FK
nameNVARCHAR(255)
sortINT
>]; + manifestarticle [label=<
manifestarticle
idINT PK
manifest_idINT FK
sku?NVARCHAR(100)
name?NVARCHAR(255)
puFLOAT
amountFLOAT
netFLOAT
comment?NVARCHAR(MAX)
rebateFLOAT
taxrateFLOAT
>]; + manifest [label=<
manifest
idINT PK
company_idINT FK
entity_id?INT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
external_number?NVARCHAR(100)
dateDATETIME2
created_atDATETIME2
>]; + package [label=<
package
idINT PK
entityaddress_idINT FK
shipping_idINT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
stateNVARCHAR(100)
details?NVARCHAR(MAX)
>]; + manifestattachment [label=<
manifestattachment
idINT PK
file_idINT FK
manifest_idINT FK
sortINT
>]; + shipping [label=<
shipping
idINT PK
manifest_idINT FK
numberNVARCHAR(100)
typeNVARCHAR(100)
stateNVARCHAR(100)
>]; + ledger [label=<
ledger
idINT PK
warehouse_id?INT FK
manifestarticle_idINT FK
transaction_typeNVARCHAR(100)
amountFLOAT
transaction_textNVARCHAR(MAX)
hash_versionINT
prev_hash?NVARCHAR(128)
created_atDATETIME2
>]; } subgraph cluster_commerce { label="Pricing & Payments"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; tax [label=<
tax
idINT PK
rateDECIMAL(18,4)
>]; + price [label=<
price
idINT PK
article_idINT FK
tax_idINT FK
customergroup_idINT FK
minmultiplierDECIMAL(18,4)
netFLOAT
>]; account [label=<
account
idINT PK
company_idINT FK
typeNVARCHAR(100)
nameNVARCHAR(255)
>]; - price [label=<
price
idINT PK
tax_idINT FK
article_idINT FK
customergroup_idINT FK
minmultiplierDECIMAL(18,4)
netFLOAT
>]; payment [label=<
payment
idINT PK
account_idINT FK
manifest_idINT FK
typeNVARCHAR(100)
amountFLOAT
>]; } subgraph cluster_units { @@ -89,9 +90,9 @@ digraph schema { label="POS"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - printer [label=<
printer
idINT PK
company_idINT FK
addressNVARCHAR(255)
typeNVARCHAR(50)
model?NVARCHAR(255)
serial?NVARCHAR(255)
sortINT
desc?NVARCHAR(MAX)
>]; - posterminal [label=<
posterminal
idINT PK
root_category_id?INT FK
company_idINT FK
nameNVARCHAR(255)
token?NVARCHAR(255)
pairingpin?NVARCHAR(50)
paired_at?DATETIME2
clientserial?NVARCHAR(255)
maxknowntombstoneid?INT
sync_root_articlesBIT
lastseen_at?DATETIME2
updated_atDATETIME2
>]; posterminalcategory [label=<
posterminalcategory
idINT PK
category_idINT FK
posterminal_idINT FK
>]; + posterminal [label=<
posterminal
idINT PK
root_category_id?INT FK
company_idINT FK
nameNVARCHAR(255)
token?NVARCHAR(255)
pairingpin?NVARCHAR(50)
paired_at?DATETIME2
clientserial?NVARCHAR(255)
maxknowntombstoneid?INT
sync_root_articlesBIT
lastseen_at?DATETIME2
updated_atDATETIME2
>]; + printer [label=<
printer
idINT PK
company_idINT FK
addressNVARCHAR(255)
typeNVARCHAR(50)
model?NVARCHAR(255)
serial?NVARCHAR(255)
sortINT
desc?NVARCHAR(MAX)
>]; labeltemplate [label=<
labeltemplate
idINT PK
company_idINT FK
nameNVARCHAR(255)
widthINT
heightINT
dpiINT
typeNVARCHAR(50)
contentNVARCHAR(MAX)
thumb?VARBINARY(MAX)
>]; } subgraph cluster_ai { @@ -106,107 +107,109 @@ digraph schema { label="Properties & Attributes"; labeljust="l"; fontsize=15; style="rounded,filled"; fillcolor="#202a3a"; color="#3f4c5f"; fontcolor="#e2e8f0"; margin=14; - propertyname [label=<
propertyname
idINT PK
company_idINT FK
nameNVARCHAR(255)
sortINT
exclusiveBIT
>]; - attributevalue [label=<
attributevalue
idINT PK
attribute_idINT FK
valueNVARCHAR(255)
sortINT
>]; - categoryproperty [label=<
categoryproperty
idINT PK
property_idINT FK
category_idINT FK
valueNVARCHAR(MAX)
sortINT
>]; - categoryattributevalue [label=<
categoryattributevalue
idINT PK
attributevalue_idINT FK
category_idINT FK
sortINT
>]; + articleproperty [label=<
articleproperty
idINT PK
article_idINT FK
property_idINT FK
valueNVARCHAR(MAX)
sortINT
>]; + articleattributevalue [label=<
articleattributevalue
idINT PK
article_idINT FK
attributevalue_idINT FK
sortINT
>]; + categoryproperty [label=<
categoryproperty
idINT PK
category_idINT FK
property_idINT FK
valueNVARCHAR(MAX)
sortINT
>]; + categoryattributevalue [label=<
categoryattributevalue
idINT PK
category_idINT FK
attributevalue_idINT FK
sortINT
>]; + attributevalue [label=<
attributevalue
idINT PK
attribute_idINT FK
valueNVARCHAR(255)
sortINT
>]; attributename [label=<
attributename
idINT PK
company_idINT FK
nameNVARCHAR(255)
sortINT
exclusiveBIT
>]; - articleproperty [label=<
articleproperty
idINT PK
property_idINT FK
article_idINT FK
valueNVARCHAR(MAX)
sortINT
>]; - articleattributevalue [label=<
articleattributevalue
idINT PK
attributevalue_idINT FK
article_idINT FK
sortINT
>]; + propertyname [label=<
propertyname
idINT PK
company_idINT FK
nameNVARCHAR(255)
sortINT
exclusiveBIT
>]; } __legend [label=<
Legend
PKprimary key
FKforeign key
?nullable column
—FOREIGN KEY constraint
- -naming convention only, no constraint
>]; - google_auth:selected_company:w -> company:in14:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_google_auth_selected_company", weight=3]; + google_auth:selected_company:w -> company:in15:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_google_auth_selected_company", weight=3]; category:parent_id:e -> category:id:e [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_category_parent", constraint=false]; - company:root_category_id:w -> category:in7:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_company_root_category", weight=3]; + company:root_category_id:w -> category:in8:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_company_root_category", weight=3]; company:default_language_id:w -> language:in1:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_company_default_language", constraint=false, weight=1]; company:taxrate:w -> tax:in4:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_company_taxrate", constraint=false, weight=1]; company:reducedtaxrate:w -> tax:in2:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_company_reducedtaxrate", constraint=false, weight=1]; company:taxfreerate:w -> tax:in3:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_company_taxfreerate", constraint=false, weight=1]; - customergroup:company_id:se -> company:in8:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_customergroup_company", weight=3]; - company:poscustomergroup_id:ne -> customergroup:in1:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_company_poscustomergroup", constraint=false, weight=1]; + customergroup:company_id:se -> company:in9:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_customergroup_company", weight=3]; + company:poscustomergroup_id:se -> customergroup:in1:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_company_poscustomergroup", constraint=false, weight=1]; entity:customergroup_id:sw -> customergroup:in2:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_entity_customergroup", weight=3]; - entityaddress:entity_id:ne -> entity:in2:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_entityaddress_entity", weight=3]; - entitycontact:entity_id:sw -> entity:in3:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_entitycontact_entity", weight=3]; + entityaddress:entity_id:ne -> entity:in1:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_entityaddress_entity", weight=3]; + entitycontact:entity_id:se -> entity:in2:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_entitycontact_entity", weight=3]; entityhistory:entity_id:sw -> entity:in4:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_entityhistory_entity", weight=3]; - entityhistory:companyuser_id:se -> companyuser:in3:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_entityhistory_companyuser", constraint=false, weight=1]; - unit:company_id:e -> company:in3:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_unit_company", weight=3]; - unittext:unit_id:w -> unit:in1:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_unittext_unit", weight=3]; - unittext:language_id:w -> language:in0:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_unittext_language", constraint=false, weight=1]; - brand:company_id:w -> company:in5:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_brand_company", weight=3]; - article:company_id:w -> company:in4:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_article_company", weight=3]; + entityhistory:companyuser_id:se -> companyuser:in2:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_entityhistory_companyuser", constraint=false, weight=1]; + unit:company_id:w -> company:in4:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_unit_company", weight=3]; + unittext:unit_id:sw -> unit:in1:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_unittext_unit", weight=3]; + unittext:language_id:w -> language:in3:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_unittext_language", constraint=false, weight=1]; + brand:company_id:e -> company:in0:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_brand_company", weight=3]; + article:company_id:e -> company:in2:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_article_company", weight=3]; article:unit_id:e -> unit:in0:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_article_unit", constraint=false, weight=1]; - article:brand_id:w -> brand:in1:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_article_brand", constraint=false, weight=1]; - article:articlelist_id:w -> articlelist:in0:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_article_articlelist", constraint=false, weight=1]; + article:brand_id:w -> brand:in0:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_article_brand", constraint=false, weight=1]; + article:articlelist_id:w -> articlelist:in1:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_article_articlelist", constraint=false, weight=1]; article:optionslist_id:w -> optionslist:in1:n [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_article_optionslist", constraint=false, weight=1]; article:parentarticle_id:e -> article:id:e [color="#c79bff", fontcolor="#c79bff", tooltip="FK_article_parentarticle", constraint=false]; - article:parentattributename_id:ne -> attributename:in0:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_article_parentattributename", constraint=false, weight=1]; - article:parentattributename_id:ne -> attributename:in0:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_article_parentattributename", constraint=false, weight=1]; - articlehistory:article_id:sw -> article:in6:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_articlehistory_article", weight=3]; + article:parentattributename_id:se -> attributename:in1:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_article_parentattributename", constraint=false, weight=1]; + article:parentattributename_id:se -> attributename:in1:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_article_parentattributename", constraint=false, weight=1]; + articlehistory:article_id:sw -> article:in2:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_articlehistory_article", weight=3]; articlehistory:companyuser_id:e -> companyuser:in0:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_articlehistory_companyuser", constraint=false, weight=1]; companyhistory:company_id:nw -> company:in11:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_companyhistory_company", weight=3]; companyhistory:companyuser_id:e -> companyuser:in1:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_companyhistory_companyuser", constraint=false, weight=1]; - articletombstone:company_id:w -> company:in6:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_articletombstone_company", weight=3]; - articleean:article_id:se -> article:in8:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_articleean_article", weight=3]; - articlepic:article_id:se -> article:in3:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_articlepic_article", weight=3]; - articlepic:pic_id:w -> pic:in0:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_articlepic_pic", constraint=false, weight=1]; - brandpic:brand_id:e -> brand:in0:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_brandpic_brand", weight=3]; - brandpic:pic_id:w -> pic:in2:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_brandpic_pic", constraint=false, weight=1]; - articlelistarticle:articlelist_id:se -> articlelist:in1:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_articlelistarticle_articlelist", weight=3]; - articlelistarticle:article_id:w -> article:in10:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_articlelistarticle_article", constraint=false, weight=1]; - optionslistarticle:optionslist_id:sw -> optionslist:in0:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_optionslistarticle_optionslist", weight=3]; - optionslistarticle:article_id:w -> article:in11:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_optionslistarticle_article", constraint=false, weight=1]; - categoryarticle:category_id:sw -> category:in2:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_categoryarticle_category", weight=3]; - categoryarticle:article_id:sw -> article:in5:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_categoryarticle_article", constraint=false, weight=1]; - categorypic:category_id:sw -> category:in5:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_categorypic_category", weight=3]; - categorypic:pic_id:w -> pic:in1:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_categorypic_pic", constraint=false, weight=1]; - categorytext:category_id:w -> category:in3:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_categorytext_category", weight=3]; - categorytext:language_id:w -> language:in2:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_categorytext_language", constraint=false, weight=1]; - articletext:article_id:e -> article:in4:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_articletext_article", weight=3]; - articletext:language_id:w -> language:in3:n [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_articletext_language", constraint=false, weight=1]; - price:tax_id:e -> tax:in0:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_price_tax", constraint=false, weight=1]; - price:article_id:w -> article:in2:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_price_article", weight=3]; - price:customergroup_id:e -> customergroup:in0:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_price_customergroup", constraint=false, weight=1]; - articlesupplier:article_id:nw -> article:in9:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_articlesupplier_article", weight=3]; - articlesupplier:entity_id:e -> entity:in1:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_articlesupplier_entity", constraint=false, weight=1]; - articlesupplier:tax_id:e -> tax:in1:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articlesupplier_tax", constraint=false, weight=1]; - manifest:company_id:sw -> company:in7:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_manifest_company", weight=3]; - manifest:entity_id:e -> entity:in0:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_manifest_entity", constraint=false, weight=1]; - manifestarticle:manifest_id:sw -> manifest:in2:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_manifestarticle_manifest", weight=3]; - warehouse:company_id:se -> company:in9:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_warehouse_company", weight=3]; - ledger:manifestarticle_id:sw -> manifestarticle:in0:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_ledger_manifestarticle", weight=3]; - ledger:warehouse_id:e -> warehouse:in0:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_ledger_warehouse", constraint=false, weight=1]; - numbers:company_id:se -> company:in10:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_numbers_company", weight=3]; - companyuser:google_auth_id:e -> google_auth:in0:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_companyuser_google_auth", constraint=false, weight=1]; - companyuser:company_id:w -> company:in12:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_companyuser_company", weight=3]; - modelconversation:companyuser_id:w -> companyuser:in2:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_modelconversation_companyuser", weight=3]; - modelvfs:company_id:w -> company:in15:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_modelvfs_company", weight=3]; - modelmessage:conversation_id:se -> modelconversation:in0:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_modelmessage_conversation", weight=3]; - companysetting:company_id:e -> company:in13:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_companysetting_company", weight=3]; - posterminal:company_id:w -> company:in17:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_posterminal_company", weight=3]; - posterminal:root_category_id:w -> category:in6:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_posterminal_root_category", constraint=false, weight=1]; - posterminalcategory:posterminal_id:nw -> posterminal:in0:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_posterminalcategory_posterminal", weight=3]; - posterminalcategory:category_id:w -> category:in8:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_posterminalcategory_category", constraint=false, weight=1]; - printer:company_id:w -> company:in16:n [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_printer_company", weight=3]; - labeltemplate:company_id:w -> company:in18:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_labeltemplate_company", weight=3]; - manifestattachment:manifest_id:sw -> manifest:in1:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_manifestattachment_manifest", weight=3]; - manifestattachment:file_id:w -> file:in0:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_manifestattachment_file", constraint=false, weight=1]; - propertyname:company_id:e -> company:in0:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_propertyname_company", weight=3]; - articleproperty:article_id:e -> article:in1:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_articleproperty_article", weight=3]; - articleproperty:property_id:w -> propertyname:in1:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articleproperty_property", constraint=false, weight=1]; - attributename:company_id:e -> company:in1:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_attributename_company", weight=3]; - attributevalue:attribute_id:e -> attributename:in2:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_attributevalue_attribute", weight=3]; - articleattributevalue:article_id:e -> article:in0:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_articleattributevalue_article", weight=3]; - articleattributevalue:attributevalue_id:w -> attributevalue:in1:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_articleattributevalue_attributevalue", constraint=false, weight=1]; - categoryproperty:category_id:e -> category:in0:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_categoryproperty_category", weight=3]; - categoryproperty:property_id:e -> propertyname:in0:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_categoryproperty_property", constraint=false, weight=1]; - categoryattributevalue:category_id:e -> category:in1:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_categoryattributevalue_category", weight=3]; - categoryattributevalue:attributevalue_id:e -> attributevalue:in0:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_categoryattributevalue_attributevalue", constraint=false, weight=1]; - account:company_id:w -> company:in2:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_account_company", weight=3]; - payment:account_id:w -> account:in0:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_payment_account", constraint=false, weight=1]; - payment:manifest_id:e -> manifest:in0:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_payment_manifest", weight=3]; - shipping:manifest_id:sw -> manifest:in3:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_shipping_manifest", weight=3]; - package:shipping_id:sw -> shipping:in0:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_package_shipping", constraint=false, weight=1]; - package:entityaddress_id:e -> entityaddress:in0:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_package_entityaddress", weight=3]; + articletombstone:company_id:e -> company:in1:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_articletombstone_company", weight=3]; + articleean:article_id:ne -> article:in3:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_articleean_article", weight=3]; + articlepic:article_id:se -> article:in6:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_articlepic_article", weight=3]; + articlepic:pic_id:w -> pic:in1:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_articlepic_pic", constraint=false, weight=1]; + brandpic:brand_id:e -> brand:in1:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_brandpic_brand", weight=3]; + brandpic:pic_id:w -> pic:in0:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_brandpic_pic", constraint=false, weight=1]; + attributevaluepic:attributevalue_id:w -> attributevalue:in0:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_attributevaluepic_attributevalue", weight=3]; + attributevaluepic:pic_id:w -> pic:in3:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_attributevaluepic_pic", constraint=false, weight=1]; + articlelistarticle:articlelist_id:nw -> articlelist:in0:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_articlelistarticle_articlelist", weight=3]; + articlelistarticle:article_id:w -> article:in0:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_articlelistarticle_article", constraint=false, weight=1]; + optionslistarticle:optionslist_id:sw -> optionslist:in0:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_optionslistarticle_optionslist", weight=3]; + optionslistarticle:article_id:e -> article:in1:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_optionslistarticle_article", constraint=false, weight=1]; + categoryarticle:category_id:nw -> category:in1:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_categoryarticle_category", weight=3]; + categoryarticle:article_id:sw -> article:in7:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_categoryarticle_article", constraint=false, weight=1]; + categorypic:category_id:sw -> category:in2:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_categorypic_category", weight=3]; + categorypic:pic_id:w -> pic:in2:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_categorypic_pic", constraint=false, weight=1]; + categorytext:category_id:e -> category:in3:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_categorytext_category", weight=3]; + categorytext:language_id:w -> language:in0:n [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_categorytext_language", constraint=false, weight=1]; + articletext:article_id:e -> article:in9:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articletext_article", weight=3]; + articletext:language_id:w -> language:in2:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_articletext_language", constraint=false, weight=1]; + price:tax_id:e -> tax:in1:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_price_tax", constraint=false, weight=1]; + price:article_id:w -> article:in8:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_price_article", weight=3]; + price:customergroup_id:e -> customergroup:in0:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_price_customergroup", constraint=false, weight=1]; + articlesupplier:article_id:sw -> article:in5:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_articlesupplier_article", weight=3]; + articlesupplier:entity_id:e -> entity:in0:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_articlesupplier_entity", constraint=false, weight=1]; + articlesupplier:tax_id:e -> tax:in0:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_articlesupplier_tax", constraint=false, weight=1]; + manifest:company_id:w -> company:in17:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_manifest_company", weight=3]; + manifest:entity_id:e -> entity:in3:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_manifest_entity", constraint=false, weight=1]; + manifestarticle:manifest_id:sw -> manifest:in1:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_manifestarticle_manifest", weight=3]; + warehouse:company_id:sw -> company:in16:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_warehouse_company", weight=3]; + ledger:manifestarticle_id:w -> manifestarticle:in0:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_ledger_manifestarticle", weight=3]; + ledger:warehouse_id:w -> warehouse:in0:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_ledger_warehouse", constraint=false, weight=1]; + numbers:company_id:se -> company:in13:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_numbers_company", weight=3]; + companyuser:google_auth_id:e -> google_auth:in0:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_companyuser_google_auth", constraint=false, weight=1]; + companyuser:company_id:w -> company:in12:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_companyuser_company", weight=3]; + modelconversation:companyuser_id:w -> companyuser:in3:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_modelconversation_companyuser", weight=3]; + modelvfs:company_id:w -> company:in18:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_modelvfs_company", weight=3]; + modelmessage:conversation_id:se -> modelconversation:in0:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_modelmessage_conversation", weight=3]; + companysetting:company_id:e -> company:in14:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_companysetting_company", weight=3]; + posterminal:company_id:e -> company:in7:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_posterminal_company", weight=3]; + posterminal:root_category_id:w -> category:in7:n [color="#56d68a", fontcolor="#56d68a", tooltip="FK_posterminal_root_category", constraint=false, weight=1]; + posterminalcategory:posterminal_id:se -> posterminal:in0:n [color="#66b3ff", fontcolor="#66b3ff", tooltip="FK_posterminalcategory_posterminal", weight=3]; + posterminalcategory:category_id:e -> category:in6:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_posterminalcategory_category", constraint=false, weight=1]; + printer:company_id:se -> company:in8:n [color="#ff6b6b", fontcolor="#ff6b6b", tooltip="FK_printer_company", weight=3]; + labeltemplate:company_id:se -> company:in10:n [color="#6bdf9a", fontcolor="#6bdf9a", tooltip="FK_labeltemplate_company", weight=3]; + manifestattachment:manifest_id:sw -> manifest:in3:n [color="#5aa7ff", fontcolor="#5aa7ff", tooltip="FK_manifestattachment_manifest", weight=3]; + manifestattachment:file_id:e -> file:in0:n [color="#f5c15c", fontcolor="#f5c15c", tooltip="FK_manifestattachment_file", constraint=false, weight=1]; + propertyname:company_id:e -> company:in6:n [color="#c79bff", fontcolor="#c79bff", tooltip="FK_propertyname_company", weight=3]; + articleproperty:article_id:e -> article:in10:n [color="#ff9f5a", fontcolor="#ff9f5a", tooltip="FK_articleproperty_article", weight=3]; + articleproperty:property_id:w -> propertyname:in1:n [color="#5cd6d6", fontcolor="#5cd6d6", tooltip="FK_articleproperty_property", constraint=false, weight=1]; + attributename:company_id:e -> company:in5:n [color="#ff7fc2", fontcolor="#ff7fc2", tooltip="FK_attributename_company", weight=3]; + attributevalue:attribute_id:se -> attributename:in2:n [color="#8f95ff", fontcolor="#8f95ff", tooltip="FK_attributevalue_attribute", weight=3]; + articleattributevalue:article_id:e -> article:in11:n [color="#58d18a", fontcolor="#58d18a", tooltip="FK_articleattributevalue_article", weight=3]; + articleattributevalue:attributevalue_id:w -> attributevalue:in1:n [color="#ff8f66", fontcolor="#ff8f66", tooltip="FK_articleattributevalue_attributevalue", constraint=false, weight=1]; + categoryproperty:category_id:w -> category:in5:n [color="#4fc4e8", fontcolor="#4fc4e8", tooltip="FK_categoryproperty_category", weight=3]; + categoryproperty:property_id:e -> propertyname:in0:n [color="#a98cff", fontcolor="#a98cff", tooltip="FK_categoryproperty_property", constraint=false, weight=1]; + categoryattributevalue:category_id:w -> category:in4:n [color="#ff6f6f", fontcolor="#ff6f6f", tooltip="FK_categoryattributevalue_category", weight=3]; + categoryattributevalue:attributevalue_id:e -> attributevalue:in2:n [color="#4ecb8f", fontcolor="#4ecb8f", tooltip="FK_categoryattributevalue_attributevalue", constraint=false, weight=1]; + account:company_id:e -> company:in3:n [color="#5aa7e6", fontcolor="#5aa7e6", tooltip="FK_account_company", weight=3]; + payment:account_id:w -> account:in0:n [color="#ff7aa8", fontcolor="#ff7aa8", tooltip="FK_payment_account", constraint=false, weight=1]; + payment:manifest_id:e -> manifest:in0:n [color="#e0b25a", fontcolor="#e0b25a", tooltip="FK_payment_manifest", weight=3]; + shipping:manifest_id:sw -> manifest:in2:n [color="#56c8c8", fontcolor="#56c8c8", tooltip="FK_shipping_manifest", weight=3]; + package:shipping_id:sw -> shipping:in0:n [color="#ff5f9e", fontcolor="#ff5f9e", tooltip="FK_package_shipping", constraint=false, weight=1]; + package:entityaddress_id:w -> entityaddress:in0:n [color="#ffb25a", fontcolor="#ffb25a", tooltip="FK_package_entityaddress", weight=3]; } \ No newline at end of file diff --git a/schema-graph.svg b/schema-graph.svg index 08de2cb..1e9e348 100644 --- a/schema-graph.svg +++ b/schema-graph.svg @@ -4,297 +4,282 @@ - - + + schema - + cluster_identity - -Identity & Company + +Identity & Company cluster_i18n - -Localization + +Localization cluster_catalog - -Catalog + +Catalog cluster_media - -Media + +Media cluster_manifests - -Documents & Shipping + +Documents & Shipping cluster_commerce - -Pricing & Payments + +Pricing & Payments cluster_units - -Units + +Units cluster_pos - -POS + +POS cluster_ai - -AI & Models + +AI & Models cluster_attributes - -Properties & Attributes - - - -meta - - -meta - - -key -NVARCHAR(255) - - -value -NVARCHAR(MAX) + +Properties & Attributes - + customergroup - - - - - -customergroup - - -id -INT -PK - - -company_id -? -INT -FK - - -name -NVARCHAR(255) - - -sort -INT - - -updated_at -DATETIME2 + + + + + +customergroup + + +id +INT +PK + + +company_id +? +INT +FK + + +name +NVARCHAR(255) + + +sort +INT + + +updated_at +DATETIME2 - + company - - - - - - - - - - - - - - - - - - - - - -company - - -id -INT -PK - - -default_language_id -? -INT -FK - - -taxrate -? -INT -FK - - -reducedtaxrate -? -INT -FK - - -taxfreerate -? -INT -FK - - -root_category_id -? -INT -FK - - -poscustomergroup_id -INT -FK - - -name -NVARCHAR(255) + + + + + + + + + + + + + + + + + + + + + +company + + +id +INT +PK + + +root_category_id +? +INT +FK + + +taxrate +? +INT +FK + + +reducedtaxrate +? +INT +FK + + +taxfreerate +? +INT +FK + + +default_language_id +? +INT +FK + + +poscustomergroup_id +INT +FK + + +name +NVARCHAR(255) customergroup:se->company:n - - + + -company:ne->customergroup:n +company:se->customergroup:n - - + + language - - - - - - -language - - -id -INT -PK - - -iso639 -NVARCHAR(10) + + + + + + +language + + +id +INT +PK + + +iso639 +NVARCHAR(10) company:w->language:n - - + + - + category - - - - - - - - - - - -category - - -id -INT -PK - - -parent_id -? -INT -FK - - -sort -INT - - -updated_at -DATETIME2 + + + + + + + + + + + +category + + +id +INT +PK + + +parent_id +? +INT +FK + + +sort +INT + + +updated_at +DATETIME2 company:w->category:n - - + + - + tax - - - - - - - -tax - - -id -INT -PK - - -rate -DECIMAL(18,4) + + + + + + + +tax + + +id +INT +PK + + +rate +DECIMAL(18,4) company:w->tax:n - - + + @@ -302,8 +287,8 @@ company:w->tax:n - - + + @@ -311,188 +296,203 @@ company:w->tax:n - - + + - - -entityaddress - - - -entityaddress - - -id -INT -PK - - -entity_id -INT -FK - - -first_name? -NVARCHAR(255) - - -name? -NVARCHAR(255) - - -street? -NVARCHAR(255) - - -streetnumber? -NVARCHAR(50) - - -zip? -NVARCHAR(50) - - -city? -NVARCHAR(255) - - -county? -NVARCHAR(255) - - -addresstype -NVARCHAR(50) - - -sort -INT - - - -entity - - - - - - - -entity - - -id -INT -PK - - -customergroup_id -INT -FK - - -first_name? -NVARCHAR(255) - - -name -NVARCHAR(255) - - -number? -NVARCHAR(100) - - -created_at -DATETIME2 - - -updated_at -DATETIME2 - - - -entityaddress:ne->entity:n - - - - - + + +meta + + +meta + + +key +NVARCHAR(255) + + +value +NVARCHAR(MAX) - + companyhistory - - -companyhistory - - -id -INT -PK - - -company_id -INT -FK - - -companyuser_id -? -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) + + +companyhistory + + +id +INT +PK + + +company_id +INT +FK + + +companyuser_id +? +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) companyhistory:nw->company:n - - + + companyuser - - - - - - -companyuser - - -id -INT -PK - - -company_id -INT -FK - - -google_auth_id -INT -FK + + + + + + +companyuser + + +id +INT +PK + + +company_id +INT +FK + + +google_auth_id +INT +FK companyhistory:e->companyuser:n - - + + + + + + + +entityaddress + + + +entityaddress + + +id +INT +PK + + +entity_id +INT +FK + + +first_name? +NVARCHAR(255) + + +name? +NVARCHAR(255) + + +street? +NVARCHAR(255) + + +streetnumber? +NVARCHAR(50) + + +zip? +NVARCHAR(50) + + +city? +NVARCHAR(255) + + +county? +NVARCHAR(255) + + +addresstype +NVARCHAR(50) + + +sort +INT + + + +entity + + + + + + + +entity + + +id +INT +PK + + +customergroup_id +INT +FK + + +first_name? +NVARCHAR(255) + + +name +NVARCHAR(255) + + +number? +NVARCHAR(100) + + +created_at +DATETIME2 + + +updated_at +DATETIME2 + + + +entityaddress:ne->entity:n + + + @@ -500,185 +500,185 @@ entity:sw->customergroup:n - - + + numbers - - -numbers - - -id -INT -PK - - -company_id -INT -FK - - -type -NVARCHAR(100) - - -prefix -NVARCHAR(50) - - -padding -INT - - -next -INT + + +numbers + + +id +INT +PK + + +company_id +INT +FK + + +type +NVARCHAR(100) + + +prefix +NVARCHAR(50) + + +padding +INT + + +next +INT - + numbers:se->company:n - - - + + + entitycontact - - -entitycontact - - -id -INT -PK - - -entity_id -INT -FK - - -contacttype -NVARCHAR(50) - - -contact -NVARCHAR(255) - - -sort -INT + + +entitycontact + + +id +INT +PK + + +entity_id +INT +FK + + +contacttype +NVARCHAR(50) + + +contact +NVARCHAR(255) + + +sort +INT -entitycontact:sw->entity:n +entitycontact:se->entity:n - - + + - + companyuser:w->company:n - - - + + + google_auth - - - -google_auth - - -id -INT -PK - - -selected_company -? -INT -FK - - -email -NVARCHAR(320) - - -picture? -NVARCHAR(2048) - - -picturebinary? -VARBINARY(MAX) - - -sub? -NVARCHAR(255) - - -created_at -DATETIME2 + + + +google_auth + + +id +INT +PK + + +selected_company +? +INT +FK + + +email +NVARCHAR(320) + + +picture? +NVARCHAR(2048) + + +picturebinary? +VARBINARY(MAX) + + +sub? +NVARCHAR(255) + + +created_at +DATETIME2 - + companyuser:e->google_auth:n - - - + + + entityhistory - - -entityhistory - - -id -INT -PK - - -entity_id -INT -FK - - -companyuser_id -? -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) + + +entityhistory + + +id +INT +PK + + +entity_id +INT +FK + + +companyuser_id +? +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) entityhistory:sw->entity:n - - + + @@ -686,50 +686,50 @@ entityhistory:se->companyuser:n - - + + companysetting - - -companysetting - - -id -INT -PK - - -company_id -INT -FK - - -key -NVARCHAR(255) - - -value -NVARCHAR(MAX) - - -frontend -BIT - - -writeonly -BIT + + +companysetting + + +id +INT +PK + + +company_id +INT +FK + + +key +NVARCHAR(255) + + +value +NVARCHAR(MAX) + + +frontend +BIT + + +writeonly +BIT - + companysetting:e->company:n - - - + + + @@ -737,384 +737,549 @@ google_auth:w->company:n - - + + - + -unittext - - -unittext - - -id -INT -PK - - -language_id -INT -FK - - -unit_id -INT -FK - - -symbol -NVARCHAR(50) - - -name -NVARCHAR(255) +articletext + + +articletext + + +id +INT +PK + + +article_id +INT +FK + + +language_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) - - -unittext:w->language:n - - - + + +articletext:w->language:n + + + - - -unit - - - - -unit - - -id -INT -PK - - -company_id -INT -FK - - -si -NVARCHAR(50) - - -basesi -NVARCHAR(50) - - -basesifactor -FLOAT + + +article + + + + + + + + + + + + + + +article + + +id +INT +PK + + +brand_id +? +INT +FK + + +articlelist_id +? +INT +FK + + +optionslist_id +? +INT +FK + + +parentarticle_id +? +INT +FK + + +unit_id +INT +FK + + +parentattributename_id +? +INT +FK + + +company_id +INT +FK + + +sku? +NVARCHAR(100) + + +unitamount +FLOAT + + +weight +FLOAT + + +track_stock +BIT + + +is_parent +BIT + + +parentsort +INT + + +created_at +DATETIME2 + + +updated_at +DATETIME2 - - -unittext:w->unit:n - - - + + +articletext:e->article:n + + + categorytext - - -categorytext - - -id -INT -PK - - -language_id -INT -FK - - -category_id -INT -FK - - -name -NVARCHAR(255) - - -slug -NVARCHAR(255) - - -seo? -NVARCHAR(MAX) - - -desc? -NVARCHAR(MAX) + + +categorytext + + +id +INT +PK + + +category_id +INT +FK + + +language_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) - + categorytext:w->language:n - - - + + + - -categorytext:w->category:n - - - - - - - - -articletext - - -articletext - - -id -INT -PK - - -language_id -INT -FK - - -article_id -INT -FK - - -name -NVARCHAR(255) - - -slug -NVARCHAR(255) - - -seo? -NVARCHAR(MAX) - - -desc? -NVARCHAR(MAX) - - - -articletext:w->language:n - - - - - - - - -article - - - - - - - - - - - - - - -article - - -id -INT -PK - - -parentattributename_id -? -INT -FK - - -unit_id -INT -FK - - -parentarticle_id -? -INT -FK - - -articlelist_id -? -INT -FK - - -optionslist_id -? -INT -FK - - -brand_id -? -INT -FK - - -company_id -INT -FK - - -sku? -NVARCHAR(100) - - -unitamount -FLOAT - - -weight -FLOAT - - -track_stock -BIT - - -is_parent -BIT - - -parentsort -INT - - -created_at -DATETIME2 - - -updated_at -DATETIME2 - - -articletext:e->article:n - - - +categorytext:e->category:n + + + - + + +unittext + + +unittext + + +id +INT +PK + + +language_id +INT +FK + + +unit_id +INT +FK + + +symbol +NVARCHAR(50) + + +name +NVARCHAR(255) + + + +unittext:w->language:n + + + + + + + + +unit + + + + +unit + + +id +INT +PK + + +company_id +INT +FK + + +si +NVARCHAR(50) + + +basesi +NVARCHAR(50) + + +basesifactor +FLOAT + + + +unittext:sw->unit:n + + + + + + + -categoryarticle - - -categoryarticle - - -id -INT -PK - - -category_id -INT -FK - - -article_id -INT -FK +brand + + + + +brand + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +gsprpinfo? +NVARCHAR(MAX) - + + +brand:e->company:n + + + + + + + + +articletombstone + + +articletombstone + + +id +INT +PK + + +company_id +INT +FK + + +article_id? +INT + + +sku? +NVARCHAR(100) + + +name? +NVARCHAR(255) + + +taxrate? +DECIMAL(18,4) + + +net? +FLOAT + + +deleted_at +DATETIME2 + + + +articletombstone:e->company:n + + + + + + + + +articlelist + + + + +articlelist + + +id +INT +PK + + + +articlelistarticle + + +articlelistarticle + + +id +INT +PK + + +articlelist_id +INT +FK + + +article_id +INT +FK + + +count +INT + + +sort +INT + + + +articlelistarticle:nw->articlelist:n + + + + + + + + +articlelistarticle:w->article:n + + + + + + + + +optionslist + + + + +optionslist + + +id +INT +PK + + + +optionslistarticle + + +optionslistarticle + + +id +INT +PK + + +optionslist_id +INT +FK + + +article_id +INT +FK + + +count +INT + + +sort +INT + + +mandated +BIT + + -categoryarticle:sw->category:n - - - +optionslistarticle:sw->optionslist:n + + + - + -categoryarticle:sw->article:n - - - - - - - - -category:e->category:e - - - +optionslistarticle:e->article:n + + + - + articlehistory - - -articlehistory - - -id -INT -PK - - -article_id -INT -FK - - -companyuser_id -? -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) + + +articlehistory + + +id +INT +PK + + +article_id +INT +FK + + +companyuser_id +? +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) articlehistory:e->companyuser:n - - + + @@ -1122,17 +1287,74 @@ articlehistory:sw->article:n - - + + + + + + + +articleean + + +articleean + + +id +INT +PK + + +article_id +INT +FK + + +ean +NVARCHAR(50) + + + +articleean:ne->article:n + + + -article:w->company:n +article:e->company:n - - + + + + + + + +article:w->brand:n + + + + + + + + +article:w->articlelist:n + + + + + + + + +article:w->optionslist:n + + + @@ -1140,90 +1362,8 @@ article:e->article:e - - - - - - - -articlelist - - - - -articlelist - - -id -INT -PK - - - -article:w->articlelist:n - - - - - - - - -optionslist - - - - -optionslist - - -id -INT -PK - - - -article:w->optionslist:n - - - - - - - - -brand - - - - -brand - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -gsprpinfo? -NVARCHAR(MAX) - - - -article:w->brand:n - - - + + @@ -1231,512 +1371,285 @@ article:e->unit:n - - + + - + attributename - - - - - -attributename - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -sort -INT - - -exclusive -BIT + + + + + +attributename + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +sort +INT + + +exclusive +BIT -article:ne->attributename:n +article:se->attributename:n - - + + -article:ne->attributename:n +article:se->attributename:n - - - - - - - -articleean - - -articleean - - -id -INT -PK - - -article_id -INT -FK - - -ean -NVARCHAR(50) - - - -articleean:se->article:n - - - + + - + articlesupplier - - -articlesupplier - - -id -INT -PK - - -tax_id -? -INT -FK - - -article_id -INT -FK - - -entity_id -INT -FK - - -net? -FLOAT - - -sku? -NVARCHAR(100) - - -stock? -FLOAT - - -pu -FLOAT - - -sort -INT + + +articlesupplier + + +id +INT +PK + + +article_id +INT +FK + + +tax_id +? +INT +FK + + +entity_id +INT +FK + + +net? +FLOAT + + +sku? +NVARCHAR(100) + + +stock? +FLOAT + + +pu +FLOAT + + +sort +INT - + articlesupplier:e->entity:n - - - + + + - -articlesupplier:nw->article:n - - - + +articlesupplier:sw->article:n + + + - + articlesupplier:e->tax:n - - - + + + - - -articlelistarticle - - -articlelistarticle - - -id -INT -PK - - -article_id -INT -FK - - -articlelist_id -INT -FK - - -count -INT - - -sort -INT - - - -articlelistarticle:w->article:n - - - + + +category:e->category:e + + + - - -articlelistarticle:se->articlelist:n - - - - - - - - -optionslistarticle - - -optionslistarticle - - -id -INT -PK - - -article_id -INT -FK - - -optionslist_id -INT -FK - - -count -INT - - -sort -INT - - -mandated -BIT - - - -optionslistarticle:w->article:n - - - - - - - - -optionslistarticle:sw->optionslist:n - - - - - - - - -brand:w->company:n - - - - - - - + -articletombstone - - -articletombstone - - -id -INT -PK - - -company_id -INT -FK - - -article_id? -INT - - -sku? -NVARCHAR(100) - - -name? -NVARCHAR(255) - - -taxrate? -DECIMAL(18,4) - - -net? -FLOAT - - -deleted_at -DATETIME2 +categoryarticle + + +categoryarticle + + +id +INT +PK + + +article_id +INT +FK + + +category_id +INT +FK - - -articletombstone:w->company:n - - - + + +categoryarticle:sw->article:n + + + + + + + + +categoryarticle:nw->category:n + + + pic - - - - - -pic - - -id -INT -PK - - -w -INT - - -h -INT - - -size -BIGINT - - -hash -NVARCHAR(64) - - -thumbw -INT - - -thumbh -INT - - -thumbhash -NVARCHAR(64) - - -smallthumbw -INT - - -smallthumbh -INT - - -source -NVARCHAR(MAX) - - -fullbinary -VARBINARY(MAX) - - -thumbbinary -VARBINARY(MAX) - - -smallthumbbinary -VARBINARY(MAX) - - - -articlepic - - -articlepic - - -id -INT -PK - - -pic_id -INT -FK - - -article_id -INT -FK - - -sort -INT - - - -articlepic:se->article:n - - - - - - - - -articlepic:w->pic:n - - - - - - - - -categorypic - - -categorypic - - -id -INT -PK - - -pic_id -INT -FK - - -category_id -INT -FK - - -sort -INT - - - -categorypic:sw->category:n - - - - - - - - -categorypic:w->pic:n - - - - - + + + + + + +pic + + +id +INT +PK + + +w +INT + + +h +INT + + +size +BIGINT + + +hash +NVARCHAR(64) + + +thumbw +INT + + +thumbh +INT + + +thumbhash +NVARCHAR(64) + + +smallthumbw +INT + + +smallthumbh +INT + + +source +NVARCHAR(MAX) + + +fullbinary +VARBINARY(MAX) + + +thumbbinary +VARBINARY(MAX) + + +smallthumbbinary +VARBINARY(MAX) - + brandpic - - -brandpic - - -id -INT -PK - - -pic_id -INT -FK - - -brand_id -INT -FK - - -sort -INT + + +brandpic + + +id +INT +PK + + +brand_id +INT +FK + + +pic_id +INT +FK + + +sort +INT brandpic:e->brand:n - - + + @@ -1744,1238 +1657,1371 @@ brandpic:w->pic:n - - + + + + + + + +articlepic + + +articlepic + + +id +INT +PK + + +pic_id +INT +FK + + +article_id +INT +FK + + +sort +INT + + + +articlepic:se->article:n + + + + + + + + +articlepic:w->pic:n + + + + + + + + +categorypic + + +categorypic + + +id +INT +PK + + +pic_id +INT +FK + + +category_id +INT +FK + + +sort +INT + + + +categorypic:sw->category:n + + + + + + + + +categorypic:w->pic:n + + + + + + + + +attributevaluepic + + +attributevaluepic + + +id +INT +PK + + +pic_id +INT +FK + + +attributevalue_id +INT +FK + + +sort +INT + + + +attributevaluepic:w->pic:n + + + + + + + + +attributevalue + + + + + +attributevalue + + +id +INT +PK + + +attribute_id +INT +FK + + +value +NVARCHAR(255) + + +sort +INT + + + +attributevaluepic:w->attributevalue:n + + + - -file - - - -file - - -id -INT -PK - - -hash -NVARCHAR(64) - - -mimetype -NVARCHAR(255) - - -name -NVARCHAR(255) - - -size -BIGINT - - -created -DATETIME2 - - -modified -DATETIME2 - - -content -VARBINARY(MAX) - - -thumbavif? -VARBINARY(MAX) - - -thumbx? -INT - - -thumby? -INT - - -meta? -NVARCHAR(MAX) - - -manifestarticle - - - -manifestarticle - - -id -INT -PK - - -manifest_id -INT -FK - - -sku? -NVARCHAR(100) - - -name? -NVARCHAR(255) - - -pu -FLOAT - - -amount -FLOAT - - -net -FLOAT - - -comment? -NVARCHAR(MAX) - - -rebate -FLOAT - - -taxrate -FLOAT - - - -manifest - - - - - - -manifest - - -id -INT -PK - - -company_id -INT -FK - - -entity_id -? -INT -FK - - -number -NVARCHAR(100) - - -type -NVARCHAR(100) - - -external_number? -NVARCHAR(100) - - -date -DATETIME2 - - -created_at -DATETIME2 - - - -manifestarticle:sw->manifest:n - - - - - - - - -ledger - - -ledger - - -id -INT -PK - - -manifestarticle_id -INT -FK - - -warehouse_id -? -INT -FK - - -transaction_type -NVARCHAR(100) - - -amount -FLOAT - - -transaction_text -NVARCHAR(MAX) - - -hash_version -INT - - -prev_hash? -NVARCHAR(128) - - -created_at -DATETIME2 - - - -ledger:sw->manifestarticle:n - - - - - +file + + + +file + + +id +INT +PK + + +hash +NVARCHAR(64) + + +mimetype +NVARCHAR(255) + + +name +NVARCHAR(255) + + +size +BIGINT + + +created +DATETIME2 + + +modified +DATETIME2 + + +content +VARBINARY(MAX) + + +thumbavif? +VARBINARY(MAX) + + +thumbx? +INT + + +thumby? +INT + + +meta? +NVARCHAR(MAX) - + warehouse - - - -warehouse - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -sort -INT + + + +warehouse + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +sort +INT - + -ledger:e->warehouse:n - - - +warehouse:sw->company:n + + + - + -manifestattachment - - -manifestattachment - - -id -INT -PK - - -file_id -INT -FK - - -manifest_id -INT -FK - - -sort -INT +manifestarticle + + + +manifestarticle + + +id +INT +PK + + +manifest_id +INT +FK + + +sku? +NVARCHAR(100) + + +name? +NVARCHAR(255) + + +pu +FLOAT + + +amount +FLOAT + + +net +FLOAT + + +comment? +NVARCHAR(MAX) + + +rebate +FLOAT + + +taxrate +FLOAT - - -manifestattachment:w->file:n - - - - - - - - -manifestattachment:sw->manifest:n - - - - - - - + -package - - -package - - -id -INT -PK - - -shipping_id -INT -FK - - -entityaddress_id -INT -FK - - -number -NVARCHAR(100) - - -type -NVARCHAR(100) - - -state -NVARCHAR(100) - - -details? -NVARCHAR(MAX) +manifest + + + + + + +manifest + + +id +INT +PK + + +company_id +INT +FK + + +entity_id +? +INT +FK + + +number +NVARCHAR(100) + + +type +NVARCHAR(100) + + +external_number? +NVARCHAR(100) + + +date +DATETIME2 + + +created_at +DATETIME2 - - -package:e->entityaddress:n - - - - - - - - -shipping - - - -shipping - - -id -INT -PK - - -manifest_id -INT -FK - - -number -NVARCHAR(100) - - -type -NVARCHAR(100) - - -state -NVARCHAR(100) - - - -package:sw->shipping:n - - - + + +manifestarticle:sw->manifest:n + + + - -manifest:sw->company:n - - - + +manifest:w->company:n + + + - + manifest:e->entity:n - - - + + + + + + + + +package + + +package + + +id +INT +PK + + +entityaddress_id +INT +FK + + +shipping_id +INT +FK + + +number +NVARCHAR(100) + + +type +NVARCHAR(100) + + +state +NVARCHAR(100) + + +details? +NVARCHAR(MAX) + + + +package:w->entityaddress:n + + + + + + + + +shipping + + + +shipping + + +id +INT +PK + + +manifest_id +INT +FK + + +number +NVARCHAR(100) + + +type +NVARCHAR(100) + + +state +NVARCHAR(100) + + + +package:sw->shipping:n + + + + + + + + +manifestattachment + + +manifestattachment + + +id +INT +PK + + +file_id +INT +FK + + +manifest_id +INT +FK + + +sort +INT + + + +manifestattachment:e->file:n + + + + + + + + +manifestattachment:sw->manifest:n + + + - + shipping:sw->manifest:n - - - + + + - - -warehouse:se->company:n - - - + + +ledger + + +ledger + + +id +INT +PK + + +warehouse_id +? +INT +FK + + +manifestarticle_id +INT +FK + + +transaction_type +NVARCHAR(100) + + +amount +FLOAT + + +transaction_text +NVARCHAR(MAX) + + +hash_version +INT + + +prev_hash? +NVARCHAR(128) + + +created_at +DATETIME2 + + + +ledger:w->warehouse:n + + + - - -account - - - -account - - -id -INT -PK - - -company_id -INT -FK - - -type -NVARCHAR(100) - - -name -NVARCHAR(255) - - - -account:w->company:n - - - + + +ledger:w->manifestarticle:n + + + price - - -price - - -id -INT -PK - - -tax_id -INT -FK - - -article_id -INT -FK - - -customergroup_id -INT -FK - - -minmultiplier -DECIMAL(18,4) - - -net -FLOAT + + +price + + +id +INT +PK + + +article_id +INT +FK + + +tax_id +INT +FK + + +customergroup_id +INT +FK + + +minmultiplier +DECIMAL(18,4) + + +net +FLOAT - + price:e->customergroup:n - - - + + + - + price:w->article:n - - - + + + - + price:e->tax:n - - - + + + + + + + + +account + + + +account + + +id +INT +PK + + +company_id +INT +FK + + +type +NVARCHAR(100) + + +name +NVARCHAR(255) + + + +account:e->company:n + + + - + payment - - -payment - - -id -INT -PK - - -account_id -INT -FK - - -manifest_id -INT -FK - - -type -NVARCHAR(100) - - -amount -FLOAT + + +payment + + +id +INT +PK + + +account_id +INT +FK + + +manifest_id +INT +FK + + +type +NVARCHAR(100) + + +amount +FLOAT - + payment:e->manifest:n - - - + + + - + payment:w->account:n - - - + + + -unit:e->company:n +unit:w->company:n - - - - - - - -printer - - -printer - - -id -INT -PK - - -company_id -INT -FK - - -address -NVARCHAR(255) - - -type -NVARCHAR(50) - - -model? -NVARCHAR(255) - - -serial? -NVARCHAR(255) - - -sort -INT - - -desc? -NVARCHAR(MAX) - - - -printer:w->company:n - - - - - - - - -posterminal - - - -posterminal - - -id -INT -PK - - -root_category_id -? -INT -FK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -token? -NVARCHAR(255) - - -pairingpin? -NVARCHAR(50) - - -paired_at? -DATETIME2 - - -clientserial? -NVARCHAR(255) - - -maxknowntombstoneid? -INT - - -sync_root_articles -BIT - - -lastseen_at? -DATETIME2 - - -updated_at -DATETIME2 - - - -posterminal:w->company:n - - - - - - - - -posterminal:w->category:n - - - + + - + posterminalcategory - - -posterminalcategory - - -id -INT -PK - - -category_id -INT -FK - - -posterminal_id -INT -FK + + +posterminalcategory + + +id +INT +PK + + +category_id +INT +FK + + +posterminal_id +INT +FK - -posterminalcategory:w->category:n - - - + +posterminalcategory:e->category:n + + + + + +posterminal + + + +posterminal + + +id +INT +PK + + +root_category_id +? +INT +FK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +token? +NVARCHAR(255) + + +pairingpin? +NVARCHAR(50) + + +paired_at? +DATETIME2 + + +clientserial? +NVARCHAR(255) + + +maxknowntombstoneid? +INT + + +sync_root_articles +BIT + + +lastseen_at? +DATETIME2 + + +updated_at +DATETIME2 + + +posterminalcategory:se->posterminal:n + + + + + + + -posterminalcategory:nw->posterminal:n - - - +posterminal:e->company:n + + + + + + + + +posterminal:w->category:n + + + + + + + + +printer + + +printer + + +id +INT +PK + + +company_id +INT +FK + + +address +NVARCHAR(255) + + +type +NVARCHAR(50) + + +model? +NVARCHAR(255) + + +serial? +NVARCHAR(255) + + +sort +INT + + +desc? +NVARCHAR(MAX) + + + +printer:se->company:n + + + - + labeltemplate - - -labeltemplate - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -width -INT - - -height -INT - - -dpi -INT - - -type -NVARCHAR(50) - - -content -NVARCHAR(MAX) - - -thumb? -VARBINARY(MAX) + + +labeltemplate + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +width +INT + + +height +INT + + +dpi +INT + + +type +NVARCHAR(50) + + +content +NVARCHAR(MAX) + + +thumb? +VARBINARY(MAX) - -labeltemplate:w->company:n - - - + +labeltemplate:se->company:n + + + - + modelmessage - - -modelmessage - - -id -INT -PK - - -conversation_id -INT -FK - - -created_at -DATETIME2 - - -role -NVARCHAR(20) - - -message -NVARCHAR(MAX) + + +modelmessage + + +id +INT +PK + + +conversation_id +INT +FK + + +created_at +DATETIME2 + + +role +NVARCHAR(20) + + +message +NVARCHAR(MAX) - + modelconversation - - - -modelconversation - - -id -INT -PK - - -companyuser_id -INT -FK - - -provider -NVARCHAR(100) - - -model -NVARCHAR(255) - - -created_at -DATETIME2 - - -updated_at -DATETIME2 - - -state -NVARCHAR(20) + + + +modelconversation + + +id +INT +PK + + +companyuser_id +INT +FK + + +provider +NVARCHAR(100) + + +model +NVARCHAR(255) + + +created_at +DATETIME2 + + +updated_at +DATETIME2 + + +state +NVARCHAR(20) - + modelmessage:se->modelconversation:n - - - + + + - + modelconversation:w->companyuser:n - - - + + + - + modelvfs - - -modelvfs - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -mime -NVARCHAR(100) - - -content -VARBINARY(MAX) - - -meta -NVARCHAR(MAX) - - -created_at -DATETIME2 - - -updated_at -DATETIME2 + + +modelvfs + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +mime +NVARCHAR(100) + + +content +VARBINARY(MAX) + + +meta +NVARCHAR(MAX) + + +created_at +DATETIME2 + + +updated_at +DATETIME2 - + modelvfs:w->company:n - - - - - - - - -propertyname - - - - -propertyname - - -id -INT -PK - - -company_id -INT -FK - - -name -NVARCHAR(255) - - -sort -INT - - -exclusive -BIT - - - -propertyname:e->company:n - - - - - - - - -attributevalue - - - - -attributevalue - - -id -INT -PK - - -attribute_id -INT -FK - - -value -NVARCHAR(255) - - -sort -INT - - - -attributevalue:e->attributename:n - - - - - - - - -categoryproperty - - -categoryproperty - - -id -INT -PK - - -property_id -INT -FK - - -category_id -INT -FK - - -value -NVARCHAR(MAX) - - -sort -INT - - - -categoryproperty:e->category:n - - - - - - - - -categoryproperty:e->propertyname:n - - - - - - - - -categoryattributevalue - - -categoryattributevalue - - -id -INT -PK - - -attributevalue_id -INT -FK - - -category_id -INT -FK - - -sort -INT - - - -categoryattributevalue:e->category:n - - - - - - - - -categoryattributevalue:e->attributevalue:n - - - - - - - - -attributename:e->company:n - - - + + + - + articleproperty - - -articleproperty - - -id -INT -PK - - -property_id -INT -FK - - -article_id -INT -FK - - -value -NVARCHAR(MAX) - - -sort -INT + + +articleproperty + + +id +INT +PK + + +article_id +INT +FK + + +property_id +INT +FK + + +value +NVARCHAR(MAX) + + +sort +INT - + articleproperty:e->article:n - - - + + + + + +propertyname + + + + +propertyname + + +id +INT +PK + + +company_id +INT +FK + + +name +NVARCHAR(255) + + +sort +INT + + +exclusive +BIT + - + articleproperty:w->propertyname:n - - - + + + - + articleattributevalue - - -articleattributevalue - - -id -INT -PK - - -attributevalue_id -INT -FK - - -article_id -INT -FK - - -sort -INT + + +articleattributevalue + + +id +INT +PK + + +article_id +INT +FK + + +attributevalue_id +INT +FK + + +sort +INT - + articleattributevalue:e->article:n - - - + + + - + articleattributevalue:w->attributevalue:n - - - + + + + + + + + +categoryproperty + + +categoryproperty + + +id +INT +PK + + +category_id +INT +FK + + +property_id +INT +FK + + +value +NVARCHAR(MAX) + + +sort +INT + + + +categoryproperty:w->category:n + + + + + + + + +categoryproperty:e->propertyname:n + + + + + + + + +categoryattributevalue + + +categoryattributevalue + + +id +INT +PK + + +category_id +INT +FK + + +attributevalue_id +INT +FK + + +sort +INT + + + +categoryattributevalue:w->category:n + + + + + + + + +categoryattributevalue:e->attributevalue:n + + + + + + + + +attributevalue:se->attributename:n + + + + + + + + +attributename:e->company:n + + + + + + + + +propertyname:e->company:n + + + - + __legend - - - -Legend - -PK - -primary key - -FK - -foreign key - -? - -nullable column - -— - -FOREIGN KEY constraint - -- - - -naming convention only, no constraint + + + +Legend + +PK + +primary key + +FK + +foreign key + +? + +nullable column + +— + +FOREIGN KEY constraint + +- - + +naming convention only, no constraint diff --git a/scripts/test-attributevalue-pic.js b/scripts/test-attributevalue-pic.js new file mode 100644 index 0000000..dea30f3 --- /dev/null +++ b/scripts/test-attributevalue-pic.js @@ -0,0 +1,115 @@ +import assert from 'node:assert/strict'; +import { mkdtempSync, rmSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import sharp from 'sharp'; +import LibDashStore from '../src/index.js'; +import { BetterSqlite3Provider } from '../src/providers/sqlite3/index.js'; + +async function run() { + console.log('--- Testing attributevaluepic & attributevalue image operations ---'); + + const tempDir = mkdtempSync(join(tmpdir(), 'test-attrval-pic-')); + const dbFile = join(tempDir, 'test.db'); + const storageDir = join(tempDir, 'storage'); + + const provider = new BetterSqlite3Provider({ + filename: dbFile, + storageDir, + }); + + await provider.initialize(); + const store = await new LibDashStore(provider); + + try { + const googleAuthId = await store.google_auth.add('tester@example.com'); + const company = await store.company.create({ + name: 'Test Corp', + iso639: 'de', + taxrate: 19, + reducedtaxrate: 7, + googleAuthId, + }); + await store.google_auth.setSelectedCompany(googleAuthId, company.id); + + const attr = await store.attributename.create(googleAuthId, { + name: 'Color', + exclusive: true, + }); + const val = await store.attributevalue.create(googleAuthId, attr.id, { + value: 'Midnight Blue', + }); + assert.ok(val.id > 0); + + // Create a 100x100 test image + const imageBuffer = await sharp({ + create: { + width: 100, + height: 100, + channels: 4, + background: { r: 25, g: 25, b: 112, alpha: 1 }, + }, + }) + .avif() + .toBuffer(); + + console.log('1. Adding image to attribute value...'); + const addResult = await store.attributevalue.addImage(googleAuthId, val.id, imageBuffer); + assert.equal(addResult.id, val.id); + assert.ok(addResult.fullHash); + assert.ok(addResult.thumbW > 0); + assert.ok(addResult.thumbH > 0); + assert.ok(addResult.thumbHash); + assert.equal(addResult.pics.length, 1); + assert.equal(addResult.pics[0].fullHash, addResult.fullHash); + + // Verify row in attributevaluepic + const rows = await provider.query('SELECT * FROM attributevaluepic WHERE attributevalue_id = @id', { + id: val.id, + }); + assert.equal(rows.rows.length, 1); + assert.equal(rows.rows[0].attributevalue_id, val.id); + + // Add again to test replacement + console.log('2. Replacing image on attribute value...'); + const replaceResult = await store.attributevalue.addImage(googleAuthId, val.id, imageBuffer); + assert.equal(replaceResult.id, val.id); + const rowsAfterReplace = await provider.query('SELECT * FROM attributevaluepic WHERE attributevalue_id = @id', { + id: val.id, + }); + assert.equal(rowsAfterReplace.rows.length, 1); + + // Delete image + console.log('3. Deleting image from attribute value...'); + const deleteResult = await store.attributevalue.deleteImage(googleAuthId, val.id); + assert.equal(deleteResult.id, val.id); + assert.equal(deleteResult.thumbW, null); + assert.equal(deleteResult.thumbH, null); + assert.equal(deleteResult.thumbHash, null); + assert.deepEqual(deleteResult.pics, []); + + const rowsAfterDelete = await provider.query('SELECT * FROM attributevaluepic WHERE attributevalue_id = @id', { + id: val.id, + }); + assert.equal(rowsAfterDelete.rows.length, 0); + + // Deleting again should fail with Image not found + await assert.rejects( + async () => { + await store.attributevalue.deleteImage(googleAuthId, val.id); + }, + /Image not found/ + ); + + console.log('All attributevaluepic tests passed successfully!'); + } finally { + try { + rmSync(tempDir, { recursive: true, force: true }); + } catch {} + } +} + +run().catch((err) => { + console.error('Test failed:', err); + process.exit(1); +}); diff --git a/src/index.js b/src/index.js index bb3d42d..930aa8f 100644 --- a/src/index.js +++ b/src/index.js @@ -212,6 +212,8 @@ import attributevalueCreate from './store/attributevalue/create.js'; import attributevalueUpdate from './store/attributevalue/update.js'; import attributevalueOrder from './store/attributevalue/order.js'; import attributevalueDelete from './store/attributevalue/delete.js'; +import attributevalueAddImage from './store/attributevalue/addImage.js'; +import attributevalueDeleteImage from './store/attributevalue/deleteImage.js'; import articleattributevalueListByArticleSku from './store/articleattributevalue/listByArticleSku.js'; import articleattributevalueSetByArticleSku from './store/articleattributevalue/setByArticleSku.js'; import categorypropertyListByCategoryId from './store/categoryproperty/listByCategoryId.js'; @@ -574,6 +576,8 @@ export default class LibDashStore { update: attributevalueUpdate(provider), order: attributevalueOrder(provider), delete: attributevalueDelete(provider), + addImage: attributevalueAddImage(provider), + deleteImage: attributevalueDeleteImage(provider), }; this.articleattributevalue = { diff --git a/src/providers/mssql/purgeSql.js b/src/providers/mssql/purgeSql.js index 9bed341..a19ceb0 100644 --- a/src/providers/mssql/purgeSql.js +++ b/src/providers/mssql/purgeSql.js @@ -6,6 +6,7 @@ export const TABLES = [ 'account', 'articleattributevalue', 'articleproperty', + 'attributevaluepic', 'attributevalue', 'attributename', 'propertyname', diff --git a/src/providers/mssql/queries/attributevaluepic.js b/src/providers/mssql/queries/attributevaluepic.js new file mode 100644 index 0000000..3305d88 --- /dev/null +++ b/src/providers/mssql/queries/attributevaluepic.js @@ -0,0 +1,23 @@ +export const GET_NEXT_SORT = ` +SELECT ISNULL(MAX(sort), -1) + 1 AS sort +FROM attributevaluepic +WHERE attributevalue_id = @attributeValueId +`; + +export const ADD = ` +INSERT INTO attributevaluepic (attributevalue_id, pic_id, sort) +VALUES (@attributeValueId, @picId, @sort) +`; + +export const DELETE_BY_ATTRIBUTE_VALUE = ` +DELETE FROM attributevaluepic +WHERE attributevalue_id = @attributeValueId +`; + +export const GET_FIRST_PIC_BY_ATTRIBUTE_VALUE = ` +SELECT TOP 1 p.id AS picId, p.thumbw AS thumbW, p.thumbh AS thumbH, p.thumbhash AS thumbHash +FROM attributevaluepic avp +INNER JOIN pic p ON p.id = avp.pic_id +WHERE avp.attributevalue_id = @attributeValueId +ORDER BY avp.sort ASC, avp.id ASC +`; diff --git a/src/providers/mssql/queries/pic.js b/src/providers/mssql/queries/pic.js index 66e4c64..7d7c603 100644 --- a/src/providers/mssql/queries/pic.js +++ b/src/providers/mssql/queries/pic.js @@ -45,6 +45,16 @@ FROM ( INNER JOIN brand b ON b.id = bp.brand_id INNER JOIN company c ON c.id = b.company_id WHERE p.hash = @hash + + UNION + + SELECT c.root_category_id AS categoryId + FROM pic p + INNER JOIN attributevaluepic avp ON avp.pic_id = p.id + INNER JOIN attributevalue av ON av.id = avp.attributevalue_id + INNER JOIN attributename an ON an.id = av.attribute_id + INNER JOIN company c ON c.id = an.company_id + WHERE p.hash = @hash ) AS combined WHERE categoryId IS NOT NULL `; diff --git a/src/providers/mssql/schema.js b/src/providers/mssql/schema.js index bf8d930..9640965 100644 --- a/src/providers/mssql/schema.js +++ b/src/providers/mssql/schema.js @@ -463,6 +463,22 @@ BEGIN END `; +export const INIT_ATTRIBUTEVALUEPIC = ` +IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'attributevaluepic') +BEGIN + CREATE TABLE attributevaluepic ( + id INT IDENTITY(1,1) PRIMARY KEY, + attributevalue_id INT NOT NULL, + pic_id INT NOT NULL, + sort INT NOT NULL CONSTRAINT DF_attributevaluepic_sort DEFAULT 0, + CONSTRAINT FK_attributevaluepic_attributevalue FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE, + CONSTRAINT FK_attributevaluepic_pic FOREIGN KEY (pic_id) REFERENCES pic(id) ON DELETE CASCADE, + CONSTRAINT UQ_attributevaluepic_attributevalue_pic UNIQUE (attributevalue_id, pic_id), + CONSTRAINT UQ_attributevaluepic_attributevalue_sort UNIQUE (attributevalue_id, sort) + ); +END +`; + export const INIT_ARTICLELISTARTICLE = ` IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'articlelistarticle') BEGIN @@ -1183,6 +1199,7 @@ export const SCHEMA_SCRIPTS = [ INIT_ARTICLEEAN, INIT_ARTICLEPIC, INIT_BRANDPIC, + INIT_ATTRIBUTEVALUEPIC, INIT_ARTICLELISTARTICLE, INIT_OPTIONSLISTARTICLE, INIT_CATEGORYARTICLE, diff --git a/src/providers/sqlite3/queries/attributevaluepic.js b/src/providers/sqlite3/queries/attributevaluepic.js new file mode 100644 index 0000000..ce18272 --- /dev/null +++ b/src/providers/sqlite3/queries/attributevaluepic.js @@ -0,0 +1,5 @@ +import * as source from '../../mssql/queries/attributevaluepic.js'; +import { translateQueries } from './translate.js'; + +const queries = translateQueries(source, 'attributevaluepic'); +export const { ADD, DELETE_BY_ATTRIBUTE_VALUE, GET_FIRST_PIC_BY_ATTRIBUTE_VALUE, GET_NEXT_SORT } = queries; diff --git a/src/providers/sqlite3/schema.js b/src/providers/sqlite3/schema.js index e3ba269..1841433 100644 --- a/src/providers/sqlite3/schema.js +++ b/src/providers/sqlite3/schema.js @@ -284,6 +284,19 @@ CREATE TABLE IF NOT EXISTS brandpic ( ); `; +export const INIT_ATTRIBUTEVALUEPIC = ` +CREATE TABLE IF NOT EXISTS attributevaluepic ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + attributevalue_id INTEGER NOT NULL, + pic_id INTEGER NOT NULL, + sort INTEGER NOT NULL DEFAULT 0, + UNIQUE (attributevalue_id, pic_id), + UNIQUE (attributevalue_id, sort), + FOREIGN KEY (attributevalue_id) REFERENCES attributevalue(id) ON DELETE CASCADE, + FOREIGN KEY (pic_id) REFERENCES pic(id) ON DELETE CASCADE +); +`; + export const INIT_ARTICLELISTARTICLE = ` CREATE TABLE IF NOT EXISTS articlelistarticle ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -853,6 +866,7 @@ export const SCHEMA_SCRIPTS = [ INIT_ARTICLEEAN, INIT_ARTICLEPIC, INIT_BRANDPIC, + INIT_ATTRIBUTEVALUEPIC, INIT_ARTICLELISTARTICLE, INIT_OPTIONSLISTARTICLE, INIT_CATEGORYARTICLE, diff --git a/src/store/attributevalue/addImage.js b/src/store/attributevalue/addImage.js new file mode 100644 index 0000000..21edf80 --- /dev/null +++ b/src/store/attributevalue/addImage.js @@ -0,0 +1,118 @@ +import { + ADD as MSSQL_ADD_AVPIC, + DELETE_BY_ATTRIBUTE_VALUE as MSSQL_DELETE_AVPIC, +} from '../../providers/mssql/queries/attributevaluepic.js'; +import { + ADD as SQLITE_ADD_AVPIC, + DELETE_BY_ATTRIBUTE_VALUE as SQLITE_DELETE_AVPIC, +} from '../../providers/sqlite3/queries/attributevaluepic.js'; +import { CREATE as MSSQL_CREATE_PIC } from '../../providers/mssql/queries/pic.js'; +import { CREATE as SQLITE_CREATE_PIC } from '../../providers/sqlite3/queries/pic.js'; +import processAvifImage from '../../util/processAvifImage.js'; +import newFullHash from '../../util/newFullHash.js'; +import resolveAttributeValueAccess from './resolveAttributeValueAccess.js'; +import makeRunner from '../runner.js'; + +export default function addImage(provider) { + const access = resolveAttributeValueAccess(provider); + const isSqlite = provider?.dialect === 'sqlite3'; + + const deleteAvPicSql = isSqlite ? SQLITE_DELETE_AVPIC : MSSQL_DELETE_AVPIC; + const createPicSql = isSqlite ? SQLITE_CREATE_PIC : MSSQL_CREATE_PIC; + const addAvPicSql = isSqlite ? SQLITE_ADD_AVPIC : MSSQL_ADD_AVPIC; + + /** + * Adds an image to an attribute value, processing full, thumb, and 32px-edge small-thumb AVIF variants. + * + * @param {number} googleAuthId - The id of the Google auth user. + * @param {number} attributeValueId - The id of the attribute value. + * @param {Buffer} image - The source image buffer. + * @param {object} [tx] - Optional transaction to run within. + * @returns {Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array}>} + */ + return async (googleAuthId, attributeValueId, image, tx) => { + const runAdd = async (runner) => { + await access(googleAuthId, attributeValueId, runner); + + const processed = await processAvifImage(image); + + // Clean existing attributevaluepic so the attribute value has 1 primary image + await runner.query(deleteAvPicSql, { attributeValueId }); + + const sort = 0; + const fullHash = newFullHash(processed.full.buffer); + + let picId; + const existingPic = await runner.query( + 'SELECT id FROM pic WHERE hash = @fullHash', + { fullHash }, + ); + + if (existingPic.rows[0]) { + picId = existingPic.rows[0].id; + } else { + if (isSqlite) { + if (runner.writePicFull) { + await runner.writePicFull(fullHash, processed.full.buffer); + await runner.writePicThumb(fullHash, processed.thumb.buffer); + } else if (provider?.writePicFull) { + await provider.writePicFull(fullHash, processed.full.buffer); + await provider.writePicThumb(fullHash, processed.thumb.buffer); + } + } + + const picResult = await runner.query(createPicSql, { + w: processed.full.w, + h: processed.full.h, + size: processed.full.size, + hash: fullHash, + thumbw: processed.thumb.w, + thumbh: processed.thumb.h, + thumbhash: processed.thumb.hash, + smallthumbw: processed.smallThumb.w, + smallthumbh: processed.smallThumb.h, + smallthumbbinary: processed.smallThumb.buffer, + source: '', + fullbinary: processed.full.buffer, + thumbbinary: processed.thumb.buffer, + }); + + picId = picResult.rows[0]?.id ?? picResult.insertId; + } + + await runner.query(addAvPicSql, { + attributeValueId, + picId, + sort, + }); + + const picObj = { + fullHash, + thumbW: processed.thumb.w, + thumbH: processed.thumb.h, + thumbHash: processed.thumb.hash, + smallThumbW: processed.smallThumb.w, + smallThumbH: processed.smallThumb.h, + }; + + return { + id: attributeValueId, + fullHash, + thumbW: processed.thumb.w, + thumbH: processed.thumb.h, + thumbHash: processed.thumb.hash, + smallThumbW: processed.smallThumb.w, + smallThumbH: processed.smallThumb.h, + pics: [picObj], + }; + }; + + if (tx) { + return runAdd(makeRunner(provider, tx)); + } + if (typeof provider?.transaction === 'function') { + return provider.transaction(runAdd); + } + return runAdd(makeRunner(provider)); + }; +} diff --git a/src/store/attributevalue/deleteImage.js b/src/store/attributevalue/deleteImage.js new file mode 100644 index 0000000..5691e91 --- /dev/null +++ b/src/store/attributevalue/deleteImage.js @@ -0,0 +1,37 @@ +import { DELETE_BY_ATTRIBUTE_VALUE as MSSQL_DELETE } from '../../providers/mssql/queries/attributevaluepic.js'; +import { DELETE_BY_ATTRIBUTE_VALUE as SQLITE_DELETE } from '../../providers/sqlite3/queries/attributevaluepic.js'; +import resolveAttributeValueAccess from './resolveAttributeValueAccess.js'; +import makeRunner from '../runner.js'; + +export default function deleteImage(provider) { + const access = resolveAttributeValueAccess(provider); + const sql = provider?.dialect === 'sqlite3' ? SQLITE_DELETE : MSSQL_DELETE; + + /** + * Deletes the image of an attribute value. + * + * @param {number} googleAuthId - The id of the Google auth user. + * @param {number} attributeValueId - The id of the attribute value. + * @param {object} [tx] - Optional transaction. + * @returns {Promise<{id: number, thumbW: null, thumbH: null, thumbHash: null, pics: Array}>} + * @throws {Error} If attribute value not found or image not found. + */ + return async (googleAuthId, attributeValueId, tx) => { + const runner = makeRunner(provider, tx); + await access(googleAuthId, attributeValueId, runner); + + const result = await runner.query(sql, { attributeValueId }); + + if (!result.rowsAffected) { + throw new Error('Image not found'); + } + + return { + id: attributeValueId, + thumbW: null, + thumbH: null, + thumbHash: null, + pics: [], + }; + }; +} diff --git a/src/store/attributevalue/resolveAttributeValueAccess.js b/src/store/attributevalue/resolveAttributeValueAccess.js new file mode 100644 index 0000000..817aa99 --- /dev/null +++ b/src/store/attributevalue/resolveAttributeValueAccess.js @@ -0,0 +1,22 @@ +import { GET_BY_ID_AND_COMPANY as MSSQL_GET } from '../../providers/mssql/queries/attributevalue.js'; +import { GET_BY_ID_AND_COMPANY as SQLITE_GET } from '../../providers/sqlite3/queries/attributevalue.js'; +import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js'; +import makeRunner from '../runner.js'; + +export default function resolveAttributeValueAccess(provider) { + const access = resolveSelectedCompanyAccess(provider); + const sql = provider?.dialect === 'sqlite3' ? SQLITE_GET : MSSQL_GET; + + return async (googleAuthId, attributeValueId, tx) => { + if (!Number.isFinite(attributeValueId) || attributeValueId <= 0) { + throw new Error('Attribute value not found'); + } + const { companyId } = await access(googleAuthId, tx); + const runner = makeRunner(provider, tx); + const result = await runner.query(sql, { id: attributeValueId, companyId }); + if (!result.rows[0]) { + throw new Error('Attribute value not found'); + } + return { companyId, attributeValue: result.rows[0] }; + }; +}