rename all variants of naming that hold an AyaType value to "aType" (parameter) / "AType" (not parameter) everywhere front and back; "ayType", "objectType", "oType" all are used in various areas
This commit is contained in:
@@ -268,7 +268,7 @@ namespace AyaNova.Util
|
||||
await ExecQueryAsync("CREATE TABLE aevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created TIMESTAMP NOT NULL, userid BIGINT NOT NULL,"
|
||||
+ "ayid BIGINT NOT NULL, ayatype INTEGER NOT NULL, ayevent INTEGER NOT NULL, textra VARCHAR(255))");
|
||||
//INDEX: Most selective first as there is more UNIQUE ID's than UNIQUE types
|
||||
await ExecQueryAsync("CREATE INDEX idx_aevent_ayid_aytype ON aevent (ayid, ayatype);");
|
||||
await ExecQueryAsync("CREATE INDEX idx_aevent_ayid_aType ON aevent (ayid, ayatype);");
|
||||
|
||||
//TODO: this may be a very low used index, revisit it down the road
|
||||
await ExecQueryAsync("CREATE INDEX idx_aevent_userid ON aevent (userid);");
|
||||
@@ -288,17 +288,17 @@ namespace AyaNova.Util
|
||||
//await ExecQueryAsync("CREATE UNIQUE INDEX asearchdictionary_word_idx ON asearchdictionary (word);");
|
||||
|
||||
//search key
|
||||
await ExecQueryAsync("CREATE TABLE asearchkey (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, wordid BIGINT NOT NULL REFERENCES asearchdictionary (id), objectid BIGINT NOT NULL, objecttype INTEGER NOT NULL)");
|
||||
await ExecQueryAsync("CREATE TABLE asearchkey (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, wordid BIGINT NOT NULL REFERENCES asearchdictionary (id), objectid BIGINT NOT NULL, atype INTEGER NOT NULL)");
|
||||
//INDEX: Most selective first as there is more UNIQUE ID's than UNIQUE types
|
||||
//to take advantage of this always query with where objectid=xx and objecttype=yy order
|
||||
//to take advantage of this always query with where objectid=xx and atype=yy order
|
||||
|
||||
//Only delete would use this, but, likely not needed as it's not in a loop
|
||||
//await ExecQueryAsync("CREATE INDEX asearchkey_typeid_idx ON asearchkey (objectid, objecttype );");
|
||||
//await ExecQueryAsync("CREATE INDEX asearchkey_typeid_idx ON asearchkey (objectid, atype );");
|
||||
|
||||
//This is what is needed during Searching
|
||||
//search does a lot of hits on searchkey looking for the wordid and optionally objecttype
|
||||
//In testing this did not pan out, in fact it was much faster to search both with and without a objecttype specified to simply have an index on wordid
|
||||
// await ExecQueryAsync("CREATE INDEX asearchkey_wordid_otype_idx ON asearchkey (wordid, objecttype);");
|
||||
//search does a lot of hits on searchkey looking for the wordid and optionally atype
|
||||
//In testing this did not pan out, in fact it was much faster to search both with and without a atype specified to simply have an index on wordid
|
||||
// await ExecQueryAsync("CREATE INDEX asearchkey_wordid_otype_idx ON asearchkey (wordid, atype);");
|
||||
await ExecQueryAsync("CREATE INDEX idx_asearchkey_wordid ON asearchkey (wordid);");
|
||||
|
||||
//Search indexing stored procedure
|
||||
@@ -306,7 +306,7 @@ namespace AyaNova.Util
|
||||
CREATE OR REPLACE PROCEDURE public.aydosearchindex(
|
||||
wordlist TEXT[],
|
||||
ayobjectid BIGINT,
|
||||
ayobjecttype INTEGER,
|
||||
ayatype INTEGER,
|
||||
cleanfirst boolean)
|
||||
LANGUAGE 'plpgsql'
|
||||
|
||||
@@ -318,12 +318,12 @@ BEGIN
|
||||
RAISE EXCEPTION 'Bad object id --> %', ayobjectid;
|
||||
END IF;
|
||||
|
||||
IF ayobjecttype=0 THEN
|
||||
RAISE EXCEPTION 'Bad object type --> %', ayobjecttype;
|
||||
IF ayatype=0 THEN
|
||||
RAISE EXCEPTION 'Bad object type --> %', ayatype;
|
||||
END IF;
|
||||
|
||||
IF cleanfirst=true THEN
|
||||
delete from asearchkey where objectid=ayobjectid and objecttype=ayobjecttype;
|
||||
delete from asearchkey where objectid=ayobjectid and atype=ayatype;
|
||||
END IF;
|
||||
|
||||
FOREACH s IN ARRAY wordlist
|
||||
@@ -331,9 +331,9 @@ BEGIN
|
||||
SELECT id INTO wordid FROM asearchdictionary WHERE word = s;
|
||||
IF wordid IS NULL THEN
|
||||
insert into asearchdictionary (word) values(s) on conflict (word) do update set word=excluded.word returning id into wordid;
|
||||
insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
|
||||
insert into asearchkey (wordid,objectid,atype) values(wordid,ayobjectid,ayatype);
|
||||
ELSE
|
||||
insert into asearchkey (wordid,objectid,objecttype) values(wordid,ayobjectid,ayobjecttype);
|
||||
insert into asearchkey (wordid,objectid,atype) values(wordid,ayobjectid,ayatype);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END;
|
||||
@@ -343,13 +343,13 @@ $BODY$;
|
||||
//Name fetcher function
|
||||
//CoreBizObject ADD here
|
||||
await ExecQueryAsync(@"
|
||||
CREATE OR REPLACE FUNCTION PUBLIC.AYGETNAME(IN AYOBJECTID BIGINT, IN AYOBJECTTYPE INTEGER) RETURNS TEXT AS $BODY$
|
||||
CREATE OR REPLACE FUNCTION PUBLIC.AYGETNAME(IN AYOBJECTID BIGINT, IN AYATYPE INTEGER) RETURNS TEXT AS $BODY$
|
||||
DECLARE
|
||||
aytable TEXT DEFAULT '';
|
||||
aynamecolumn TEXT DEFAULT 'name';
|
||||
returnstr TEXT DEFAULT '';
|
||||
BEGIN
|
||||
case ayobjecttype
|
||||
case ayatype
|
||||
when 0 then return 'LT:NoType';
|
||||
when 1 then return 'LT:Global';
|
||||
when 2 then aytable = 'awidget';
|
||||
@@ -496,7 +496,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
LogUpdateMessage(log);
|
||||
|
||||
await ExecQueryAsync("CREATE TABLE afileattachment (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
|
||||
+ "attachtoobjectid BIGINT NOT NULL, attachtoobjecttype INTEGER NOT NULL, "
|
||||
+ "attachtoobjectid BIGINT NOT NULL, attachtoatype INTEGER NOT NULL, "
|
||||
+ "storedfilename TEXT NOT NULL, displayfilename TEXT NOT NULL, contenttype TEXT, lastmodified TIMESTAMP NOT NULL, notes TEXT, exists BOOL NOT NULL, size BIGINT NOT NULL)");
|
||||
|
||||
//index required for ops that need to check if file already in db (delete, count refs etc)
|
||||
@@ -505,7 +505,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
|
||||
//index for the common issue of checking if an object has an attachment and retrieving them
|
||||
//note always query (where clause) in this same order for best performance
|
||||
await ExecQueryAsync("CREATE INDEX idx_afileattachment_attachtoobjectid_attachtoobjecttype ON afileattachment (attachtoobjectid, attachtoobjecttype );");
|
||||
await ExecQueryAsync("CREATE INDEX idx_afileattachment_attachtoobjectid_attachtoatype ON afileattachment (attachtoobjectid, attachtoatype );");
|
||||
|
||||
await SetSchemaLevelAsync(++currentSchema);
|
||||
}
|
||||
@@ -520,7 +520,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
LogUpdateMessage(log);
|
||||
|
||||
await ExecQueryAsync("CREATE TABLE aopsjob (gid uuid PRIMARY KEY, name TEXT NOT NULL, created TIMESTAMP NOT NULL, exclusive BOOL NOT NULL, "
|
||||
+ "startafter TIMESTAMP NOT NULL, jobtype INTEGER NOT NULL, subtype INTEGER, objectid BIGINT, objecttype INTEGER, jobstatus INTEGER NOT NULL, jobinfo TEXT)");
|
||||
+ "startafter TIMESTAMP NOT NULL, jobtype INTEGER NOT NULL, subtype INTEGER, objectid BIGINT, atype INTEGER, jobstatus INTEGER NOT NULL, jobinfo TEXT)");
|
||||
await ExecQueryAsync("CREATE TABLE aopsjoblog (gid uuid PRIMARY KEY, jobid uuid NOT NULL, created TIMESTAMP NOT NULL, statustext TEXT NOT NULL)");
|
||||
await SetSchemaLevelAsync(++currentSchema);
|
||||
}
|
||||
@@ -619,9 +619,9 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
await ExecQueryAsync("CREATE TABLE areview (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
|
||||
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
|
||||
+ "duedate TIMESTAMP NOT NULL, completeddate TIMESTAMP NULL, completionnotes TEXT, userid BIGINT NOT NULL REFERENCES auser(id), "
|
||||
+ "assignedbyuserid BIGINT NOT NULL REFERENCES auser(id), objecttype INTEGER NOT NULL, objectid BIGINT NOT NULL)");
|
||||
+ "assignedbyuserid BIGINT NOT NULL REFERENCES auser(id), atype INTEGER NOT NULL, objectid BIGINT NOT NULL)");
|
||||
|
||||
await ExecQueryAsync("CREATE INDEX idx_areview_objectid_objecttype ON areview (objectid, objecttype );");
|
||||
await ExecQueryAsync("CREATE INDEX idx_areview_objectid_atype ON areview (objectid, atype );");
|
||||
await ExecQueryAsync("CREATE INDEX idx_areview_userid ON areview (userid);");
|
||||
await ExecQueryAsync("CREATE INDEX idx_areview_duedate ON areview (duedate);");
|
||||
await ExecQueryAsync("CREATE INDEX idx_areview_completeddate ON areview (completeddate);");
|
||||
@@ -630,20 +630,20 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
//SERVICE BANK
|
||||
//Note: I'm allowing negative balances so this code differs slightly from the example it was drawn from https://dba.stackexchange.com/a/19368
|
||||
await ExecQueryAsync("CREATE TABLE aservicebank (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
|
||||
+ "entrydate TIMESTAMP NOT NULL, lastentrydate TIMESTAMP NULL, objecttype INTEGER NOT NULL, objectid BIGINT NOT NULL, sourcetype INTEGER NOT NULL, sourceid BIGINT NOT NULL, "
|
||||
+ "entrydate TIMESTAMP NOT NULL, lastentrydate TIMESTAMP NULL, atype INTEGER NOT NULL, objectid BIGINT NOT NULL, sourcetype INTEGER NOT NULL, sourceid BIGINT NOT NULL, "
|
||||
+ "incidents DECIMAL(19,5) NOT NULL, incidentsbalance DECIMAL(19,5) NOT NULL, lastincidentsbalance DECIMAL(19,5) NULL, "
|
||||
+ "currency DECIMAL(38,18) NOT NULL, currencybalance DECIMAL(38,18) NOT NULL, lastcurrencybalance DECIMAL(38,18) NULL, "
|
||||
+ "hours DECIMAL(19,5) NOT NULL, hoursbalance DECIMAL(19,5) NOT NULL, lasthoursbalance DECIMAL(19,5) NULL, "
|
||||
+ "CONSTRAINT unq_servicebank UNIQUE (entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), "
|
||||
+ "CONSTRAINT unq_servicebank_previous_values UNIQUE (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance), "
|
||||
+ "CONSTRAINT fk_servicebank_self FOREIGN KEY (lastentrydate, objectid, objecttype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance) REFERENCES aservicebank(entrydate, objectid, objecttype, incidentsbalance, hoursbalance, currencybalance), "
|
||||
+ "CONSTRAINT unq_servicebank UNIQUE (entrydate, objectid, atype, incidentsbalance, hoursbalance, currencybalance), "
|
||||
+ "CONSTRAINT unq_servicebank_previous_values UNIQUE (lastentrydate, objectid, atype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance), "
|
||||
+ "CONSTRAINT fk_servicebank_self FOREIGN KEY (lastentrydate, objectid, atype, lastincidentsbalance, lasthoursbalance, lastcurrencybalance) REFERENCES aservicebank(entrydate, objectid, atype, incidentsbalance, hoursbalance, currencybalance), "
|
||||
+ "CONSTRAINT chk_servicebank_valid_incidentbalance CHECK(incidentsbalance = COALESCE(lastincidentsbalance, 0) + incidents), "
|
||||
+ "CONSTRAINT chk_servicebank_valid_currencybalance CHECK(currencybalance = COALESCE(lastcurrencybalance, 0) + currency), "
|
||||
+ "CONSTRAINT chk_servicebank_valid_hoursbalance CHECK(hoursbalance = COALESCE(lasthoursbalance, 0) + hours), "
|
||||
+ "CONSTRAINT chk_servicebank_valid_dates_sequence CHECK(lastentrydate < entrydate), "
|
||||
+ "CONSTRAINT chk_servicebank_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 );");
|
||||
await ExecQueryAsync("CREATE INDEX idx_aservicebank_objectid_atype ON aservicebank (objectid, atype );");
|
||||
|
||||
//CONTRACT
|
||||
await ExecQueryAsync("CREATE TABLE acontract (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
|
||||
@@ -1000,7 +1000,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
{
|
||||
LogUpdateMessage(log);
|
||||
await ExecQueryAsync("CREATE TABLE areport (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
|
||||
+ "notes TEXT, roles INTEGER NOT NULL, objecttype INTEGER NOT NULL, template TEXT, style TEXT, jsprerender TEXT, jshelpers TEXT, rendertype INTEGER NOT NULL, "
|
||||
+ "notes TEXT, roles INTEGER NOT NULL, atype INTEGER NOT NULL, template TEXT, style TEXT, jsprerender TEXT, jshelpers TEXT, rendertype INTEGER NOT NULL, "
|
||||
+ "headertemplate TEXT, footertemplate TEXT, displayheaderfooter BOOL, paperformat INTEGER NOT NULL, landscape BOOL, marginoptionsbottom TEXT, "
|
||||
+ "marginoptionsleft TEXT, marginoptionsright TEXT, marginoptionstop TEXT, pageranges TEXT, prefercsspagesize BOOL, printbackground BOOL, scale DECIMAL(8,5) )");
|
||||
await SetSchemaLevelAsync(++currentSchema);
|
||||
|
||||
@@ -451,7 +451,7 @@ namespace AyaNova.Util
|
||||
Notes = notes,
|
||||
ContentType = contentType,
|
||||
AttachToObjectId = attachToObject.ObjectId,
|
||||
AttachToObjectType = attachToObject.ObjectType,
|
||||
AttachToAType = attachToObject.AType,
|
||||
LastModified = lastModified,
|
||||
Size = FileSize
|
||||
|
||||
@@ -495,7 +495,7 @@ namespace AyaNova.Util
|
||||
//
|
||||
internal static async Task DeleteAttachmentsForObjectAsync(AyaType ayaType, long ayaId, AyContext ct)
|
||||
{
|
||||
var deleteList = await ct.FileAttachment.Where(z => z.AttachToObjectId == ayaId && z.AttachToObjectType == ayaType).ToListAsync();
|
||||
var deleteList = await ct.FileAttachment.Where(z => z.AttachToObjectId == ayaId && z.AttachToAType == ayaType).ToListAsync();
|
||||
foreach (var d in deleteList)
|
||||
{
|
||||
await DeleteFileAttachmentAsync(d, ct);
|
||||
|
||||
Reference in New Issue
Block a user