This commit is contained in:
2021-02-26 16:09:55 +00:00
parent a6cafef66f
commit 009bcffc29

View File

@@ -243,15 +243,15 @@ namespace AyaNova.Util
+ ")");
//create global ops BACKUP settings table
await ExecQueryAsync("CREATE TABLE aglobalopsbackupsettings (id INTEGER NOT NULL PRIMARY KEY, active BOOL NOT NULL, " +
"backuptime TIMESTAMP, backupsetstokeep int, backupattachments BOOL)");
await ExecQueryAsync("CREATE TABLE aglobalopsbackupsettings (id INTEGER NOT NULL PRIMARY KEY, active BOOL NOT NULL, "
+ "backuptime TIMESTAMP, backupsetstokeep int, backupattachments BOOL)");
await ExecQueryAsync("CREATE TABLE aglobalopsnotificationsettings (id INTEGER NOT NULL PRIMARY KEY, smtpdeliveryactive BOOL NOT NULL, " +
"smtpserveraddress TEXT, smtpaccount TEXT, smtppassword TEXT, connectionsecurity INTEGER NOT NULL default 0, smtpserverport INTEGER, notifyfromaddress TEXT, ayanovaserverurl TEXT)");
await ExecQueryAsync("CREATE TABLE aglobalopsnotificationsettings (id INTEGER NOT NULL PRIMARY KEY, smtpdeliveryactive BOOL NOT NULL, "
+ "smtpserveraddress TEXT, smtpaccount TEXT, smtppassword TEXT, connectionsecurity INTEGER NOT NULL default 0, smtpserverport INTEGER, notifyfromaddress TEXT, ayanovaserverurl TEXT)");
//create aevent biz event log table
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))");
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);");
@@ -425,16 +425,16 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//Add user table
await ExecQueryAsync("CREATE TABLE auser (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active BOOL NOT NULL, name TEXT NOT NULL UNIQUE, " +
"lastlogin TIMESTAMP, login TEXT NOT NULL UNIQUE, password TEXT NOT NULL, salt TEXT NOT NULL, roles INTEGER NOT NULL, currentauthtoken TEXT, " +
"dlkey TEXT, dlkeyexpire TIMESTAMP, passwordresetcode TEXT, passwordresetcodeexpire TIMESTAMP, usertype INTEGER NOT NULL, employeenumber TEXT, notes TEXT, customerid BIGINT, " +
"headofficeid BIGINT, vendorid BIGINT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE auser (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active BOOL NOT NULL, name TEXT NOT NULL UNIQUE, "
+ "lastlogin TIMESTAMP, login TEXT NOT NULL UNIQUE, password TEXT NOT NULL, salt TEXT NOT NULL, roles INTEGER NOT NULL, currentauthtoken TEXT, "
+ "dlkey TEXT, dlkeyexpire TIMESTAMP, passwordresetcode TEXT, passwordresetcodeexpire TIMESTAMP, usertype INTEGER NOT NULL, employeenumber TEXT, notes TEXT, customerid BIGINT, "
+ "headofficeid BIGINT, vendorid BIGINT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
//Add user options table
await ExecQueryAsync("CREATE TABLE auseroptions (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
"userid BIGINT NOT NULL REFERENCES auser (id), translationid BIGINT NOT NULL REFERENCES atranslation (id), languageoverride TEXT, timezoneoverride TEXT, " +
"currencyname TEXT, hour12 BOOL NOT NULL, emailaddress TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, uicolor VARCHAR(12) NOT NULL default '#000000', mapurltemplate TEXT)");
await ExecQueryAsync("CREATE TABLE auseroptions (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "userid BIGINT NOT NULL REFERENCES auser (id), translationid BIGINT NOT NULL REFERENCES atranslation (id), languageoverride TEXT, timezoneoverride TEXT, "
+ "currencyname TEXT, hour12 BOOL NOT NULL, emailaddress TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, uicolor VARCHAR(12) NOT NULL default '#000000', mapurltemplate TEXT)");
//Prime the db with the default SuperUser account
@@ -465,9 +465,9 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//Add widget table
//id, TEXT, longtext, boolean, currency,
await ExecQueryAsync("CREATE TABLE awidget (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL," +
"startdate TIMESTAMP, enddate TIMESTAMP, dollaramount DECIMAL(19,4), active BOOL NOT NULL, usertype int4, count INTEGER," +
"notes TEXT, userid BIGINT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE awidget (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL UNIQUE, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,"
+ "startdate TIMESTAMP, enddate TIMESTAMP, dollaramount DECIMAL(19,4), active BOOL NOT NULL, usertype int4, count INTEGER,"
+ "notes TEXT, userid BIGINT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -479,9 +479,9 @@ $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, " +
"storedfilename TEXT NOT NULL, displayfilename TEXT NOT NULL, contenttype TEXT, lastmodified TIMESTAMP NOT NULL, notes TEXT, exists BOOL NOT NULL, size BIGINT NOT NULL)");
await ExecQueryAsync("CREATE TABLE afileattachment (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "attachtoobjectid BIGINT NOT NULL, attachtoobjecttype 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)
//LOOKAT: isn't this useless without the ID as well or is that not fetched?
@@ -503,8 +503,8 @@ $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)");
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)");
await ExecQueryAsync("CREATE TABLE aopsjoblog (gid uuid PRIMARY KEY, jobid uuid NOT NULL, created TIMESTAMP NOT NULL, statustext TEXT NOT NULL)");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -544,8 +544,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
{
LogUpdateMessage(log);
await ExecQueryAsync("CREATE TABLE aformcustom (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
"formkey VARCHAR(255) NOT NULL, template TEXT, UNIQUE(formkey))");
await ExecQueryAsync("CREATE TABLE aformcustom (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "formkey VARCHAR(255) NOT NULL, template TEXT, UNIQUE(formkey))");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -557,8 +557,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
{
LogUpdateMessage(log);
await ExecQueryAsync("CREATE TABLE apicklisttemplate (id INTEGER NOT NULL PRIMARY KEY, " +
"template TEXT)");
await ExecQueryAsync("CREATE TABLE apicklisttemplate (id INTEGER NOT NULL PRIMARY KEY, "
+ "template TEXT)");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -571,39 +571,39 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
LogUpdateMessage(log);
//SERVICERATE
await ExecQueryAsync("CREATE TABLE aservicerate (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, " +
"accountnumber TEXT, unit TEXT, cost DECIMAL(19,4) NOT NULL default 0, charge DECIMAL(19,4) NOT NULL default 0)");
await ExecQueryAsync("CREATE TABLE aservicerate (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, "
+ "accountnumber TEXT, unit TEXT, cost DECIMAL(19,4) NOT NULL default 0, charge DECIMAL(19,4) NOT NULL default 0)");
//TRAVELRATE
await ExecQueryAsync("CREATE TABLE atravelrate (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, " +
"accountnumber TEXT, unit TEXT, cost DECIMAL(19,4) NOT NULL default 0, charge DECIMAL(19,4) NOT NULL default 0)");
await ExecQueryAsync("CREATE TABLE atravelrate (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, "
+ "accountnumber TEXT, unit TEXT, cost DECIMAL(19,4) NOT NULL default 0, charge DECIMAL(19,4) NOT NULL default 0)");
//TAXCODE
await ExecQueryAsync("CREATE TABLE ataxcode (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, " +
"taxa DECIMAL(19,4) NOT NULL default 0, taxb DECIMAL(19,4) NOT NULL default 0, taxontax BOOL NOT NULL default false)");
await ExecQueryAsync("CREATE TABLE ataxcode (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, "
+ "taxa DECIMAL(19,4) NOT NULL default 0, taxb DECIMAL(19,4) NOT NULL default 0, taxontax BOOL NOT NULL default false)");
//MEMO
await ExecQueryAsync("CREATE TABLE amemo (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"sent TIMESTAMP NOT NULL, viewed BOOL default false, replied BOOL default false, fromid BIGINT NOT NULL REFERENCES auser(id), toid BIGINT NOT NULL REFERENCES auser(id) )");
await ExecQueryAsync("CREATE TABLE amemo (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "sent TIMESTAMP NOT NULL, viewed BOOL default false, replied BOOL default false, fromid BIGINT NOT NULL REFERENCES auser(id), toid BIGINT NOT NULL REFERENCES auser(id) )");
//REMINDER
await ExecQueryAsync("CREATE TABLE areminder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"startdate TIMESTAMP NOT NULL, stopdate TIMESTAMP NOT NULL, userid BIGINT NOT NULL REFERENCES auser(id), color VARCHAR(12) NOT NULL default '#ffffff')");
await ExecQueryAsync("CREATE TABLE areminder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "startdate TIMESTAMP NOT NULL, stopdate TIMESTAMP NOT NULL, userid BIGINT NOT NULL REFERENCES auser(id), color VARCHAR(12) NOT NULL default '#ffffff')");
await ExecQueryAsync("CREATE INDEX idx_areminder_userid ON areminder (userid);");
await ExecQueryAsync("CREATE INDEX idx_areminder_startdate ON areminder (startdate);");
await ExecQueryAsync("CREATE INDEX idx_areminder_stopdate ON areminder (stopdate);");
//REVIEW
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)");
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)");
await ExecQueryAsync("CREATE INDEX idx_areview_objectid_objecttype ON areview (objectid, objecttype );");
await ExecQueryAsync("CREATE INDEX idx_areview_userid ON areview (userid);");
@@ -613,104 +613,104 @@ $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, " +
"incidents DECIMAL(19,4) NOT NULL, incidentsbalance DECIMAL(19,4) NOT NULL, lastincidentsbalance DECIMAL(19,4) NULL, " +
"currency DECIMAL(19,4) NOT NULL, currencybalance DECIMAL(19,4) NOT NULL, lastcurrencybalance DECIMAL(19,4) NULL, " +
"hours DECIMAL(19,4) NOT NULL, hoursbalance DECIMAL(19,4) NOT NULL, lasthoursbalance DECIMAL(19,4) 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 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 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, "
+ "incidents DECIMAL(19,4) NOT NULL, incidentsbalance DECIMAL(19,4) NOT NULL, lastincidentsbalance DECIMAL(19,4) NULL, "
+ "currency DECIMAL(19,4) NOT NULL, currencybalance DECIMAL(19,4) NOT NULL, lastcurrencybalance DECIMAL(19,4) NULL, "
+ "hours DECIMAL(19,4) NOT NULL, hoursbalance DECIMAL(19,4) NOT NULL, lasthoursbalance DECIMAL(19,4) 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 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 );");
//CUSTOMER
await ExecQueryAsync("CREATE TABLE acustomer (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, " +
"webaddress TEXT, popupnotes TEXT, billheadoffice BOOL, technotes TEXT, accountnumber TEXT, usesbanking BOOL, contractexpires TIMESTAMP NULL, " +
"phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, " +
"postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6))");
await ExecQueryAsync("CREATE TABLE acustomer (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, "
+ "webaddress TEXT, popupnotes TEXT, billheadoffice BOOL, technotes TEXT, accountnumber TEXT, usesbanking BOOL, contractexpires TIMESTAMP NULL, "
+ "phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, "
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6))");
await ExecQueryAsync("ALTER TABLE auser ADD FOREIGN KEY (customerid) REFERENCES acustomer(id)");
//CUSTOMER NOTES
await ExecQueryAsync("CREATE TABLE acustomernote (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
"customerid BIGINT NOT NULL REFERENCES acustomer(id), userid BIGINT NOT NULL REFERENCES auser(id), " +
"notedate TIMESTAMP NOT NULL, notes TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE acustomernote (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "customerid BIGINT NOT NULL REFERENCES acustomer(id), userid BIGINT NOT NULL REFERENCES auser(id), "
+ "notedate TIMESTAMP NOT NULL, notes TEXT, tags VARCHAR(255) ARRAY )");
//CONTRACT
await ExecQueryAsync("CREATE TABLE acontract (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 )");
await ExecQueryAsync("CREATE TABLE acontract (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 )");
await ExecQueryAsync("ALTER TABLE acustomer ADD column contractid BIGINT NULL REFERENCES acontract");
//HEADOFFICE
await ExecQueryAsync("CREATE TABLE aheadoffice (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," +
"webaddress TEXT, accountnumber TEXT, usesbanking BOOL, contractexpires TIMESTAMP NULL, contractid BIGINT NULL REFERENCES acontract(id), " +
"phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, " +
"postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6)" +
" )");
await ExecQueryAsync("CREATE TABLE aheadoffice (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,"
+ "webaddress TEXT, accountnumber TEXT, usesbanking BOOL, contractexpires TIMESTAMP NULL, contractid BIGINT NULL REFERENCES acontract(id), "
+ "phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, "
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6)"
+ " )");
await ExecQueryAsync("ALTER TABLE acustomer ADD column headofficeid BIGINT NULL REFERENCES aheadoffice");
await ExecQueryAsync("ALTER TABLE auser ADD FOREIGN KEY (headofficeid) REFERENCES aheadoffice(id)");
//VENDOR
await ExecQueryAsync("CREATE TABLE avendor (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, webaddress TEXT, popupnotes TEXT, accountnumber TEXT, " +
"contact TEXT, contactnotes TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, " +
"postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6))");
await ExecQueryAsync("CREATE TABLE avendor (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, webaddress TEXT, popupnotes TEXT, accountnumber TEXT, "
+ "contact TEXT, contactnotes TEXT, phone1 TEXT, phone2 TEXT, phone3 TEXT, phone4 TEXT, phone5 TEXT, emailaddress TEXT, "
+ "postaddress TEXT, postcity TEXT, postregion TEXT, postcountry TEXT, postcode TEXT, address TEXT, city TEXT, region TEXT, country TEXT, latitude DECIMAL(8,6), longitude DECIMAL(9,6))");
await ExecQueryAsync("ALTER TABLE auser ADD FOREIGN KEY (vendorid) REFERENCES avendor(id)");
//PART
await ExecQueryAsync("CREATE TABLE apart (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"partnumber TEXT NOT NULL UNIQUE, manufacturerid BIGINT REFERENCES avendor, manufacturernumber TEXT, " +
"wholesalerid BIGINT REFERENCES avendor, wholesalernumber TEXT, alternativewholesalerid BIGINT REFERENCES avendor, alternativewholesalernumber TEXT, " +
"cost DECIMAL(19,4) NOT NULL, retail DECIMAL(19,4) NOT NULL, unitofmeasure TEXT, upc TEXT " +
" )");
await ExecQueryAsync("CREATE TABLE apart (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "partnumber TEXT NOT NULL UNIQUE, manufacturerid BIGINT REFERENCES avendor, manufacturernumber TEXT, "
+ "wholesalerid BIGINT REFERENCES avendor, wholesalernumber TEXT, alternativewholesalerid BIGINT REFERENCES avendor, alternativewholesalernumber TEXT, "
+ "cost DECIMAL(19,4) NOT NULL, retail DECIMAL(19,4) NOT NULL, unitofmeasure TEXT, upc TEXT "
+ " )");
//PARTWAREHOUSE
await ExecQueryAsync("CREATE TABLE apartwarehouse (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)");
await ExecQueryAsync("CREATE TABLE apartwarehouse (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)");
await ExecQueryAsync("INSERT INTO apartwarehouse(name, active) VALUES ('Default', true);");
//PARTSERIAL
await ExecQueryAsync("CREATE TABLE apartserial (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial TEXT NOT NULL, " +
"partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, CONSTRAINT unq_partserialpart UNIQUE (partid, serial) )");//ensure not duplicate partid/serial combo
await ExecQueryAsync("CREATE TABLE apartserial (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial TEXT NOT NULL, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, CONSTRAINT unq_partserialpart UNIQUE (partid, serial) )");//ensure not duplicate partid/serial combo
//PARTASSEMBLY
await ExecQueryAsync("CREATE TABLE apartassembly (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 )");
await ExecQueryAsync("CREATE TABLE apartassembly (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 )");
//PARTASSEMBLYITEM
await ExecQueryAsync("CREATE TABLE apartassemblyitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, partassemblyid BIGINT NOT NULL REFERENCES apartassembly ON DELETE CASCADE, " +
"partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, quantity DECIMAL(19,4) NOT NULL default 1, " +
"CONSTRAINT unq_partassemblypart UNIQUE (partid, partassemblyid) " +//ensure no duplicate parts in the same assembly
")");
await ExecQueryAsync("CREATE TABLE apartassemblyitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, partassemblyid BIGINT NOT NULL REFERENCES apartassembly ON DELETE CASCADE, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, quantity DECIMAL(19,4) NOT NULL default 1, "
+ "CONSTRAINT unq_partassemblypart UNIQUE (partid, partassemblyid) "
+ ")");
// 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 NOT NULL, " +
"entrydate TIMESTAMP NOT NULL, lastentrydate TIMESTAMP NULL, partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, " +
"sourcetype INTEGER, sourceid BIGINT, " +
"quantity DECIMAL(19,4) NOT NULL, balance DECIMAL(19,4) NOT NULL, lastbalance DECIMAL(19,4) NULL, " +
"CONSTRAINT unq_partinventory UNIQUE (partid, partwarehouseid, entrydate, balance), " +
"CONSTRAINT unq_partinventory_previous_values UNIQUE (partid, partwarehouseid, lastentrydate, lastbalance), " +
"CONSTRAINT fk_partinventory_self FOREIGN KEY (partid, partwarehouseid, lastentrydate, lastbalance) REFERENCES apartinventory(partid, partwarehouseid, 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 lastbalance IS NULL) OR (lastentrydate IS NOT NULL AND lastbalance IS NOT NULL)), " +
"CONSTRAINT chk_partinventory_valid_source CHECK((sourcetype IS NULL AND sourceid IS NULL) OR (sourcetype IS NOT NULL AND sourceid IS NOT NULL)) " +
" )");
await ExecQueryAsync("CREATE TABLE apartinventory (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, description TEXT NOT NULL, "
+ "entrydate TIMESTAMP NOT NULL, lastentrydate TIMESTAMP NULL, partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, "
+ "sourcetype INTEGER, sourceid BIGINT, "
+ "quantity DECIMAL(19,4) NOT NULL, balance DECIMAL(19,4) NOT NULL, lastbalance DECIMAL(19,4) NULL, "
+ "CONSTRAINT unq_partinventory UNIQUE (partid, partwarehouseid, entrydate, balance), "
+ "CONSTRAINT unq_partinventory_previous_values UNIQUE (partid, partwarehouseid, lastentrydate, lastbalance), "
+ "CONSTRAINT fk_partinventory_self FOREIGN KEY (partid, partwarehouseid, lastentrydate, lastbalance) REFERENCES apartinventory(partid, partwarehouseid, 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 lastbalance IS NULL) OR (lastentrydate IS NOT NULL AND lastbalance IS NOT NULL)), "
+ "CONSTRAINT chk_partinventory_valid_source CHECK((sourcetype IS NULL AND sourceid IS NULL) OR (sourcetype IS NOT NULL AND sourceid IS NOT NULL)) "
+ " )");
//PART INVENTORY VIEW
await ExecQueryAsync("CREATE VIEW vpartinventorynow AS WITH T AS (SELECT *, ROW_NUMBER() OVER(PARTITION BY partid, partwarehouseid ORDER BY entrydate DESC) AS rn FROM apartinventory) SELECT * FROM T WHERE rn = 1");
@@ -721,153 +721,169 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
//await ExecQueryAsync("CREATE INDEX idx_PartInventory_SourceId_SourceType ON apartinventory (sourceid, sourcetype);");
//PARTSTOCKLEVEL
await ExecQueryAsync("CREATE TABLE apartstocklevel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse ON DELETE CASCADE, " +
"partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, minimumquantity DECIMAL(19,4) NOT NULL default 1, " +
"CONSTRAINT unq_partstocklevel_part_warehouse UNIQUE (partid, partwarehouseid) " +//ensure no duplicates
")");
await ExecQueryAsync("CREATE TABLE apartstocklevel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse ON DELETE CASCADE, "
+ "partid BIGINT NOT NULL REFERENCES apart ON DELETE CASCADE, minimumquantity DECIMAL(19,4) NOT NULL default 1, "
+ "CONSTRAINT unq_partstocklevel_part_warehouse UNIQUE (partid, partwarehouseid) "//ensure no duplicates
+ ")");
//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, " +
"datestarted TIMESTAMP NULL, datecompleted TIMESTAMP NULL, projectoverseerid BIGINT NULL REFERENCES auser(id), accountnumber TEXT)");
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, "
+ "datestarted TIMESTAMP NULL, datecompleted TIMESTAMP NULL, projectoverseerid BIGINT NULL REFERENCES auser(id), accountnumber TEXT)");
//PURCHASEORDER
await ExecQueryAsync("CREATE TABLE apurchaseorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"vendormemo TEXT, dropshiptocustomerid BIGINT REFERENCES acustomer, referencenumber TEXT, vendorid BIGINT NOT NULL REFERENCES avendor, " +
"ordereddate TIMESTAMP, expectedreceivedate TIMESTAMP, status integer CONSTRAINT chk_status_valid CHECK (status > 0 AND status < 7), " +//"a check constraint is satisfied if the check expression evaluates to true or the null value"
"projectid BIGINT REFERENCES aproject, text1 TEXT, text2 TEXT " +
" )");
await ExecQueryAsync("CREATE TABLE apurchaseorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "vendormemo TEXT, dropshiptocustomerid BIGINT REFERENCES acustomer, referencenumber TEXT, vendorid BIGINT NOT NULL REFERENCES avendor, "
+ "ordereddate TIMESTAMP, expectedreceivedate TIMESTAMP, status integer CONSTRAINT chk_status_valid CHECK (status > 0 AND status < 7), "//"a check constraint is satisfied if the check expression evaluates to true or the null value"
+ "projectid BIGINT REFERENCES aproject, text1 TEXT, text2 TEXT "
+ " )");
//PURCHASEORDERITEM
await ExecQueryAsync("CREATE TABLE apurchaseorderitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, purchaseorderid BIGINT NOT NULL REFERENCES apurchaseorder ON DELETE CASCADE, " +
"partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, quantityordered DECIMAL(19,4) NOT NULL default 0, " +
"quantityreceived DECIMAL(19,4) NOT NULL default 0, purchaseordercost DECIMAL(19,4) NOT NULL default 0, receivedcost DECIMAL(19,4) NOT NULL default 0, " +
"receiveddate TIMESTAMP, partrequestedbyid BIGINT REFERENCES auser, purchasetaxcodeid BIGINT REFERENCES ataxcode, vendorpartnumber TEXT, serials TEXT " +
")");
await ExecQueryAsync("CREATE TABLE apurchaseorderitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, purchaseorderid BIGINT NOT NULL REFERENCES apurchaseorder ON DELETE CASCADE, "
+ "partid BIGINT NOT NULL REFERENCES apart, partwarehouseid BIGINT NOT NULL REFERENCES apartwarehouse, quantityordered DECIMAL(19,4) NOT NULL default 0, "
+ "quantityreceived DECIMAL(19,4) NOT NULL default 0, purchaseordercost DECIMAL(19,4) NOT NULL default 0, receivedcost DECIMAL(19,4) NOT NULL default 0, "
+ "receiveddate TIMESTAMP, partrequestedbyid BIGINT REFERENCES auser, purchasetaxcodeid BIGINT REFERENCES ataxcode, vendorpartnumber TEXT, serials TEXT "
+ ")");
//RESTOCK REQUIRED
//VPARTSONORDER
await ExecQueryAsync("CREATE VIEW vpartsonorder AS SELECT partid, partwarehouseid, SUM((COALESCE(apurchaseorderitem.quantityordered,0)-COALESCE(apurchaseorderitem.quantityreceived,0))) AS quantityonorder "
+ "FROM apurchaseorderitem WHERE (COALESCE(apurchaseorderitem.quantityordered,0)-COALESCE(apurchaseorderitem.quantityreceived,0)) > 0 GROUP BY partid, partwarehouseid");
//VRESTOCKREQUIRED
await ExecQueryAsync("CREATE VIEW vrestockrequired AS SELECT apart.id AS partid, apartwarehouse.id AS partwarehouseid, apart.partnumber, apartwarehouse.name AS displaywarehouse, "
+ "apartstocklevel.minimumquantity, vpartinventorynow.balance, COALESCE(vpartsonorder.quantityonorder,0) AS onorderquantity, "
+ "apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, 0) + COALESCE(vpartsonorder.quantityonorder, 0)) AS requiredquantity "
+ "FROM vpartinventorynow "
+ "LEFT JOIN apart ON vpartinventorynow.partid=apart.id LEFT JOIN apartwarehouse ON vpartinventorynow.partwarehouseid = apartwarehouse.id "
+ "LEFT JOIN apartstocklevel ON vpartinventorynow.partid=apartstocklevel.partid AND vpartinventorynow.partwarehouseid=apartstocklevel.partwarehouseid "
+ "LEFT JOIN vpartsonorder ON vpartinventorynow.partid=vpartsonorder.partid AND vpartinventorynow.partwarehouseid=vpartsonorder.partwarehouseid "
+ "WHERE apartstocklevel.minimumquantity IS NOT NULL AND (apartstocklevel.minimumquantity - (COALESCE(vpartinventorynow.balance, 0) + COALESCE(vpartsonorder.quantityonorder, 0))) >0 "
+ "ORDER BY requiredquantity DESC");
//UNITMODEL
await ExecQueryAsync("CREATE TABLE aunitmodel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NULL, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"number TEXT NOT NULL, vendorid BIGINT NULL REFERENCES avendor(id), upc TEXT NULL, lifetimewarranty BOOL NOT NULL, introduceddate TIMESTAMP NULL, " +
"discontinued BOOL NOT NULL, discontinueddate TIMESTAMP NULL, warrantylength INTEGER NULL, warrantyterms TEXT NULL, CONSTRAINT UNQ_UnitModelNumberVendorId UNIQUE (number, vendorid) " +
")");
await ExecQueryAsync("CREATE TABLE aunitmodel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NULL, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "number TEXT NOT NULL, vendorid BIGINT NULL REFERENCES avendor(id), upc TEXT NULL, lifetimewarranty BOOL NOT NULL, introduceddate TIMESTAMP NULL, "
+ "discontinued BOOL NOT NULL, discontinueddate TIMESTAMP NULL, warrantylength INTEGER NULL, warrantyterms TEXT NULL, CONSTRAINT UNQ_UnitModelNumberVendorId UNIQUE (number, vendorid) "
+ ")");
//UNIT
await ExecQueryAsync("CREATE TABLE aunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"serial TEXT NOT NULL, customerid BIGINT NOT NULL REFERENCES acustomer(id), parentunitid BIGINT NULL REFERENCES aunit(id), " +
"unitmodelid BIGINT NULL REFERENCES aunitmodel(id), unithasownaddress BOOL, boughthere BOOL, purchasedfromvendorid BIGINT NULL REFERENCES avendor(id), " +
"receipt TEXT NULL, purchaseddate TIMESTAMP NULL, description TEXT NULL, replacedbyunitid BIGINT NULL REFERENCES aunit(id), " +
"overridemodelwarranty BOOL, warrantylength INTEGER NULL, warrantyterms TEXT NULL, usesbanking BOOL, metered BOOL, lifetimewarranty BOOL, " +
"text1 TEXT NULL, text2 TEXT NULL, text3 TEXT NULL, text4 TEXT NULL, address TEXT NULL, city TEXT NULL, region TEXT NULL, country TEXT NULL, latitude DECIMAL(8,6) NULL, longitude DECIMAL(9,6) NULL, " +
"CONSTRAINT unq_unitserialmodelid UNIQUE (serial, unitmodelid) " +
" )");
await ExecQueryAsync("CREATE TABLE aunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "serial TEXT NOT NULL, customerid BIGINT NOT NULL REFERENCES acustomer(id), parentunitid BIGINT NULL REFERENCES aunit(id), "
+ "unitmodelid BIGINT NULL REFERENCES aunitmodel(id), unithasownaddress BOOL, boughthere BOOL, purchasedfromvendorid BIGINT NULL REFERENCES avendor(id), "
+ "receipt TEXT NULL, purchaseddate TIMESTAMP NULL, description TEXT NULL, replacedbyunitid BIGINT NULL REFERENCES aunit(id), "
+ "overridemodelwarranty BOOL, warrantylength INTEGER NULL, warrantyterms TEXT NULL, usesbanking BOOL, metered BOOL, lifetimewarranty BOOL, "
+ "text1 TEXT NULL, text2 TEXT NULL, text3 TEXT NULL, text4 TEXT NULL, address TEXT NULL, city TEXT NULL, region TEXT NULL, country TEXT NULL, latitude DECIMAL(8,6) NULL, longitude DECIMAL(9,6) NULL, "
+ "CONSTRAINT unq_unitserialmodelid UNIQUE (serial, unitmodelid) "
+ " )");
//LOANUNIT
await ExecQueryAsync("CREATE TABLE aloanunit (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, " +
"serial TEXT, unitid BIGINT NULL REFERENCES aunit(id), defaultrate INTEGER NOT NULL, " +
"ratehour DECIMAL(19,4) NOT NULL, ratehalfday DECIMAL(19,4) NOT NULL, rateday DECIMAL(19,4) NOT NULL, rateweek DECIMAL(19,4) NOT NULL, ratemonth DECIMAL(19,4) NOT NULL, rateyear DECIMAL(19,4) NOT NULL " +
")");
await ExecQueryAsync("CREATE TABLE aloanunit (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, "
+ "serial TEXT, unitid BIGINT NULL REFERENCES aunit(id), defaultrate INTEGER NOT NULL, "
+ "ratehour DECIMAL(19,4) NOT NULL, ratehalfday DECIMAL(19,4) NOT NULL, rateday DECIMAL(19,4) NOT NULL, rateweek DECIMAL(19,4) NOT NULL, ratemonth DECIMAL(19,4) NOT NULL, rateyear DECIMAL(19,4) NOT NULL "
+ ")");
//----------
//WORKORDER
await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE aworkorder (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE aworkorderitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderid BIGINT NOT NULL REFERENCES aworkorder (id), " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE aworkorderitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderid BIGINT NOT NULL REFERENCES aworkorder (id), "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE aworkorderitemexpense (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemexpense (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemlabor (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemlabor (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemloan (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemloan (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("ALTER TABLE aloanunit ADD column workorderitemloanid BIGINT NULL REFERENCES aworkorderitemloan");
await ExecQueryAsync("CREATE TABLE aworkorderitempart (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitempart (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitempartrequest (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitempartrequest (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("ALTER TABLE apurchaseorderitem ADD column workorderitempartrequestid BIGINT REFERENCES aworkorderitempartrequest");
await ExecQueryAsync("CREATE TABLE aworkorderitemscheduleduser (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemscheduleduser (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemtask (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemtask (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemtravel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemtravel (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), " +
"notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE aworkorderitemunit (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, workorderitemid BIGINT NOT NULL REFERENCES aworkorderitem (id), "
+ "notes TEXT, customfields TEXT, tags VARCHAR(255) ARRAY)");
//----------
//WORKORDERTEMPLATE
await ExecQueryAsync("CREATE TABLE aworkordertemplate (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 )");
await ExecQueryAsync("CREATE TABLE aworkordertemplate (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 )");
await ExecQueryAsync("ALTER TABLE acustomer ADD column defaultservicetemplateid BIGINT NULL REFERENCES aworkordertemplate");
//WORKORDERTEMPLATEITEM
await ExecQueryAsync("CREATE TABLE aworkordertemplateitem (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 )");
await ExecQueryAsync("CREATE TABLE aworkordertemplateitem (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 )");
//QUOTE
await ExecQueryAsync("CREATE TABLE aquote (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE aquote (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
//QUOTEITEM
await ExecQueryAsync("CREATE TABLE aquoteitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, quoteid BIGINT NOT NULL REFERENCES aquote (id), name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE aquoteitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, quoteid BIGINT NOT NULL REFERENCES aquote (id), name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
//QUOTETEMPLATE
await ExecQueryAsync("CREATE TABLE aquotetemplate (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 )");
await ExecQueryAsync("CREATE TABLE aquotetemplate (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 )");
//QUOTETEMPLATEITEM
await ExecQueryAsync("CREATE TABLE aquotetemplateitem (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 )");
await ExecQueryAsync("CREATE TABLE aquotetemplateitem (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 )");
//PM
await ExecQueryAsync("CREATE TABLE apm (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE apm (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, serial BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
//PMITEM
await ExecQueryAsync("CREATE TABLE apmitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, pmid BIGINT NOT NULL REFERENCES apm (id), name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
await ExecQueryAsync("CREATE TABLE apmitem (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, pmid BIGINT NOT NULL REFERENCES apm (id), name TEXT NOT NULL UNIQUE, active BOOL NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY )");
//PMTEMPLATE
await ExecQueryAsync("CREATE TABLE apmtemplate (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 )");
await ExecQueryAsync("CREATE TABLE apmtemplate (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 )");
//PMTEMPLATEITEM
await ExecQueryAsync("CREATE TABLE apmtemplateitem (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 )");
await ExecQueryAsync("CREATE TABLE apmtemplateitem (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 )");
//CUSTOMERSERVICEREQUEST
await ExecQueryAsync("CREATE TABLE acustomerservicerequest (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, " +
"notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, " +
"daterequested TIMESTAMP NOT NULL, customerid BIGINT NOT NULL REFERENCES acustomer(id), unitid BIGINT REFERENCES aunit(id), workorderitemid BIGINT REFERENCES aworkorderitem(id), " +
"requestedbyuserid BIGINT NOT NULL REFERENCES auser(id), customerreferencenumber TEXT, status INTEGER NOT NULL, priority INTEGER NOT NULL " +
")");
await ExecQueryAsync("CREATE TABLE acustomerservicerequest (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT NOT NULL, "
+ "notes TEXT, wiki TEXT, customfields TEXT, tags VARCHAR(255) ARRAY, "
+ "daterequested TIMESTAMP NOT NULL, customerid BIGINT NOT NULL REFERENCES acustomer(id), unitid BIGINT REFERENCES aunit(id), workorderitemid BIGINT REFERENCES aworkorderitem(id), "
+ "requestedbyuserid BIGINT NOT NULL REFERENCES auser(id), customerreferencenumber TEXT, status INTEGER NOT NULL, priority INTEGER NOT NULL "
+ ")");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -880,26 +896,26 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
{
LogUpdateMessage(log);
await ExecQueryAsync("CREATE TABLE anotifysubscription (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
"userid BIGINT NOT NULL REFERENCES auser (id), ayatype INTEGER NOT NULL, eventtype INTEGER NOT NULL, advancenotice interval NOT NULL, " +
"idvalue BIGINT NOT NULL, decvalue DECIMAL(19,4) NOT NULL, agevalue interval NOT NULL, deliverymethod INTEGER NOT NULL, " +
"deliveryaddress TEXT, linkreportid BIGINT NOT NULL, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE anotifysubscription (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "userid BIGINT NOT NULL REFERENCES auser (id), ayatype INTEGER NOT NULL, eventtype INTEGER NOT NULL, advancenotice interval NOT NULL, "
+ "idvalue BIGINT NOT NULL, decvalue DECIMAL(19,4) NOT NULL, agevalue interval NOT NULL, deliverymethod INTEGER NOT NULL, "
+ "deliveryaddress TEXT, linkreportid BIGINT NOT NULL, tags VARCHAR(255) ARRAY)");
await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created TIMESTAMP NOT NULL, " +
"ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, name TEXT NOT NULL, eventtype INTEGER NOT NULL, notifysubscriptionid BIGINT NOT NULL REFERENCES anotifysubscription(id) ON DELETE CASCADE, " +
"userid BIGINT NOT NULL REFERENCES auser (id), eventdate TIMESTAMP NOT NULL, message TEXT)");
await ExecQueryAsync("CREATE TABLE anotifyevent (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, created TIMESTAMP NOT NULL, "
+ "ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, name TEXT NOT NULL, eventtype INTEGER NOT NULL, notifysubscriptionid BIGINT NOT NULL REFERENCES anotifysubscription(id) ON DELETE CASCADE, "
+ "userid BIGINT NOT NULL REFERENCES auser (id), eventdate TIMESTAMP NOT NULL, message TEXT)");
//these fields were in here but seem to not be required so commented out for now, see notifyevent model for deets but
//basically remove this comment once certain don't need these fields (close to release or after)
//idvalue BIGINT NOT NULL, decvalue DECIMAL(19,4) NOT NULL,
await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid BIGINT NOT NULL REFERENCES auser (id), " +
"created TIMESTAMP NOT NULL, ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, name TEXT NOT NULL, eventtype INTEGER NOT NULL, " +
"notifysubscriptionid BIGINT NOT NULL REFERENCES anotifysubscription(id) ON DELETE CASCADE, message TEXT, fetched BOOL NOT NULL)");
await ExecQueryAsync("CREATE TABLE anotification (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, userid BIGINT NOT NULL REFERENCES auser (id), "
+ "created TIMESTAMP NOT NULL, ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, name TEXT NOT NULL, eventtype INTEGER NOT NULL, "
+ "notifysubscriptionid BIGINT NOT NULL REFERENCES anotifysubscription(id) ON DELETE CASCADE, message TEXT, fetched BOOL NOT NULL)");
await ExecQueryAsync("CREATE TABLE anotifydeliverylog (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, processed TIMESTAMP NOT NULL, " +
"ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, eventtype INTEGER NOT NULL, notifysubscriptionid BIGINT NOT NULL, idvalue BIGINT NOT NULL, " +
"decvalue DECIMAL(19,4) NOT NULL, userid BIGINT NOT NULL REFERENCES auser (id), deliverymethod INTEGER NOT NULL, fail BOOL NOT NULL, error TEXT)");
await ExecQueryAsync("CREATE TABLE anotifydeliverylog (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, processed TIMESTAMP NOT NULL, "
+ "ayatype INTEGER NOT NULL, objectid BIGINT NOT NULL, eventtype INTEGER NOT NULL, notifysubscriptionid BIGINT NOT NULL, idvalue BIGINT NOT NULL, "
+ "decvalue DECIMAL(19,4) NOT NULL, userid BIGINT NOT NULL REFERENCES auser (id), deliverymethod INTEGER NOT NULL, fail BOOL NOT NULL, error TEXT)");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -910,8 +926,8 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
{
LogUpdateMessage(log);
await ExecQueryAsync("CREATE TABLE alogo (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, " +
"large bytea, largetype TEXT, medium bytea, mediumtype TEXT, small bytea, smalltype TEXT)");
await ExecQueryAsync("CREATE TABLE alogo (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
+ "large bytea, largetype TEXT, medium bytea, mediumtype TEXT, small bytea, smalltype TEXT)");
await SetSchemaLevelAsync(++currentSchema);
}
@@ -921,10 +937,10 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
if (currentSchema < 14)
{
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, " +
"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(19,4) )");
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, "
+ "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(19,4) )");
await SetSchemaLevelAsync(++currentSchema);
//Load the stock REPORT TEMPLATES