diff --git a/schema-graph.dot b/schema-graph.dot index fc6dc69..fe44f39 100644 --- a/schema-graph.dot +++ b/schema-graph.dot @@ -11,11 +11,11 @@ digraph schema { fontcolor="#1a365d"; margin=14; meta [label=<
meta
keyNVARCHAR(255)
valueNVARCHAR(MAX)
>]; customergroup [label=<
customergroup
idINT PK
company_idINT FK
nameNVARCHAR(255)
>]; - company [label=<
company
idINT PK
default_language_id?INT FK
root_category_id?INT FK
nameNVARCHAR(255)
>]; numbers [label=<
numbers
idINT PK
company_idINT FK
typeNVARCHAR(100)
prefixNVARCHAR(50)
paddingINT
nextINT
>]; entity [label=<
entity
idINT PK
customergroup_idINT FK
firstnameNVARCHAR(255)
lastnameNVARCHAR(255)
>]; + company [label=<
company
idINT PK
default_language_id?INT FK
root_category_id?INT FK
nameNVARCHAR(255)
>]; companyuser [label=<
companyuser
idINT PK
company_idINT FK
google_auth_idINT FK
>]; - google_auth [label=<
google_auth
idINT PK
emailNVARCHAR(320)
created_atDATETIME2
>]; + google_auth [label=<
google_auth
idINT PK
selected_company?INT FK
emailNVARCHAR(320)
created_atDATETIME2
>]; } subgraph cluster_i18n { label="Localization"; labeljust="l"; fontsize=15; @@ -47,8 +47,8 @@ digraph schema { fontcolor="#1a365d"; margin=14; categorypic [label=<
categorypic
idINT PK
category_idINT FK
pic_idINT FK
sortINT
>]; articlepic [label=<
articlepic
idINT PK
article_idINT FK
pic_idINT FK
sortINT
>]; - brandpic [label=<
brandpic
idINT PK
brand_idINT FK
pic_idINT FK
sortINT
>]; pic [label=<
pic
idINT PK
wINT
hINT
sizeBIGINT
hashNVARCHAR(64)
thumbwINT
thumbhINT
thumbhashNVARCHAR(64)
sourceNVARCHAR(MAX)
>]; + brandpic [label=<
brandpic
idINT PK
brand_idINT FK
pic_idINT FK
sortINT
>]; } subgraph cluster_commerce { label="Pricing & Documents"; labeljust="l"; fontsize=15; @@ -68,43 +68,44 @@ digraph schema { __legend [label=<
Legend
PKprimary key
FKforeign key
?nullable column
—FOREIGN KEY constraint
- -naming convention only, no constraint
>]; - category:parent_id:e -> category:in3:n [color="#c53030", fontcolor="#c53030", tooltip="FK_category_parent"]; - company:root_category_id:e -> category:in0:n [color="#2f855a", fontcolor="#2f855a", tooltip="FK_company_root_category"]; - company:default_language_id:e -> language:in0:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_company_default_language"]; - customergroup:company_id:se -> company:in0:n [color="#b7791f", fontcolor="#b7791f", tooltip="FK_customergroup_company"]; - entity:customergroup_id:sw -> customergroup:in0:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_entity_customergroup"]; - unittext:unit_id:se -> unit:in0:n [color="#c05621", fontcolor="#c05621", tooltip="FK_unittext_unit"]; - unittext:language_id:se -> language:in1:n [color="#319795", fontcolor="#319795", tooltip="FK_unittext_language"]; - article:unit_id:w -> unit:in1:n [color="#97266d", fontcolor="#97266d", tooltip="FK_article_unit"]; - article:brand_id:se -> brand:in0:n [color="#4c51bf", fontcolor="#4c51bf", tooltip="FK_article_brand"]; - article:articlelist_id:se -> articlelist:in0:n [color="#276749", fontcolor="#276749", tooltip="FK_article_articlelist"]; - article:optionslist_id:se -> optionslist:in0:n [color="#9c4221", fontcolor="#9c4221", tooltip="FK_article_optionslist"]; - article:fatherarticle_id:e -> article:in3:n [color="#0987a0", fontcolor="#0987a0", tooltip="FK_article_fatherarticle"]; - articlehistory:article_id:se -> article:in2:n [color="#553c9a", fontcolor="#553c9a", tooltip="FK_articlehistory_article"]; - articleean:article_id:sw -> article:in4:n [color="#742a2a", fontcolor="#742a2a", tooltip="FK_articleean_article"]; - articlepic:article_id:w -> article:in9:n [color="#22543d", fontcolor="#22543d", tooltip="FK_articlepic_article"]; - articlepic:pic_id:se -> pic:in1:n [color="#1a365d", fontcolor="#1a365d", tooltip="FK_articlepic_pic"]; - brandpic:brand_id:w -> brand:in1:n [color="#702459", fontcolor="#702459", tooltip="FK_brandpic_brand"]; - brandpic:pic_id:se -> pic:in2:n [color="#744210", fontcolor="#744210", tooltip="FK_brandpic_pic"]; - articlelistarticle:articlelist_id:sw -> articlelist:in1:n [color="#285e61", fontcolor="#285e61", tooltip="FK_articlelistarticle_articlelist"]; - articlelistarticle:article_id:sw -> article:in5:n [color="#d53f8c", fontcolor="#d53f8c", tooltip="FK_articlelistarticle_article"]; - optionslistarticle:optionslist_id:sw -> optionslist:in1:n [color="#dd6b20", fontcolor="#dd6b20", tooltip="FK_optionslistarticle_optionslist"]; - optionslistarticle:article_id:sw -> article:in6:n [color="#38a169", fontcolor="#38a169", tooltip="FK_optionslistarticle_article"]; - categoryarticle:category_id:sw -> category:in2:n [color="#3182ce", fontcolor="#3182ce", tooltip="FK_categoryarticle_category"]; - categoryarticle:article_id:se -> article:in1:n [color="#805ad5", fontcolor="#805ad5", tooltip="FK_categoryarticle_article"]; - categorypic:category_id:w -> category:in4:n [color="#c53030", fontcolor="#c53030", tooltip="FK_categorypic_category"]; - categorypic:pic_id:se -> pic:in0:n [color="#2f855a", fontcolor="#2f855a", tooltip="FK_categorypic_pic"]; - categorytext:category_id:se -> category:in1:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_categorytext_category"]; - categorytext:language_id:sw -> language:in3:n [color="#b7791f", fontcolor="#b7791f", tooltip="FK_categorytext_language"]; - articletext:article_id:e -> article:in0:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_articletext_article"]; - articletext:language_id:sw -> language:in2:n [color="#c05621", fontcolor="#c05621", tooltip="FK_articletext_language"]; - price:tax_id:se -> tax:in0:n [color="#319795", fontcolor="#319795", tooltip="FK_price_tax"]; - price:article_id:sw -> article:in7:n [color="#97266d", fontcolor="#97266d", tooltip="FK_price_article"]; - price:customergroup_id:w -> customergroup:in1:n [color="#4c51bf", fontcolor="#4c51bf", tooltip="FK_price_customergroup"]; - manifestarticle:manifest_id:sw -> manifest:in0:n [color="#276749", fontcolor="#276749", tooltip="FK_manifestarticle_manifest"]; - manifestarticle:article_id:w -> article:in8:n [color="#9c4221", fontcolor="#9c4221", tooltip="FK_manifestarticle_article"]; - manifestarticle:tax_id:se -> tax:in1:n [color="#0987a0", fontcolor="#0987a0", tooltip="FK_manifestarticle_tax"]; - numbers:company_id:sw -> company:in1:n [color="#553c9a", fontcolor="#553c9a", tooltip="FK_numbers_company"]; - companyuser:google_auth_id:se -> google_auth:in0:n [color="#742a2a", fontcolor="#742a2a", tooltip="FK_companyuser_google_auth"]; - companyuser:company_id:sw -> company:in2:n [color="#22543d", fontcolor="#22543d", tooltip="FK_companyuser_company"]; + google_auth:selected_company:sw -> company:in3:n [color="#c53030", fontcolor="#c53030", tooltip="FK_google_auth_selected_company"]; + category:parent_id:e -> category:in3:n [color="#2f855a", fontcolor="#2f855a", tooltip="FK_category_parent"]; + company:root_category_id:e -> category:in0:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_company_root_category"]; + company:default_language_id:e -> language:in0:n [color="#b7791f", fontcolor="#b7791f", tooltip="FK_company_default_language"]; + customergroup:company_id:se -> company:in0:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_customergroup_company"]; + entity:customergroup_id:sw -> customergroup:in0:n [color="#c05621", fontcolor="#c05621", tooltip="FK_entity_customergroup"]; + unittext:unit_id:e -> unit:in0:n [color="#319795", fontcolor="#319795", tooltip="FK_unittext_unit"]; + unittext:language_id:se -> language:in1:n [color="#97266d", fontcolor="#97266d", tooltip="FK_unittext_language"]; + article:unit_id:w -> unit:in1:n [color="#4c51bf", fontcolor="#4c51bf", tooltip="FK_article_unit"]; + article:brand_id:se -> brand:in0:n [color="#276749", fontcolor="#276749", tooltip="FK_article_brand"]; + article:articlelist_id:se -> articlelist:in0:n [color="#9c4221", fontcolor="#9c4221", tooltip="FK_article_articlelist"]; + article:optionslist_id:se -> optionslist:in0:n [color="#0987a0", fontcolor="#0987a0", tooltip="FK_article_optionslist"]; + article:fatherarticle_id:e -> article:in3:n [color="#553c9a", fontcolor="#553c9a", tooltip="FK_article_fatherarticle"]; + articlehistory:article_id:se -> article:in2:n [color="#742a2a", fontcolor="#742a2a", tooltip="FK_articlehistory_article"]; + articleean:article_id:sw -> article:in4:n [color="#22543d", fontcolor="#22543d", tooltip="FK_articleean_article"]; + articlepic:article_id:w -> article:in9:n [color="#1a365d", fontcolor="#1a365d", tooltip="FK_articlepic_article"]; + articlepic:pic_id:se -> pic:in1:n [color="#702459", fontcolor="#702459", tooltip="FK_articlepic_pic"]; + brandpic:brand_id:w -> brand:in1:n [color="#744210", fontcolor="#744210", tooltip="FK_brandpic_brand"]; + brandpic:pic_id:sw -> pic:in2:n [color="#285e61", fontcolor="#285e61", tooltip="FK_brandpic_pic"]; + articlelistarticle:articlelist_id:sw -> articlelist:in1:n [color="#d53f8c", fontcolor="#d53f8c", tooltip="FK_articlelistarticle_articlelist"]; + articlelistarticle:article_id:sw -> article:in5:n [color="#dd6b20", fontcolor="#dd6b20", tooltip="FK_articlelistarticle_article"]; + optionslistarticle:optionslist_id:sw -> optionslist:in1:n [color="#38a169", fontcolor="#38a169", tooltip="FK_optionslistarticle_optionslist"]; + optionslistarticle:article_id:sw -> article:in6:n [color="#3182ce", fontcolor="#3182ce", tooltip="FK_optionslistarticle_article"]; + categoryarticle:category_id:sw -> category:in2:n [color="#805ad5", fontcolor="#805ad5", tooltip="FK_categoryarticle_category"]; + categoryarticle:article_id:se -> article:in1:n [color="#c53030", fontcolor="#c53030", tooltip="FK_categoryarticle_article"]; + categorypic:category_id:w -> category:in4:n [color="#2f855a", fontcolor="#2f855a", tooltip="FK_categorypic_category"]; + categorypic:pic_id:se -> pic:in0:n [color="#2b6cb0", fontcolor="#2b6cb0", tooltip="FK_categorypic_pic"]; + categorytext:category_id:se -> category:in1:n [color="#b7791f", fontcolor="#b7791f", tooltip="FK_categorytext_category"]; + categorytext:language_id:sw -> language:in3:n [color="#6b46c1", fontcolor="#6b46c1", tooltip="FK_categorytext_language"]; + articletext:article_id:e -> article:in0:n [color="#c05621", fontcolor="#c05621", tooltip="FK_articletext_article"]; + articletext:language_id:sw -> language:in2:n [color="#319795", fontcolor="#319795", tooltip="FK_articletext_language"]; + price:tax_id:se -> tax:in0:n [color="#97266d", fontcolor="#97266d", tooltip="FK_price_tax"]; + price:article_id:sw -> article:in7:n [color="#4c51bf", fontcolor="#4c51bf", tooltip="FK_price_article"]; + price:customergroup_id:w -> customergroup:in1:n [color="#276749", fontcolor="#276749", tooltip="FK_price_customergroup"]; + manifestarticle:manifest_id:sw -> manifest:in0:n [color="#9c4221", fontcolor="#9c4221", tooltip="FK_manifestarticle_manifest"]; + manifestarticle:article_id:w -> article:in8:n [color="#0987a0", fontcolor="#0987a0", tooltip="FK_manifestarticle_article"]; + manifestarticle:tax_id:se -> tax:in1:n [color="#553c9a", fontcolor="#553c9a", tooltip="FK_manifestarticle_tax"]; + numbers:company_id:se -> company:in1:n [color="#742a2a", fontcolor="#742a2a", tooltip="FK_numbers_company"]; + companyuser:google_auth_id:se -> google_auth:in0:n [color="#22543d", fontcolor="#22543d", tooltip="FK_companyuser_google_auth"]; + companyuser:company_id:sw -> company:in2:n [color="#1a365d", fontcolor="#1a365d", tooltip="FK_companyuser_company"]; } \ No newline at end of file diff --git a/schema-graph.svg b/schema-graph.svg index 7ee94ce..b6c500e 100644 --- a/schema-graph.svg +++ b/schema-graph.svg @@ -4,40 +4,40 @@ - + schema - + cluster_identity - + Identity & Company cluster_i18n - -Localization + +Localization cluster_catalog - -Catalog + +Catalog cluster_media - -Media + +Media cluster_commerce - -Pricing & Documents + +Pricing & Documents cluster_units - -Units + +Units @@ -78,112 +78,48 @@ NVARCHAR(255) - + company - - - - - -company - - -id -INT -PK - - -default_language_id -? -INT -FK - - -root_category_id -? -INT -FK - - -name -NVARCHAR(255) + + + + + + +company + + +id +INT +PK + + +default_language_id +? +INT +FK + + +root_category_id +? +INT +FK + + +name +NVARCHAR(255) - + customergroup:se->company:n - - - - - - - - -language - - - - - - -language - - -id -INT -PK - - -iso639 -NVARCHAR(10) - - - -company:e->language:n - - - - - - - - -category - - - - - - - -category - - -id -INT -PK - - -parent_id -? -INT -FK - - -sort -INT - - - -company:e->category:n - - - + + + - + numbers @@ -216,16 +152,16 @@ INT - -numbers:sw->company:n - - - + +numbers:se->company:n + + + - + entity @@ -250,1033 +186,1113 @@ NVARCHAR(255) - + entity:sw->customergroup:n - - - + + + + + + + + +language + + + + + + +language + + +id +INT +PK + + +iso639 +NVARCHAR(10) + + + +company:e->language:n + + + + + + + + +category + + + + + + + +category + + +id +INT +PK + + +parent_id +? +INT +FK + + +sort +INT + + + +company:e->category: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 - + companyuser:sw->company:n - - - + + + google_auth - - - -google_auth - - -id -INT -PK - - -email -NVARCHAR(320) - - -created_at -DATETIME2 + + + +google_auth + + +id +INT +PK + + +selected_company +? +INT +FK + + +email +NVARCHAR(320) + + +created_at +DATETIME2 - + companyuser:se->google_auth:n - - - + + + + + + + + +google_auth:sw->company:n + + + unittext - - -unittext - - -id -INT -PK - - -language_id -INT -FK - - -unit_id -INT -FK - - -symbol -NVARCHAR(50) - - -name -NVARCHAR(255) + + +unittext + + +id +INT +PK + + +language_id +INT +FK + + +unit_id +INT +FK + + +symbol +NVARCHAR(50) + + +name +NVARCHAR(255) - + unittext:se->language:n - - - + + + unit - - - - -unit - - -id -INT -PK - - -si -NVARCHAR(50) - - -basesi -NVARCHAR(50) - - -basesifactor -FLOAT + + + + +unit + + +id +INT +PK + + +si +NVARCHAR(50) + + +basesi +NVARCHAR(50) + + +basesifactor +FLOAT - -unittext:se->unit:n - - - + +unittext:e->unit: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 + + +id +INT +PK + + +language_id +INT +FK + + +article_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) - + articletext:sw->language:n - - - + + + article - - - - - - - - - - - - -article - - -id -INT -PK - - -unit_id -INT -FK - - -fatherarticle_id -? -INT -FK - - -articlelist_id -? -INT -FK - - -optionslist_id -? -INT -FK - - -brand_id -? -INT -FK - - -sku? -NVARCHAR(100) - - -unitamount -FLOAT - - -weight -FLOAT - - -is_father -BIT - - -fathersort -INT - - -created_at -DATETIME2 - - -updated_at -DATETIME2 + + + + + + + + + + + + +article + + +id +INT +PK + + +unit_id +INT +FK + + +fatherarticle_id +? +INT +FK + + +articlelist_id +? +INT +FK + + +optionslist_id +? +INT +FK + + +brand_id +? +INT +FK + + +sku? +NVARCHAR(100) + + +unitamount +FLOAT + + +weight +FLOAT + + +is_father +BIT + + +fathersort +INT + + +created_at +DATETIME2 + + +updated_at +DATETIME2 - + 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 + + +language_id +INT +FK + + +category_id +INT +FK + + +name +NVARCHAR(255) + + +slug +NVARCHAR(255) + + +seo? +NVARCHAR(MAX) + + +desc? +NVARCHAR(MAX) - + categorytext:sw->language:n - - - + + + - + categorytext:se->category:n - - - + + + - + category:e->category:n - - - + + + categoryarticle - - -categoryarticle - - -id -INT -PK - - -category_id -INT -FK - - -article_id -INT -FK + + +categoryarticle + + +id +INT +PK + + +category_id +INT +FK + + +article_id +INT +FK - + categoryarticle:sw->category:n - - - + + + - + categoryarticle:se->article:n - - - + + + articlehistory - - -articlehistory - - -id -INT -PK - - -article_id -INT -FK - - -date -DATETIME2 - - -text -NVARCHAR(MAX) + + +articlehistory + + +id +INT +PK + + +article_id +INT +FK + + +date +DATETIME2 + + +text +NVARCHAR(MAX) - + articlehistory:se->article:n - - - + + + - + article:e->article:n - - - + + + articlelist - - - - -articlelist - - -id -INT -PK + + + + +articlelist + + +id +INT +PK - + article:se->articlelist:n - - - + + + optionslist - - - - -optionslist - - -id -INT -PK + + + + +optionslist + + +id +INT +PK - + article:se->optionslist:n - - - + + + brand - - - - -brand - - -id -INT -PK - - -name -NVARCHAR(255) - - -gsprpinfo? -NVARCHAR(MAX) + + + + +brand + + +id +INT +PK + + +name +NVARCHAR(255) + + +gsprpinfo? +NVARCHAR(MAX) - + article:se->brand:n - - - + + + - + article:w->unit:n - - - + + + articleean - - -articleean - - -id -INT -PK - - -article_id -INT -FK - - -ean -NVARCHAR(50) + + +articleean + + +id +INT +PK + + +article_id +INT +FK + + +ean +NVARCHAR(50) - + articleean:sw->article:n - - - + + + articlelistarticle - - -articlelistarticle - - -id -INT -PK - - -article_id -INT -FK - - -articlelist_id -INT -FK - - -count -INT - - -sort -INT + + +articlelistarticle + + +id +INT +PK + + +article_id +INT +FK + + +articlelist_id +INT +FK + + +count +INT + + +sort +INT - + articlelistarticle:sw->article:n - - - + + + - + articlelistarticle:sw->articlelist:n - - - + + + optionslistarticle - - -optionslistarticle - - -id -INT -PK - - -article_id -INT -FK - - -optionslist_id -INT -FK - - -count -INT - - -sort -INT - - -mandated -BIT + + +optionslistarticle + + +id +INT +PK + + +article_id +INT +FK + + +optionslist_id +INT +FK + + +count +INT + + +sort +INT + + +mandated +BIT - + optionslistarticle:sw->article:n - - - + + + - + optionslistarticle:sw->optionslist:n - - - + + + categorypic - - -categorypic - - -id -INT -PK - - -category_id -INT -FK - - -pic_id -INT -FK - - -sort -INT + + +categorypic + + +id +INT +PK + + +category_id +INT +FK + + +pic_id +INT +FK + + +sort +INT - + categorypic:w->category:n - - - + + + - + pic - - - - - -pic - - -id -INT -PK - - -w -INT - - -h -INT - - -size -BIGINT - - -hash -NVARCHAR(64) - - -thumbw -INT - - -thumbh -INT - - -thumbhash -NVARCHAR(64) - - -source -NVARCHAR(MAX) + + + + + +pic + + +id +INT +PK + + +w +INT + + +h +INT + + +size +BIGINT + + +hash +NVARCHAR(64) + + +thumbw +INT + + +thumbh +INT + + +thumbhash +NVARCHAR(64) + + +source +NVARCHAR(MAX) - + categorypic:se->pic:n - - - + + + articlepic - - -articlepic - - -id -INT -PK - - -article_id -INT -FK - - -pic_id -INT -FK - - -sort -INT + + +articlepic + + +id +INT +PK + + +article_id +INT +FK + + +pic_id +INT +FK + + +sort +INT - + articlepic:w->article:n - - - + + + - + articlepic:se->pic:n - - - + + + - + brandpic - - -brandpic - - -id -INT -PK - - -brand_id -INT -FK - - -pic_id -INT -FK - - -sort -INT + + +brandpic + + +id +INT +PK + + +brand_id +INT +FK + + +pic_id +INT +FK + + +sort +INT - + brandpic:w->brand:n - - - + + + - -brandpic:se->pic:n - - - + +brandpic:sw->pic:n + + + manifest - - - -manifest - - -id -INT -PK - - -number -NVARCHAR(100) - - -type -NVARCHAR(100) - - -date -DATETIME2 + + + +manifest + + +id +INT +PK + + +number +NVARCHAR(100) + + +type +NVARCHAR(100) + + +date +DATETIME2 price - - -price - - -id -INT -PK - - -customergroup_id -INT -FK - - -article_id -INT -FK - - -tax_id -INT -FK - - -minmultiplier -DECIMAL(18,4) - - -net -FLOAT + + +price + + +id +INT +PK + + +customergroup_id +INT +FK + + +article_id +INT +FK + + +tax_id +INT +FK + + +minmultiplier +DECIMAL(18,4) + + +net +FLOAT - + price:w->customergroup:n - - - + + + - + price:sw->article:n - - - + + + tax - - - - -tax - - -id -INT -PK - - -rate -DECIMAL(18,4) + + + + +tax + + +id +INT +PK + + +rate +DECIMAL(18,4) - + price:se->tax:n - - - + + + manifestarticle - - -manifestarticle - - -id -INT -PK - - -article_id -INT -FK - - -manifest_id -INT -FK - - -tax_id -INT -FK - - -amount -FLOAT - - -net -FLOAT - - -transactedamount -FLOAT - - -comment? -NVARCHAR(MAX) - - -rebate -FLOAT + + +manifestarticle + + +id +INT +PK + + +article_id +INT +FK + + +manifest_id +INT +FK + + +tax_id +INT +FK + + +amount +FLOAT + + +net +FLOAT + + +transactedamount +FLOAT + + +comment? +NVARCHAR(MAX) + + +rebate +FLOAT - + manifestarticle:w->article:n - - - + + + - + manifestarticle:sw->manifest:n - - - + + + - + manifestarticle:se->tax: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-api.js b/scripts/test-api.js index eb481ed..4f620d7 100644 --- a/scripts/test-api.js +++ b/scripts/test-api.js @@ -49,35 +49,93 @@ async function shutdown(pool, code = 0) { process.exit(code); } -const METHODS = [ - { - value: 'setup.company', - label: chalk.cyan('setup company'), - hint: 'email + name + lang', +const MENU = { + setup: { + label: chalk.cyan('setup'), + hint: 'guided flows', + items: [ + { value: 'setup.company', label: 'company', hint: 'email + name + lang' }, + ], }, - { value: 'company.create', label: 'company.create', hint: '{name} → id' }, - { value: 'company.list', label: 'company.list', hint: '→ rows' }, - { value: 'company.setDefaultLang', label: 'company.setDefaultLang', hint: 'companyId, langId' }, - { value: 'company.setRootCategory', label: 'company.setRootCategory', hint: 'companyId, categoryId' }, - { value: 'company.delete', label: 'company.delete', hint: 'companyId' }, - { value: 'company.getByCompanyUserId', label: 'company.getByCompanyUserId', hint: 'id → tuple' }, - { value: 'lang.create', label: 'lang.create', hint: 'iso639 → id' }, - { value: 'lang.list', label: 'lang.list', hint: '→ rows' }, - { value: 'lang.delete', label: 'lang.delete', hint: 'id' }, - { value: 'category.create', label: 'category.create', hint: '{parent_id, sort} → id' }, - { value: 'category.updateParentId', label: 'category.updateParentId', hint: 'id, parentId' }, - { value: 'category.delete', label: 'category.delete', hint: 'id' }, - { value: 'category.getTree', label: 'category.getTree', hint: 'rootId → rows' }, - { value: 'companyuser.add', label: 'companyuser.add', hint: 'companyId, authId → id' }, - { value: 'companyuser.delete', label: 'companyuser.delete', hint: 'id' }, - { value: 'companyuser.getByEmail', label: 'companyuser.getByEmail', hint: 'email → ids' }, - { value: 'google_auth.add', label: 'google_auth.add', hint: 'email → authId' }, - { value: 'google_auth.list', label: 'google_auth.list', hint: '→ rows' }, - { value: 'google_auth.del', label: 'google_auth.del', hint: 'id' }, - { value: 'initialize', label: 'initialize', hint: 'ensure schema (no purge)' }, - { value: 'purge', label: chalk.red('purge'), hint: 'drop all · exit' }, - { value: 'exit', label: 'exit', hint: 'quit without purge' }, -]; + company: { + label: 'company', + items: [ + { value: 'company.create', label: 'create', hint: '{name} → id' }, + { value: 'company.list', label: 'list', hint: '→ rows' }, + { value: 'company.setDefaultLang', label: 'setDefaultLang', hint: 'companyId, langId' }, + { value: 'company.setRootCategory', label: 'setRootCategory', hint: 'companyId, categoryId' }, + { value: 'company.delete', label: 'delete', hint: 'companyId' }, + { value: 'company.getByCompanyUserId', label: 'getByCompanyUserId', hint: 'id → tuple' }, + ], + }, + lang: { + label: 'lang', + items: [ + { value: 'lang.create', label: 'create', hint: 'iso639 → id' }, + { value: 'lang.list', label: 'list', hint: '→ rows' }, + { value: 'lang.delete', label: 'delete', hint: 'id' }, + ], + }, + category: { + label: 'category', + items: [ + { value: 'category.create', label: 'create', hint: '{parent_id, sort} → id' }, + { value: 'category.updateParentId', label: 'updateParentId', hint: 'id, parentId' }, + { value: 'category.delete', label: 'delete', hint: 'id' }, + { value: 'category.getTree', label: 'getTree', hint: 'rootId → rows' }, + ], + }, + companyuser: { + label: 'companyuser', + items: [ + { value: 'companyuser.add', label: 'add', hint: 'companyId, authId → id' }, + { value: 'companyuser.delete', label: 'delete', hint: 'id' }, + { value: 'companyuser.getByEmail', label: 'getByEmail', hint: 'email → ids' }, + ], + }, + google_auth: { + label: 'google_auth', + items: [ + { value: 'google_auth.add', label: 'add', hint: 'email → authId' }, + { value: 'google_auth.list', label: 'list', hint: '→ rows' }, + { value: 'google_auth.del', label: 'del', hint: 'id' }, + ], + }, + schema: { + label: 'schema', + items: [ + { value: 'initialize', label: 'initialize', hint: 'ensure schema (no purge)' }, + { value: 'purge', label: chalk.red('purge'), hint: 'drop all · exit' }, + ], + }, +}; + +async function pickAction() { + const group = await p.select({ + message: 'Group', + options: [ + ...Object.entries(MENU).map(([value, group]) => ({ + value, + label: group.label, + hint: group.hint, + })), + { value: 'exit', label: 'exit', hint: 'quit without purge' }, + ], + }); + + if (p.isCancel(group) || group === 'exit') return 'exit'; + + const action = await p.select({ + message: MENU[group].label, + options: [ + ...MENU[group].items, + { value: 'back', label: chalk.dim('← back') }, + ], + }); + + if (p.isCancel(action) || action === 'back') return null; + return action; +} async function runMethod(client, action) { switch (action) { @@ -308,16 +366,15 @@ async function main() { ); while (true) { - const action = await p.select({ - message: 'API method', - options: METHODS, - }); + const action = await pickAction(); - if (p.isCancel(action) || action === 'exit') { + if (action === 'exit') { p.outro(chalk.dim('Bye')); await shutdown(pool, 0); } + if (action == null) continue; + if (action === 'purge') { const confirm1 = await p.confirm({ message: chalk.red('Drop ALL tables?'), diff --git a/src/schema.js b/src/schema.js index c40dd66..7246569 100644 --- a/src/schema.js +++ b/src/schema.js @@ -22,7 +22,9 @@ BEGIN id INT IDENTITY(1,1) PRIMARY KEY, email NVARCHAR(320) NOT NULL, created_at DATETIME2 NOT NULL CONSTRAINT DF_google_auth_created_at DEFAULT SYSUTCDATETIME(), - CONSTRAINT UQ_google_auth_email UNIQUE (email) + selected_company INT NULL, + CONSTRAINT UQ_google_auth_email UNIQUE (email), + CONSTRAINT FK_google_auth_selected_company FOREIGN KEY (selected_company) REFERENCES company(id) ON DELETE SET NULL ); END `; @@ -501,12 +503,12 @@ END /** DDL scripts in dependency order for schema init. */ export const SCHEMA_SCRIPTS = [ INIT_META, - INIT_GOOGLE_AUTH, INIT_LANGUAGE, INIT_TAX, INIT_CATEGORY, INIT_PIC, INIT_COMPANY, + INIT_GOOGLE_AUTH, INIT_CUSTOMERGROUP, INIT_ENTITY, INIT_UNIT, diff --git a/src/sql/google_auth.js b/src/sql/google_auth.js index cfb8842..a6027fc 100644 --- a/src/sql/google_auth.js +++ b/src/sql/google_auth.js @@ -5,7 +5,7 @@ VALUES (@email) `; export const LIST = ` -SELECT id, email, created_at +SELECT id, email, created_at, selected_company FROM google_auth ORDER BY id `; diff --git a/src/sql/purge.js b/src/sql/purge.js index 23647fe..1c85a01 100644 --- a/src/sql/purge.js +++ b/src/sql/purge.js @@ -23,12 +23,12 @@ export const TABLES = [ 'unit', 'entity', 'customergroup', + 'google_auth', 'company', 'pic', 'category', 'tax', 'language', - 'google_auth', 'meta', ];