case 4212
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -63,7 +63,7 @@
|
||||
"AYANOVA_DB_CONNECTION": "Server=localhost;Username=postgres;Password=raven;Database=AyaNova;CommandTimeout=300;",
|
||||
"AYANOVA_DATA_PATH": "c:\\temp\\ravendata",
|
||||
"AYANOVA_USE_URLS": "http://*:7575;",
|
||||
//"AYANOVA_PERMANENTLY_ERASE_DATABASE":"true",
|
||||
"AYANOVA_PERMANENTLY_ERASE_DATABASE":"true",
|
||||
//"AYANOVA_REMOVE_LICENSE_FROM_DB":"true",
|
||||
//"AYANOVA_REPORT_RENDERING_TIMEOUT":"1",
|
||||
"AYANOVA_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_14\\bin"
|
||||
|
||||
@@ -487,6 +487,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
|
||||
|
||||
//Add user table
|
||||
//!!WARNING: changes here need to be reflected in dbutil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync auser_backup
|
||||
await ExecQueryAsync("CREATE TABLE auser (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, active BOOL NOT NULL, name TEXT NOT NULL UNIQUE, "
|
||||
+ "lastlogin TIMESTAMPTZ, login TEXT NOT NULL UNIQUE, password TEXT NOT NULL, salt TEXT NOT NULL, roles INTEGER NOT NULL, currentauthtoken TEXT, "
|
||||
+ "dlkey TEXT, dlkeyexpire TIMESTAMPTZ, totpsecret TEXT, temptoken TEXT, twofactorenabled BOOL, passwordresetcode TEXT, passwordresetcodeexpire TIMESTAMPTZ, usertype INTEGER NOT NULL, "
|
||||
@@ -495,6 +496,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
|
||||
|
||||
//Add user options table
|
||||
//!!WARNING: changes here need to be reflected in dbutil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync auseroptions_backup
|
||||
await ExecQueryAsync("CREATE TABLE auseroptions (id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "
|
||||
+ "userid BIGINT NOT NULL UNIQUE REFERENCES auser (id) ON DELETE CASCADE, 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, mapurltemplate TEXT, uicolor VARCHAR(12) NOT NULL default '#ffffff')");
|
||||
@@ -1520,6 +1522,7 @@ $BODY$ LANGUAGE PLPGSQL STABLE");
|
||||
{
|
||||
LogUpdateMessage(log);
|
||||
|
||||
//!!WARNING: changes TO AUSER need to be reflected in dbutil::EmptyBizDataFromDatabaseForSeedingOrImportingAsync auser_backup
|
||||
await ExecQueryAsync("ALTER TABLE auser ADD column allowlogin BOOL");
|
||||
await ExecQueryAsync("UPDATE auser SET allowlogin=true WHERE active=true");
|
||||
|
||||
|
||||
@@ -500,6 +500,17 @@ namespace AyaNova.Util
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
//case 4221 truncate support
|
||||
//BACKUP USER AND DATA TO BE PRESERVED THAT TRUNCATE WILL CASCADE DELETE
|
||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||
{
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = "CREATE TABLE auser_backup AS TABLE auser;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
cmd.CommandText = "CREATE TABLE auseroptions_backup AS TABLE auseroptions;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
//REMOVE ALL REMAINING DATA
|
||||
|
||||
await EraseTableAsync("aunitmeterreading", conn);
|
||||
@@ -633,25 +644,48 @@ namespace AyaNova.Util
|
||||
// await EraseTableAsync("XXXXX", conn);
|
||||
|
||||
|
||||
//case 4221 truncate support
|
||||
//COPY BACK USER AND DATA TO BE PRESERVED THAT TRUNCATE WILL CASCADE DELETE
|
||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||
{
|
||||
//AT this point the truncate commands in erasetable above have caused all user and useroptions to be deleted
|
||||
//so no need to clean out those tables, instead put our backup superuser back in again
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = "INSERT INTO auser (active, name, lastlogin, login, password, salt , roles, currentauthtoken, "
|
||||
+ "dlkey, dlkeyexpire, totpsecret, temptoken, twofactorenabled, passwordresetcode, passwordresetcodeexpire, usertype, "
|
||||
+ "employeenumber, notes, wiki, customfields, tags, allowlogin) "
|
||||
+ "SELECT active, name, lastlogin, login, password, salt , roles, currentauthtoken, "
|
||||
+ "dlkey, dlkeyexpire, totpsecret, temptoken, twofactorenabled, passwordresetcode, passwordresetcodeexpire, usertype, "
|
||||
+ "employeenumber, notes, wiki, customfields, tags, allowlogin "
|
||||
+ "FROM auser_backup where id = 1;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
cmd.CommandText = "INSERT INTO auseroptions (userid, translationid, languageoverride, timezoneoverride, "
|
||||
+ "currencyname, hour12, emailaddress, phone1, phone2, phone3, mapurltemplate, uicolor) "
|
||||
+ "SELECT userid, translationid, languageoverride, timezoneoverride, "
|
||||
+ "currencyname, hour12, emailaddress, phone1, phone2, phone3, mapurltemplate, uicolor "
|
||||
+ "FROM auseroptions_backup where userid = 1;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
cmd.CommandText="DROP TABLE IF EXISTS AUSEROPTIONS_BACKUP, AUSER_BACKUP;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
|
||||
//after cleanup
|
||||
//final housekeeping
|
||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||
{
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = "delete from \"auseroptions\" where UserId <> 1;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
cmd.CommandText = "ALTER SEQUENCE auseroptions_id_seq RESTART WITH 2;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
cmd.CommandText = "delete from \"auser\" where id <> 1;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
cmd.CommandText = "ALTER SEQUENCE auser_id_seq RESTART WITH 2;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
//already deleted above no need for this...I think, not sure why it was here
|
||||
// cmd.CommandText = "delete from \"adashboardview\" where userid <> 1;";
|
||||
// await cmd.ExecuteNonQueryAsync();
|
||||
// cmd.CommandText = $"ALTER SEQUENCE adashboardview_id_seq RESTART WITH 2;";
|
||||
// await cmd.ExecuteNonQueryAsync();
|
||||
//Removed for case 4221 handled above
|
||||
// // cmd.CommandText = "delete from \"auseroptions\" where UserId <> 1;";
|
||||
// // await cmd.ExecuteNonQueryAsync();
|
||||
// // cmd.CommandText = "ALTER SEQUENCE auseroptions_id_seq RESTART WITH 2;";
|
||||
// // await cmd.ExecuteNonQueryAsync();
|
||||
// // cmd.CommandText = "delete from \"auser\" where id <> 1;";
|
||||
// // await cmd.ExecuteNonQueryAsync();
|
||||
// // cmd.CommandText = "ALTER SEQUENCE auser_id_seq RESTART WITH 2;";
|
||||
// // await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
cmd.CommandText = "delete from \"apartwarehouse\" where id <> 1;";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
cmd.CommandText = $"ALTER SEQUENCE apartwarehouse_id_seq RESTART WITH 2;";
|
||||
|
||||
Reference in New Issue
Block a user