This commit is contained in:
2021-01-20 19:53:25 +00:00
parent fd586468b9
commit dd243bc943
3 changed files with 91 additions and 3 deletions

View File

@@ -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
*/

View File

@@ -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

View File

@@ -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, " +