Adds the company tables of SPEC 11.1 behind one generic service so that every table gets the same rules, history, cache and CSV import/export, plus the company profile, fiscal years with monthly lock and the base-data seeder. - 26 coded tables, exchange rates, company profile, fiscal years and periods: entities, maps and migrations 010-014 - TableService + TableCatalog: unique codes, per-table rules (VAT codes are checked by the fiscal pack), delete or disable when in use, single default, CSV export/import all-or-nothing, cache with cross-instance invalidation - CompanyProfileService (Italian identifiers through the pack), FiscalYearService with the date check used by every dated record - EcbRatesClient and the ECB rates system task; CsvReader - ISeeder/SeedRunner with the data version in company settings; base tables from the pack (IBaseTablesTemplate) and an embedded ISO country list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
25f8a7ad30
commit
34e196424f
33 files changed
+6049
-3
No files matched your search
@@ -0,0 +1,246 @@
|
||||
using Khaemhat.Application.Modules;
|
||||
using Khaemhat.Application.Tables;
|
||||
using Khaemhat.Core.Tables;
|
||||
using Khaemhat.Data.Querying;
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
using Khaemhat.Infrastructure.Files;
|
||||
|
||||
namespace Khaemhat.Application.Seeding;
|
||||
|
||||
/// <summary>
|
||||
/// The base tables of SPEC §14 available from M4: countries, currencies, units, VAT codes (from the fiscal pack),
|
||||
/// payment methods and terms and document types (from the pack's <see cref="IBaseTablesTemplate"/>), transport tables,
|
||||
/// warehouse reasons, the main warehouse, categories, the base price list, the numerators and the fiscal year of the
|
||||
/// current year. Provinces, municipalities and banks come from datasets loaded separately (ADR 0026).
|
||||
/// </summary>
|
||||
/// <param name="years">Creates the current fiscal year.</param>
|
||||
public sealed class BaseTablesSeeder(FiscalYearService years) : ISeeder
|
||||
{
|
||||
/// <summary>The currencies of the ECB reference rates, plus the euro: code, name, symbol, decimals.</summary>
|
||||
public static readonly IReadOnlyList<(string Code, string Name, string Symbol, int Decimals)> Currencies =
|
||||
[
|
||||
("EUR", "Euro", "€", 2), ("USD", "Dollaro statunitense", "$", 2), ("GBP", "Sterlina britannica", "£", 2), ("CHF", "Franco svizzero", "CHF", 2),
|
||||
("JPY", "Yen giapponese", "¥", 0), ("CZK", "Corona ceca", "Kč", 2), ("DKK", "Corona danese", "kr", 2), ("HUF", "Fiorino ungherese", "Ft", 2),
|
||||
("PLN", "Zloty polacco", "zł", 2), ("RON", "Leu rumeno", "lei", 2), ("SEK", "Corona svedese", "kr", 2), ("ISK", "Corona islandese", "kr", 0),
|
||||
("NOK", "Corona norvegese", "kr", 2), ("TRY", "Lira turca", "₺", 2), ("AUD", "Dollaro australiano", "A$", 2), ("BRL", "Real brasiliano", "R$", 2),
|
||||
("CAD", "Dollaro canadese", "C$", 2), ("CNY", "Renminbi cinese", "¥", 2), ("HKD", "Dollaro di Hong Kong", "HK$", 2), ("IDR", "Rupia indonesiana", "Rp", 2),
|
||||
("ILS", "Nuovo siclo israeliano", "₪", 2), ("INR", "Rupia indiana", "₹", 2), ("KRW", "Won sudcoreano", "₩", 0), ("MXN", "Peso messicano", "Mex$", 2),
|
||||
("MYR", "Ringgit malese", "RM", 2), ("NZD", "Dollaro neozelandese", "NZ$", 2), ("PHP", "Peso filippino", "₱", 2), ("SGD", "Dollaro di Singapore", "S$", 2),
|
||||
("THB", "Baht thailandese", "฿", 2), ("ZAR", "Rand sudafricano", "R", 2),
|
||||
];
|
||||
|
||||
/// <summary>The numerators of the base data: code, description, family, section, format, gaps allowed.</summary>
|
||||
public static readonly IReadOnlyList<(string Code, string Description, NumeratorKind Kind, string? Section, string Format, bool Gaps)> Numerators =
|
||||
[
|
||||
("PRE", "Preventivi", NumeratorKind.Quotation, null, "PRE-{year}-{number:D4}", true),
|
||||
("ORD", "Ordini clienti", NumeratorKind.SalesOrder, null, "OC-{year}-{number:D4}", true),
|
||||
("DDT", "Documenti di trasporto", NumeratorKind.DeliveryNote, null, "{number}/{year}", true),
|
||||
("FAT", "Fatture e note di credito", NumeratorKind.SalesInvoice, null, "{number}/{year}", false),
|
||||
("AUT", "Autofatture e integrazioni", NumeratorKind.SalesInvoice, "AF", "{number}/AF/{year}", false),
|
||||
("PRF", "Pro forma", NumeratorKind.Other, null, "PF-{year}-{number:D4}", true),
|
||||
("ORF", "Ordini fornitori", NumeratorKind.PurchaseOrder, null, "OF-{year}-{number:D4}", true),
|
||||
("PRA", "Protocollo acquisti", NumeratorKind.PurchaseInvoice, null, "{number}", false),
|
||||
("MAG", "Movimenti di magazzino", NumeratorKind.Inventory, null, "MM-{year}-{number:D5}", true),
|
||||
("PN", "Registrazioni contabili", NumeratorKind.Journal, null, "{number}", false),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
public string ModuleCode => ModuleCodes.Core;
|
||||
|
||||
/// <inheritdoc />
|
||||
public SeedKind Kind => SeedKind.Base;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task RunAsync(SeedContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
await context.EnsureAsync("countries", ReadCountries(), cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("currencies", Currencies.Select(c => new Currency { Code = c.Code, Description = c.Name, Symbol = c.Symbol, Decimals = c.Decimals }), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
await context.EnsureAsync("units_of_measure", Units(), cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("tax_codes", TaxCodes(context.Pack), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var reasons = await context.EnsureAsync("inventory_reasons", InventoryReasons(), cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("warehouses", [new Warehouse { Code = "SEDE", Description = "Magazzino sede", IsDefault = true }], cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("shipping_terms", Coded<ShippingTerm>(("FRANCO", "Porto franco"), ("ASSEGNATO", "Porto assegnato"), ("ADDEBITO", "Franco con addebito in fattura")), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
await context.EnsureAsync("transport_means", Coded<TransportMean>(("MITT", "Mittente"), ("DEST", "Destinatario"), ("VETT", "Vettore")), cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync(
|
||||
"goods_appearances",
|
||||
Coded<GoodsAppearance>(("CARTONI", "Cartoni"), ("SCATOLE", "Scatole"), ("BANCALI", "Bancali"), ("COLLI", "Colli"), ("BUSTE", "Buste"), ("SFUSO", "Sfuso"), ("VISTA", "A vista")),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("delivery_terms", Incoterms(), cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync(
|
||||
"transport_reasons",
|
||||
Coded<TransportReason>(
|
||||
("VEN", "Vendita"), ("CV", "Conto visione"), ("CD", "Conto deposito"), ("CL", "Conto lavorazione"), ("RES", "Reso"), ("RIP", "Riparazione"),
|
||||
("OMA", "Omaggio"), ("TRA", "Trasferimento tra depositi")),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("item_categories", [new ItemCategory { Code = "GEN", Description = "Generica" }], cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("party_categories", Coded<PartyCategory>(("GEN", "Generica")), cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync("price_lists", [new PriceList { Code = "BASE", Description = "Listino base" }], cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var year = context.Today.Year;
|
||||
var numerators = new Dictionary<string, DocumentNumerator>(StringComparer.Ordinal);
|
||||
foreach (var n in Numerators)
|
||||
{
|
||||
numerators[n.Code] = await context.EnsureOneAsync(
|
||||
"document_numerators",
|
||||
x => x.Code == n.Code && x.Year == year,
|
||||
new DocumentNumerator { Code = n.Code, Description = n.Description, Kind = n.Kind, Section = n.Section, Year = year, Format = n.Format, GapsAllowed = n.Gaps },
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (context.Pack.GetFeature<IBaseTablesTemplate>() is { } template)
|
||||
{
|
||||
await SeedPaymentsAsync(context, template, cancellationToken).ConfigureAwait(false);
|
||||
await context.EnsureAsync(
|
||||
"document_types",
|
||||
template.DocumentTypes.Select(d => new DocumentType
|
||||
{
|
||||
Code = d.Code,
|
||||
Description = d.Description,
|
||||
Kind = d.Kind,
|
||||
NumeratorId = d.NumeratorCode is { } n && numerators.TryGetValue(n, out var numerator) ? numerator.Id : null,
|
||||
InventoryReasonId = d.InventoryReasonCode is { } r && reasons.TryGetValue(r, out var reason) ? reason.Id : null,
|
||||
EInvoiceType = d.EInvoiceType,
|
||||
}),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var calendar = await context.UnitOfWork.Repository<FiscalYear, long>()
|
||||
.CountAsync(Query.For<FiscalYear>().Where(y => y.StartDate <= context.Today && y.EndDate >= context.Today), cancellationToken).ConfigureAwait(false);
|
||||
if (calendar == 0 && await context.UnitOfWork.Repository<FiscalYear, long>().CountAsync(Query.For<FiscalYear>(), cancellationToken).ConfigureAwait(false) == 0)
|
||||
{
|
||||
await years.CreateAsync(context.UnitOfWork, context.Today, "system", cancellationToken).ConfigureAwait(false);
|
||||
context.Count("fiscal_years");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The countries of the embedded list (ISO 3166-1, Italian names, EU members, currency).</summary>
|
||||
/// <returns>The rows.</returns>
|
||||
public static IReadOnlyList<Country> ReadCountries()
|
||||
{
|
||||
using var stream = typeof(BaseTablesSeeder).Assembly.GetManifestResourceStream("Khaemhat.Application.Seeding.Data.countries.csv")
|
||||
?? throw new InvalidOperationException("The country list is missing from the assembly.");
|
||||
using var reader = new StreamReader(stream);
|
||||
var lines = CsvReader.Parse(reader.ReadToEnd(), ';');
|
||||
return
|
||||
[
|
||||
.. lines.Skip(1).Select(l => new Country
|
||||
{
|
||||
Code = l[0],
|
||||
Iso3 = l[1].Length == 0 ? null : l[1],
|
||||
Description = l[2],
|
||||
EuMember = l[3] == "1",
|
||||
CurrencyCode = l[4].Length == 0 ? null : l[4],
|
||||
|
||||
// Greece uses EL in VAT numbers and VIES.
|
||||
VatPrefix = l[0] == "GR" ? "EL" : null,
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
private static async Task SeedPaymentsAsync(SeedContext context, IBaseTablesTemplate template, CancellationToken cancellationToken)
|
||||
{
|
||||
var methods = await context.EnsureAsync(
|
||||
"payment_methods",
|
||||
template.PaymentMethods.Select(m => new PaymentMethod { Code = m.Code, Description = m.Description, EInvoiceCode = m.EInvoiceCode, NeedsBank = m.NeedsBank }),
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
var existing = (await context.UnitOfWork.Repository<PaymentTerm, long>().ListAsync(Query.For<PaymentTerm>(), cancellationToken).ConfigureAwait(false)).Items
|
||||
.Select(t => t.Code)
|
||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
var lines = context.UnitOfWork.Repository<PaymentTermLine, long>();
|
||||
foreach (var t in template.PaymentTerms.Where(t => !existing.Contains(t.Code)))
|
||||
{
|
||||
var terms = await context.EnsureOneAsync(
|
||||
"payment_terms",
|
||||
x => x.Code == t.Code,
|
||||
new PaymentTerm
|
||||
{
|
||||
Code = t.Code,
|
||||
Description = t.Description,
|
||||
Condition = t.Condition,
|
||||
PaymentMethodId = methods.TryGetValue(t.PaymentMethodCode, out var method) ? method.Id : null,
|
||||
},
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
var number = 1;
|
||||
foreach (var i in t.Installments)
|
||||
{
|
||||
await lines.InsertAsync(new PaymentTermLine { PaymentTermId = terms.Id, Number = number++, Days = i.Days, EndOfMonth = i.EndOfMonth, Percent = i.Percent }, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<TaxCode> TaxCodes(IFiscalPack pack) =>
|
||||
pack.TaxCodes.BaseCodes.Select(c => new TaxCode
|
||||
{
|
||||
Code = c.Code,
|
||||
Description = c.Description,
|
||||
Rate = c.Rate,
|
||||
Nature = c.Nature,
|
||||
Exigibility = c.Exigibility,
|
||||
NonDeductiblePercent = c.NonDeductiblePercent,
|
||||
LegalReference = c.LegalReference,
|
||||
Kind = pack.TaxCodes.KindOf(c.Rate, c.Nature),
|
||||
});
|
||||
|
||||
private static IEnumerable<UnitOfMeasure> Units() =>
|
||||
[
|
||||
new() { Code = "NR", Description = "Numero", Decimals = 0 },
|
||||
new() { Code = "PZ", Description = "Pezzi", Decimals = 0 },
|
||||
new() { Code = "CF", Description = "Confezioni", Decimals = 0 },
|
||||
new() { Code = "CT", Description = "Cartoni", Decimals = 0 },
|
||||
new() { Code = "PAL", Description = "Pallet", Decimals = 0 },
|
||||
new() { Code = "KG", Description = "Chilogrammi", Decimals = 3 },
|
||||
new() { Code = "G", Description = "Grammi", Decimals = 0 },
|
||||
new() { Code = "T", Description = "Tonnellate", Decimals = 3 },
|
||||
new() { Code = "L", Description = "Litri", Decimals = 3 },
|
||||
new() { Code = "M", Description = "Metri", Decimals = 3 },
|
||||
new() { Code = "M2", Description = "Metri quadrati", Decimals = 3 },
|
||||
new() { Code = "M3", Description = "Metri cubi", Decimals = 3 },
|
||||
new() { Code = "KM", Description = "Chilometri", Decimals = 2 },
|
||||
new() { Code = "KWH", Description = "Kilowattora", Decimals = 3 },
|
||||
new() { Code = "ORE", Description = "Ore", Decimals = 2 },
|
||||
new() { Code = "GG", Description = "Giorni", Decimals = 2 },
|
||||
new() { Code = "MESI", Description = "Mesi", Decimals = 0 },
|
||||
new() { Code = "SERV", Description = "Servizio", Decimals = 0 },
|
||||
];
|
||||
|
||||
private static IEnumerable<InventoryReason> InventoryReasons() =>
|
||||
[
|
||||
new() { Code = "CAR", Description = "Carico da acquisto", Effect = StockEffect.Load },
|
||||
new() { Code = "SCA", Description = "Scarico per vendita", Effect = StockEffect.Unload },
|
||||
new() { Code = "RESC", Description = "Reso da cliente", Effect = StockEffect.Load },
|
||||
new() { Code = "RESF", Description = "Reso a fornitore", Effect = StockEffect.Unload },
|
||||
new() { Code = "TRA", Description = "Trasferimento tra depositi", Effect = StockEffect.None, AffectsValue = false, IsTransfer = true },
|
||||
new() { Code = "INVP", Description = "Rettifica inventariale in aumento", Effect = StockEffect.Load },
|
||||
new() { Code = "INVN", Description = "Rettifica inventariale in diminuzione", Effect = StockEffect.Unload },
|
||||
new() { Code = "CVU", Description = "Uscita in conto visione", Effect = StockEffect.Unload, AffectsValue = false },
|
||||
new() { Code = "CVR", Description = "Rientro da conto visione", Effect = StockEffect.Load, AffectsValue = false },
|
||||
new() { Code = "OMA", Description = "Omaggio", Effect = StockEffect.Unload },
|
||||
new() { Code = "AUTO", Description = "Autoconsumo", Effect = StockEffect.Unload },
|
||||
new() { Code = "APE", Description = "Esistenza iniziale", Effect = StockEffect.Load },
|
||||
];
|
||||
|
||||
private static IEnumerable<DeliveryTerm> Incoterms() => Coded<DeliveryTerm>(
|
||||
("EXW", "Franco fabbrica (Ex Works)"),
|
||||
("FCA", "Franco vettore (Free Carrier)"),
|
||||
("CPT", "Trasporto pagato fino a (Carriage Paid To)"),
|
||||
("CIP", "Trasporto e assicurazione pagati fino a (Carriage and Insurance Paid To)"),
|
||||
("DAP", "Reso al luogo di destinazione (Delivered at Place)"),
|
||||
("DPU", "Reso al luogo di destinazione scaricato (Delivered at Place Unloaded)"),
|
||||
("DDP", "Reso sdoganato (Delivered Duty Paid)"),
|
||||
("FAS", "Franco lungo bordo (Free Alongside Ship)"),
|
||||
("FOB", "Franco a bordo (Free On Board)"),
|
||||
("CFR", "Costo e nolo (Cost and Freight)"),
|
||||
("CIF", "Costo, assicurazione e nolo (Cost, Insurance and Freight)"));
|
||||
|
||||
private static IEnumerable<T> Coded<T>(params (string Code, string Description)[] rows)
|
||||
where T : CodedEntity, new() =>
|
||||
rows.Select(r => new T { Code = r.Code, Description = r.Description });
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
code;iso3;name;eu;currency
|
||||
AD;AND;Andorra;0;EUR
|
||||
AE;ARE;Emirati Arabi Uniti;0;AED
|
||||
AF;AFG;Afghanistan;0;AFN
|
||||
AG;ATG;Antigua e Barbuda;0;XCD
|
||||
AI;AIA;Anguilla;0;XCD
|
||||
AL;ALB;Albania;0;ALL
|
||||
AM;ARM;Armenia;0;AMD
|
||||
AO;AGO;Angola;0;AOA
|
||||
AQ;ATA;Antartide;0;
|
||||
AR;ARG;Argentina;0;ARS
|
||||
AS;ASM;Samoa americane;0;USD
|
||||
AT;AUT;Austria;1;EUR
|
||||
AU;AUS;Australia;0;AUD
|
||||
AW;ABW;Aruba;0;AWG
|
||||
AX;ALA;Isole Åland;0;EUR
|
||||
AZ;AZE;Azerbaigian;0;AZN
|
||||
BA;BIH;Bosnia ed Erzegovina;0;BAM
|
||||
BB;BRB;Barbados;0;BBD
|
||||
BD;BGD;Bangladesh;0;BDT
|
||||
BE;BEL;Belgio;1;EUR
|
||||
BF;BFA;Burkina Faso;0;XOF
|
||||
BG;BGR;Bulgaria;1;EUR
|
||||
BH;BHR;Bahrein;0;BHD
|
||||
BI;BDI;Burundi;0;BIF
|
||||
BJ;BEN;Benin;0;XOF
|
||||
BL;BLM;Saint-Barthélemy;0;EUR
|
||||
BM;BMU;Bermuda;0;BMD
|
||||
BN;BRN;Brunei;0;BND
|
||||
BO;BOL;Bolivia;0;BOB
|
||||
BQ;BES;Caraibi olandesi;0;USD
|
||||
BR;BRA;Brasile;0;BRL
|
||||
BS;BHS;Bahamas;0;BSD
|
||||
BT;BTN;Bhutan;0;BTN
|
||||
BV;BVT;Isola Bouvet;0;NOK
|
||||
BW;BWA;Botswana;0;BWP
|
||||
BY;BLR;Bielorussia;0;BYN
|
||||
BZ;BLZ;Belize;0;BZD
|
||||
CA;CAN;Canada;0;CAD
|
||||
CC;CCK;Isole Cocos (Keeling);0;AUD
|
||||
CD;COD;Repubblica Democratica del Congo;0;CDF
|
||||
CF;CAF;Repubblica Centrafricana;0;XAF
|
||||
CG;COG;Repubblica del Congo;0;XAF
|
||||
CH;CHE;Svizzera;0;CHF
|
||||
CI;CIV;Costa d'Avorio;0;XOF
|
||||
CK;COK;Isole Cook;0;NZD
|
||||
CL;CHL;Cile;0;CLP
|
||||
CM;CMR;Camerun;0;XAF
|
||||
CN;CHN;Cina;0;CNY
|
||||
CO;COL;Colombia;0;COP
|
||||
CR;CRI;Costa Rica;0;CRC
|
||||
CU;CUB;Cuba;0;CUP
|
||||
CV;CPV;Capo Verde;0;CVE
|
||||
CW;CUW;Curaçao;0;XCG
|
||||
CX;CXR;Isola di Natale;0;AUD
|
||||
CY;CYP;Cipro;1;EUR
|
||||
CZ;CZE;Cechia;1;CZK
|
||||
DE;DEU;Germania;1;EUR
|
||||
DJ;DJI;Gibuti;0;DJF
|
||||
DK;DNK;Danimarca;1;DKK
|
||||
DM;DMA;Dominica;0;XCD
|
||||
DO;DOM;Repubblica Dominicana;0;DOP
|
||||
DZ;DZA;Algeria;0;DZD
|
||||
EC;ECU;Ecuador;0;USD
|
||||
EE;EST;Estonia;1;EUR
|
||||
EG;EGY;Egitto;0;EGP
|
||||
EH;ESH;Sahara Occidentale;0;MAD
|
||||
ER;ERI;Eritrea;0;ERN
|
||||
ES;ESP;Spagna;1;EUR
|
||||
ET;ETH;Etiopia;0;ETB
|
||||
FI;FIN;Finlandia;1;EUR
|
||||
FJ;FJI;Figi;0;FJD
|
||||
FK;FLK;Isole Falkland;0;FKP
|
||||
FM;FSM;Micronesia;0;USD
|
||||
FO;FRO;Isole Fær Øer;0;DKK
|
||||
FR;FRA;Francia;1;EUR
|
||||
GA;GAB;Gabon;0;XAF
|
||||
GB;GBR;Regno Unito;0;GBP
|
||||
GD;GRD;Grenada;0;XCD
|
||||
GE;GEO;Georgia;0;GEL
|
||||
GF;GUF;Guyana francese;0;EUR
|
||||
GG;GGY;Guernsey;0;GBP
|
||||
GH;GHA;Ghana;0;GHS
|
||||
GI;GIB;Gibilterra;0;GIP
|
||||
GL;GRL;Groenlandia;0;DKK
|
||||
GM;GMB;Gambia;0;GMD
|
||||
GN;GIN;Guinea;0;GNF
|
||||
GP;GLP;Guadalupa;0;EUR
|
||||
GQ;GNQ;Guinea Equatoriale;0;XAF
|
||||
GR;GRC;Grecia;1;EUR
|
||||
GS;SGS;Georgia del Sud e isole Sandwich australi;0;GBP
|
||||
GT;GTM;Guatemala;0;GTQ
|
||||
GU;GUM;Guam;0;USD
|
||||
GW;GNB;Guinea-Bissau;0;XOF
|
||||
GY;GUY;Guyana;0;GYD
|
||||
HK;HKG;Hong Kong;0;HKD
|
||||
HM;HMD;Isole Heard e McDonald;0;AUD
|
||||
HN;HND;Honduras;0;HNL
|
||||
HR;HRV;Croazia;1;EUR
|
||||
HT;HTI;Haiti;0;HTG
|
||||
HU;HUN;Ungheria;1;HUF
|
||||
ID;IDN;Indonesia;0;IDR
|
||||
IE;IRL;Irlanda;1;EUR
|
||||
IL;ISR;Israele;0;ILS
|
||||
IM;IMN;Isola di Man;0;GBP
|
||||
IN;IND;India;0;INR
|
||||
IO;IOT;Territorio britannico dell'Oceano Indiano;0;USD
|
||||
IQ;IRQ;Iraq;0;IQD
|
||||
IR;IRN;Iran;0;IRR
|
||||
IS;ISL;Islanda;0;ISK
|
||||
IT;ITA;Italia;1;EUR
|
||||
JE;JEY;Jersey;0;GBP
|
||||
JM;JAM;Giamaica;0;JMD
|
||||
JO;JOR;Giordania;0;JOD
|
||||
JP;JPN;Giappone;0;JPY
|
||||
KE;KEN;Kenya;0;KES
|
||||
KG;KGZ;Kirghizistan;0;KGS
|
||||
KH;KHM;Cambogia;0;KHR
|
||||
KI;KIR;Kiribati;0;AUD
|
||||
KM;COM;Comore;0;KMF
|
||||
KN;KNA;Saint Kitts e Nevis;0;XCD
|
||||
KP;PRK;Corea del Nord;0;KPW
|
||||
KR;KOR;Corea del Sud;0;KRW
|
||||
KW;KWT;Kuwait;0;KWD
|
||||
KY;CYM;Isole Cayman;0;KYD
|
||||
KZ;KAZ;Kazakistan;0;KZT
|
||||
LA;LAO;Laos;0;LAK
|
||||
LB;LBN;Libano;0;LBP
|
||||
LC;LCA;Santa Lucia;0;XCD
|
||||
LI;LIE;Liechtenstein;0;CHF
|
||||
LK;LKA;Sri Lanka;0;LKR
|
||||
LR;LBR;Liberia;0;LRD
|
||||
LS;LSO;Lesotho;0;LSL
|
||||
LT;LTU;Lituania;1;EUR
|
||||
LU;LUX;Lussemburgo;1;EUR
|
||||
LV;LVA;Lettonia;1;EUR
|
||||
LY;LBY;Libia;0;LYD
|
||||
MA;MAR;Marocco;0;MAD
|
||||
MC;MCO;Monaco;0;EUR
|
||||
MD;MDA;Moldavia;0;MDL
|
||||
ME;MNE;Montenegro;0;EUR
|
||||
MF;MAF;Saint-Martin;0;EUR
|
||||
MG;MDG;Madagascar;0;MGA
|
||||
MH;MHL;Isole Marshall;0;USD
|
||||
MK;MKD;Macedonia del Nord;0;MKD
|
||||
ML;MLI;Mali;0;XOF
|
||||
MM;MMR;Myanmar;0;MMK
|
||||
MN;MNG;Mongolia;0;MNT
|
||||
MO;MAC;Macao;0;MOP
|
||||
MP;MNP;Isole Marianne Settentrionali;0;USD
|
||||
MQ;MTQ;Martinica;0;EUR
|
||||
MR;MRT;Mauritania;0;MRU
|
||||
MS;MSR;Montserrat;0;XCD
|
||||
MT;MLT;Malta;1;EUR
|
||||
MU;MUS;Mauritius;0;MUR
|
||||
MV;MDV;Maldive;0;MVR
|
||||
MW;MWI;Malawi;0;MWK
|
||||
MX;MEX;Messico;0;MXN
|
||||
MY;MYS;Malaysia;0;MYR
|
||||
MZ;MOZ;Mozambico;0;MZN
|
||||
NA;NAM;Namibia;0;NAD
|
||||
NC;NCL;Nuova Caledonia;0;XPF
|
||||
NE;NER;Niger;0;XOF
|
||||
NF;NFK;Isola Norfolk;0;AUD
|
||||
NG;NGA;Nigeria;0;NGN
|
||||
NI;NIC;Nicaragua;0;NIO
|
||||
NL;NLD;Paesi Bassi;1;EUR
|
||||
NO;NOR;Norvegia;0;NOK
|
||||
NP;NPL;Nepal;0;NPR
|
||||
NR;NRU;Nauru;0;AUD
|
||||
NU;NIU;Niue;0;NZD
|
||||
NZ;NZL;Nuova Zelanda;0;NZD
|
||||
OM;OMN;Oman;0;OMR
|
||||
PA;PAN;Panama;0;PAB
|
||||
PE;PER;Perù;0;PEN
|
||||
PF;PYF;Polinesia francese;0;XPF
|
||||
PG;PNG;Papua Nuova Guinea;0;PGK
|
||||
PH;PHL;Filippine;0;PHP
|
||||
PK;PAK;Pakistan;0;PKR
|
||||
PL;POL;Polonia;1;PLN
|
||||
PM;SPM;Saint-Pierre e Miquelon;0;EUR
|
||||
PN;PCN;Isole Pitcairn;0;NZD
|
||||
PR;PRI;Porto Rico;0;USD
|
||||
PS;PSE;Palestina;0;ILS
|
||||
PT;PRT;Portogallo;1;EUR
|
||||
PW;PLW;Palau;0;USD
|
||||
PY;PRY;Paraguay;0;PYG
|
||||
QA;QAT;Qatar;0;QAR
|
||||
RE;REU;Riunione;0;EUR
|
||||
RO;ROU;Romania;1;RON
|
||||
RS;SRB;Serbia;0;RSD
|
||||
RU;RUS;Russia;0;RUB
|
||||
RW;RWA;Ruanda;0;RWF
|
||||
SA;SAU;Arabia Saudita;0;SAR
|
||||
SB;SLB;Isole Salomone;0;SBD
|
||||
SC;SYC;Seychelles;0;SCR
|
||||
SD;SDN;Sudan;0;SDG
|
||||
SE;SWE;Svezia;1;SEK
|
||||
SG;SGP;Singapore;0;SGD
|
||||
SH;SHN;Sant'Elena, Ascensione e Tristan da Cunha;0;SHP
|
||||
SI;SVN;Slovenia;1;EUR
|
||||
SJ;SJM;Svalbard e Jan Mayen;0;NOK
|
||||
SK;SVK;Slovacchia;1;EUR
|
||||
SL;SLE;Sierra Leone;0;SLE
|
||||
SM;SMR;San Marino;0;EUR
|
||||
SN;SEN;Senegal;0;XOF
|
||||
SO;SOM;Somalia;0;SOS
|
||||
SR;SUR;Suriname;0;SRD
|
||||
SS;SSD;Sudan del Sud;0;SSP
|
||||
ST;STP;São Tomé e Príncipe;0;STN
|
||||
SV;SLV;El Salvador;0;USD
|
||||
SX;SXM;Sint Maarten;0;XCG
|
||||
SY;SYR;Siria;0;SYP
|
||||
SZ;SWZ;Eswatini;0;SZL
|
||||
TC;TCA;Isole Turks e Caicos;0;USD
|
||||
TD;TCD;Ciad;0;XAF
|
||||
TF;ATF;Terre australi e antartiche francesi;0;EUR
|
||||
TG;TGO;Togo;0;XOF
|
||||
TH;THA;Thailandia;0;THB
|
||||
TJ;TJK;Tagikistan;0;TJS
|
||||
TK;TKL;Tokelau;0;NZD
|
||||
TL;TLS;Timor Est;0;USD
|
||||
TM;TKM;Turkmenistan;0;TMT
|
||||
TN;TUN;Tunisia;0;TND
|
||||
TO;TON;Tonga;0;TOP
|
||||
TR;TUR;Turchia;0;TRY
|
||||
TT;TTO;Trinidad e Tobago;0;TTD
|
||||
TV;TUV;Tuvalu;0;AUD
|
||||
TW;TWN;Taiwan;0;TWD
|
||||
TZ;TZA;Tanzania;0;TZS
|
||||
UA;UKR;Ucraina;0;UAH
|
||||
UG;UGA;Uganda;0;UGX
|
||||
UM;UMI;Isole minori esterne degli Stati Uniti;0;USD
|
||||
US;USA;Stati Uniti;0;USD
|
||||
UY;URY;Uruguay;0;UYU
|
||||
UZ;UZB;Uzbekistan;0;UZS
|
||||
VA;VAT;Città del Vaticano;0;EUR
|
||||
VC;VCT;Saint Vincent e Grenadine;0;XCD
|
||||
VE;VEN;Venezuela;0;VES
|
||||
VG;VGB;Isole Vergini britanniche;0;USD
|
||||
VI;VIR;Isole Vergini americane;0;USD
|
||||
VN;VNM;Vietnam;0;VND
|
||||
VU;VUT;Vanuatu;0;VUV
|
||||
WF;WLF;Wallis e Futuna;0;XPF
|
||||
WS;WSM;Samoa;0;WST
|
||||
XI;;Irlanda del Nord (IVA);1;GBP
|
||||
XK;XKX;Kosovo;0;EUR
|
||||
YE;YEM;Yemen;0;YER
|
||||
YT;MYT;Mayotte;0;EUR
|
||||
ZA;ZAF;Sudafrica;0;ZAR
|
||||
ZM;ZMB;Zambia;0;ZMW
|
||||
ZW;ZWE;Zimbabwe;0;ZWG
|
||||
|
@@ -0,0 +1,287 @@
|
||||
using Khaemhat.Application.Instance;
|
||||
using Khaemhat.Application.Security;
|
||||
using Khaemhat.Application.Tables;
|
||||
using Khaemhat.Core.Entities;
|
||||
using Khaemhat.Core.Instance;
|
||||
using Khaemhat.Core.Tables;
|
||||
using Khaemhat.Data;
|
||||
using Khaemhat.Data.Querying;
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Khaemhat.Application.Seeding;
|
||||
|
||||
/// <summary>The kind of data a seeder loads (SPEC §14).</summary>
|
||||
public enum SeedKind
|
||||
{
|
||||
/// <summary>The base tables every company needs.</summary>
|
||||
Base = 0,
|
||||
|
||||
/// <summary>The fictitious demo company.</summary>
|
||||
Demo = 1,
|
||||
}
|
||||
|
||||
/// <summary>A source of base or demo data (SPEC §14). Seeders are idempotent: they add what is missing and change nothing else.</summary>
|
||||
public interface ISeeder
|
||||
{
|
||||
/// <summary>The licence module whose tables it fills (<c>CORE</c>, <c>ACCT</c>...).</summary>
|
||||
string ModuleCode { get; }
|
||||
|
||||
/// <summary>Base or demo.</summary>
|
||||
SeedKind Kind { get; }
|
||||
|
||||
/// <summary>The order among seeders of the same kind (lower first).</summary>
|
||||
int Order { get; }
|
||||
|
||||
/// <summary>Loads the data.</summary>
|
||||
/// <param name="context">The company, its unit of work and fiscal pack.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>A task.</returns>
|
||||
Task RunAsync(SeedContext context, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>What a seeder works with, and the counts of what it added.</summary>
|
||||
public sealed class SeedContext
|
||||
{
|
||||
private readonly Dictionary<string, int> _added = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>Creates the context.</summary>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="unitOfWork">The company unit of work, committed by the runner.</param>
|
||||
/// <param name="pack">The fiscal pack of the company.</param>
|
||||
/// <param name="today">Today, for the current year.</param>
|
||||
public SeedContext(string companyCode, IUnitOfWork unitOfWork, IFiscalPack pack, DateOnly today)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(companyCode);
|
||||
ArgumentNullException.ThrowIfNull(unitOfWork);
|
||||
ArgumentNullException.ThrowIfNull(pack);
|
||||
CompanyCode = companyCode;
|
||||
UnitOfWork = unitOfWork;
|
||||
Pack = pack;
|
||||
Today = today;
|
||||
}
|
||||
|
||||
/// <summary>The company.</summary>
|
||||
public string CompanyCode { get; }
|
||||
|
||||
/// <summary>The company unit of work.</summary>
|
||||
public IUnitOfWork UnitOfWork { get; }
|
||||
|
||||
/// <summary>The fiscal pack.</summary>
|
||||
public IFiscalPack Pack { get; }
|
||||
|
||||
/// <summary>Today.</summary>
|
||||
public DateOnly Today { get; }
|
||||
|
||||
/// <summary>Rows added, by table.</summary>
|
||||
public IReadOnlyDictionary<string, int> Added => _added;
|
||||
|
||||
/// <summary>Adds the rows whose code is missing; existing rows are left as the users made them.</summary>
|
||||
/// <typeparam name="T">The entity.</typeparam>
|
||||
/// <param name="table">The table, for the counts.</param>
|
||||
/// <param name="rows">The rows.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>Every row of the seed as stored (the existing one when the code was there).</returns>
|
||||
public async Task<IReadOnlyDictionary<string, T>> EnsureAsync<T>(string table, IEnumerable<T> rows, CancellationToken cancellationToken)
|
||||
where T : CodedEntity, new()
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(rows);
|
||||
var repository = UnitOfWork.Repository<T, long>();
|
||||
var existing = (await repository.ListAsync(Query.For<T>(), cancellationToken).ConfigureAwait(false)).Items
|
||||
.GroupBy(r => r.Code, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(g => g.Key, g => g.First(), StringComparer.OrdinalIgnoreCase);
|
||||
var result = new Dictionary<string, T>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (existing.TryGetValue(row.Code, out var found))
|
||||
{
|
||||
result[row.Code] = found;
|
||||
continue;
|
||||
}
|
||||
|
||||
row.Id = await repository.InsertAsync(row, cancellationToken).ConfigureAwait(false);
|
||||
existing[row.Code] = row;
|
||||
result[row.Code] = row;
|
||||
Count(table);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>Adds one row when nothing matches a condition.</summary>
|
||||
/// <typeparam name="T">The entity.</typeparam>
|
||||
/// <param name="table">The table, for the counts.</param>
|
||||
/// <param name="match">Finds the row.</param>
|
||||
/// <param name="row">The row to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>The stored row.</returns>
|
||||
public async Task<T> EnsureOneAsync<T>(string table, System.Linq.Expressions.Expression<Func<T, bool>> match, T row, CancellationToken cancellationToken)
|
||||
where T : class, IEntity<long>, new()
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(row);
|
||||
var repository = UnitOfWork.Repository<T, long>();
|
||||
var found = await repository.FindAsync(Query.For<T>().Where(match), cancellationToken).ConfigureAwait(false);
|
||||
if (found is not null)
|
||||
{
|
||||
return found;
|
||||
}
|
||||
|
||||
row.Id = await repository.InsertAsync(row, cancellationToken).ConfigureAwait(false);
|
||||
Count(table);
|
||||
return row;
|
||||
}
|
||||
|
||||
/// <summary>Counts a row added by hand.</summary>
|
||||
/// <param name="table">The table.</param>
|
||||
public void Count(string table) => _added[table] = _added.GetValueOrDefault(table) + 1;
|
||||
}
|
||||
|
||||
/// <summary>The outcome of a seed run.</summary>
|
||||
/// <param name="DataVersion">The data version now recorded, such as <c>IT 2026.2</c>.</param>
|
||||
/// <param name="Added">Rows added, by table.</param>
|
||||
public sealed record SeedReport(string DataVersion, IReadOnlyDictionary<string, int> Added)
|
||||
{
|
||||
/// <summary>Total rows added.</summary>
|
||||
public int Total => Added.Values.Sum();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs the seeders of a kind on a company in one unit of work and records the data version in the company setting
|
||||
/// <see cref="VersionSetting"/> (SPEC §14). At company creation and at every start it runs the base seeders when
|
||||
/// <c>KHAEMHAT_SEED_BASE</c> is on; the button <i>Aggiorna tabelle di base</i> and <c>scripts/seed.sh --base</c> run
|
||||
/// them on demand. Being idempotent, running again only adds what a newer data version brings.
|
||||
/// </summary>
|
||||
public sealed partial class SeedRunner : ICompanySeeder
|
||||
{
|
||||
/// <summary>The company setting with the version of the base data.</summary>
|
||||
public const string VersionSetting = "seed.base.version";
|
||||
|
||||
private readonly IReadOnlyList<ISeeder> _seeders;
|
||||
private readonly IUnitOfWorkFactory _factory;
|
||||
private readonly CompanyFiscalContext _fiscal;
|
||||
private readonly PermissionService _permissions;
|
||||
private readonly TableService _tables;
|
||||
private readonly FiscalYearService _years;
|
||||
private readonly TimeProvider _clock;
|
||||
private readonly ILogger<SeedRunner> _logger;
|
||||
|
||||
/// <summary>Creates the runner.</summary>
|
||||
/// <param name="seeders">The seeders.</param>
|
||||
/// <param name="factory">Opens the company databases.</param>
|
||||
/// <param name="fiscal">The fiscal pack of each company.</param>
|
||||
/// <param name="permissions">Checks permissions (the button).</param>
|
||||
/// <param name="tables">The tables (cache invalidation).</param>
|
||||
/// <param name="years">The fiscal years (cache invalidation).</param>
|
||||
/// <param name="clock">The clock.</param>
|
||||
/// <param name="logger">The log.</param>
|
||||
public SeedRunner(
|
||||
IEnumerable<ISeeder> seeders, IUnitOfWorkFactory factory, CompanyFiscalContext fiscal, PermissionService permissions, TableService tables,
|
||||
FiscalYearService years, TimeProvider clock, ILogger<SeedRunner> logger)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(seeders);
|
||||
ArgumentNullException.ThrowIfNull(factory);
|
||||
ArgumentNullException.ThrowIfNull(fiscal);
|
||||
ArgumentNullException.ThrowIfNull(permissions);
|
||||
ArgumentNullException.ThrowIfNull(tables);
|
||||
ArgumentNullException.ThrowIfNull(years);
|
||||
ArgumentNullException.ThrowIfNull(clock);
|
||||
ArgumentNullException.ThrowIfNull(logger);
|
||||
_seeders = [.. seeders.OrderBy(s => s.Kind).ThenBy(s => s.Order)];
|
||||
_factory = factory;
|
||||
_fiscal = fiscal;
|
||||
_permissions = permissions;
|
||||
_tables = tables;
|
||||
_years = years;
|
||||
_clock = clock;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Order => 10;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SeedAsync(string companyCode, CompanySeedContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
if (context.Base)
|
||||
{
|
||||
await RunAsync(companyCode, SeedKind.Base, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The button <i>Aggiorna tabelle di base</i>: runs the base seeders for a company.</summary>
|
||||
/// <param name="actor">Who asks: needs <c>company.settings.write</c>.</param>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>What was added.</returns>
|
||||
public async Task<SeedReport> UpdateBaseAsync(Actor actor, string companyCode, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var company = await CompanyGuard.DemandAsync(_permissions, actor, companyCode, TableService.WritePermission, cancellationToken).ConfigureAwait(false);
|
||||
return await RunAsync(company, SeedKind.Base, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>The data version recorded in a company, or <see langword="null"/> before the first run.</summary>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>The version.</returns>
|
||||
public async Task<string?> VersionAsync(string companyCode, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await using var uow = await _factory.CreateAsync(DatabaseScope.Company(CompanyCodes.Normalize(companyCode)), cancellationToken).ConfigureAwait(false);
|
||||
var setting = await uow.Repository<CompanySetting, long>().FindAsync(Query.For<CompanySetting>().Where(s => s.Key == VersionSetting), cancellationToken).ConfigureAwait(false);
|
||||
return setting?.Value;
|
||||
}
|
||||
|
||||
/// <summary>Runs every seeder of a kind on a company.</summary>
|
||||
/// <param name="companyCode">The company.</param>
|
||||
/// <param name="kind">Base or demo.</param>
|
||||
/// <param name="cancellationToken">Cancellation.</param>
|
||||
/// <returns>What was added.</returns>
|
||||
public async Task<SeedReport> RunAsync(string companyCode, SeedKind kind, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var company = CompanyCodes.Normalize(companyCode);
|
||||
var pack = await _fiscal.PackOfAsync(company, cancellationToken).ConfigureAwait(false);
|
||||
var today = DateOnly.FromDateTime(_clock.GetLocalNow().DateTime);
|
||||
SeedContext context;
|
||||
await using (var uow = await _factory.CreateAsync(DatabaseScope.Company(company), cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
await uow.BeginAsync(cancellationToken).ConfigureAwait(false);
|
||||
context = new SeedContext(company, uow, pack, today);
|
||||
foreach (var seeder in _seeders.Where(s => s.Kind == kind))
|
||||
{
|
||||
await seeder.RunAsync(context, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (kind == SeedKind.Base)
|
||||
{
|
||||
await WriteVersionAsync(uow, pack.DataVersion, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await uow.CommitAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await _tables.InvalidateAllAsync(company, cancellationToken).ConfigureAwait(false);
|
||||
await _years.InvalidateAsync(company, cancellationToken).ConfigureAwait(false);
|
||||
await _fiscal.InvalidateAsync(company, cancellationToken).ConfigureAwait(false);
|
||||
var report = new SeedReport(pack.DataVersion, context.Added);
|
||||
LogSeeded(_logger, kind, company, pack.DataVersion, report.Total);
|
||||
return report;
|
||||
}
|
||||
|
||||
private static async Task WriteVersionAsync(IUnitOfWork uow, string version, CancellationToken cancellationToken)
|
||||
{
|
||||
var settings = uow.Repository<CompanySetting, long>();
|
||||
var setting = await settings.FindAsync(Query.For<CompanySetting>().Where(s => s.Key == VersionSetting), cancellationToken).ConfigureAwait(false);
|
||||
if (setting is null)
|
||||
{
|
||||
await settings.InsertAsync(new CompanySetting { Key = VersionSetting, Value = version }, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else if (setting.Value != version)
|
||||
{
|
||||
setting.Value = version;
|
||||
await settings.UpdateAsync(setting, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Information, Message = "Dati {Kind} dell'azienda {Company} (versione {Version}): {Added} righe aggiunte.")]
|
||||
private static partial void LogSeeded(ILogger logger, SeedKind kind, string company, string version, int added);
|
||||
}
|
||||
Reference in new issue
Block a user