From dd243bc943a10e2ea04e96cc2052a9c99a7b1db6 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 20 Jan 2021 19:53:25 +0000 Subject: [PATCH] --- server/AyaNova/models/PartInventory.cs | 69 ++++++++++++++++++++++++++ server/AyaNova/models/ServiceBank.cs | 3 +- server/AyaNova/util/AySchema.cs | 22 +++++++- 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 server/AyaNova/models/PartInventory.cs diff --git a/server/AyaNova/models/PartInventory.cs b/server/AyaNova/models/PartInventory.cs new file mode 100644 index 00000000..8a892f2f --- /dev/null +++ b/server/AyaNova/models/PartInventory.cs @@ -0,0 +1,69 @@ +using System; +using AyaNova.Biz; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Newtonsoft.Json; + +namespace AyaNova.Models +{ + //PARTINVENTORY LEDGER + + //NOTE: following pattern outlined here: + //https://dba.stackexchange.com/a/19368 + + public class PartInventory + { + public long Id { get; set; } + public uint Concurrency { get; set; } + + [Required] + public string Description { get; set; } + [Required] + public DateTime EntryDate { get; set; } + public DateTime? LastEntryDate { get; set; } + [Required] + public long PartId { get; set; } + [Required] + public long PartWarehouseId { get; set; } + [Required] + public long SourceId { get; set; } + [Required] + public AyaType SourceType { get; set; } + [Required] + public decimal Quantity { get; set; } + [Required] + public decimal Balance { get; set; } + public decimal? LastBalance { get; set; } + + + + public PartInventory() + { + EntryDate = DateTime.UtcNow; + SourceId=0; + SourceType=AyaType.NoType; + } + + + + }//eoc + + + + + +}//eons +/* +CREATE TABLE [dbo].[APARTBYWAREHOUSEINVENTORY]( + [AID] [uniqueidentifier] NOT NULL, + [ACREATED] [datetime] NOT NULL, + [AMODIFIED] [datetime] NOT NULL, + [ACREATOR] [uniqueidentifier] NOT NULL, + [AMODIFIER] [uniqueidentifier] NOT NULL, + [APARTID] [uniqueidentifier] NOT NULL, + [APARTWAREHOUSEID] [uniqueidentifier] NOT NULL, + [AQUANTITYONHAND] [decimal](19, 5) NOT NULL, + [AQUANTITYONORDER] [decimal](19, 5) NOT NULL,//calculated on teh fly from active PO's + [AMINSTOCKLEVEL] [decimal](19, 5) NOT NULL,//New table / feature PartRestock (partid/warhouseid/stocklevel) + [AQTYONORDERCOMMITTED] [decimal](19, 5) NOT NULL, //Calculated on the fly from po and partrequests +*/ \ No newline at end of file diff --git a/server/AyaNova/models/ServiceBank.cs b/server/AyaNova/models/ServiceBank.cs index ca92bfdd..42fdd3f5 100644 --- a/server/AyaNova/models/ServiceBank.cs +++ b/server/AyaNova/models/ServiceBank.cs @@ -6,8 +6,7 @@ using Newtonsoft.Json; namespace AyaNova.Models { - //NOTE: Any non required field (nullable in DB) sb nullable here, i.e. decimal? not decimal, - //otherwise the server will call it an invalid record if the field isn't sent from client + //SERVICEBANK LEDGER //NOTE: following pattern outlined here: //https://dba.stackexchange.com/a/19368 diff --git a/server/AyaNova/util/AySchema.cs b/server/AyaNova/util/AySchema.cs index e1002b98..c5a0591c 100644 --- a/server/AyaNova/util/AySchema.cs +++ b/server/AyaNova/util/AySchema.cs @@ -40,7 +40,7 @@ namespace AyaNova.Util HOW TO INDEX https://www.postgresqltutorial.com/postgresql-indexes/postgresql-create-index/ - AyaNova does a lot of name fetching so any tables that contain a lot of columns in addition to the name will benefit from a compound index on (id,name) + Other indexes should be created with care and after a huge load and integration test periodically look for unused indexes and see how they are performing HOW TO FIND SHITTY INDEXES: https://gist.github.com/jberkus/6b1bcaf7724dfc2a54f3 @@ -687,6 +687,26 @@ $BODY$ LANGUAGE PLPGSQL STABLE"); // await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partid ON apartassemblyitem(partid)"); // await ExecQueryAsync("CREATE INDEX idx_apartassemblyitem_partassemblyid ON apartassemblyitem(partassemblyid)"); + + + //PART INVENTORY + + await ExecQueryAsync("CREATE TABLE apartinventory (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, description text null, " + + "entrydate timestamp not null, lastentrydate timestamp null, partid bigint not null references apart, partwarehouseid bigint not null references apartwarehouse, " + + "sourcetype integer not null, sourceid bigint not null, " + + "quantity decimal(19,4) not null, balance decimal(19,4) not null, lastbalance decimal(19,4) null, " + + "CONSTRAINT UNQ_PartInventory UNIQUE (sourceid, sourcetype, entrydate, balance), " + + "CONSTRAINT UNQ_PartInventory_Previous_values UNIQUE (sourceid, sourcetype, lastentrydate, lastbalance), " + + "CONSTRAINT fk_PartInventory_self FOREIGN KEY (sourceid, sourcetype, lastentrydate, lastbalance) references apartinventory(sourceid, sourcetype, entrydate, balance), " + + "CONSTRAINT CHK_PartInventory_Valid_Balance CHECK(balance >= 0 AND (balance = COALESCE(lastbalance, 0) + quantity)), " + + + "CONSTRAINT CHK_PartInventory_Valid_Dates_Sequence CHECK(lastentrydate < entrydate), " + + "CONSTRAINT CHK_PartInventory_Valid_Previous_Columns CHECK((lastentrydate IS NULL AND lastincidentsbalance IS NULL AND lastcurrencybalance IS NULL AND lasthoursbalance IS NULL) OR (lastentrydate IS NOT NULL AND lastincidentsbalance IS NOT NULL AND lastcurrencybalance IS NOT NULL AND lasthoursbalance IS NOT NULL)) " + + " )"); + await ExecQueryAsync("CREATE INDEX idx_aservicebank_objectid_objecttype ON aservicebank (objectid, objecttype );"); + + + //PROJECT await ExecQueryAsync("CREATE TABLE aproject (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name text not null unique, active bool not null, " + "notes text, wiki text, customfields text, tags varchar(255) ARRAY, " +