Properly erase db without fucking things up
This commit is contained in:
@@ -289,28 +289,33 @@ namespace AyaNova.Util
|
|||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Delete non stock translations
|
||||||
|
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||||
|
{
|
||||||
|
cmd.Connection = conn;
|
||||||
|
|
||||||
|
//set to default translation so can delete all non default ones
|
||||||
|
cmd.CommandText = "update auseroptions set translationid=1;";
|
||||||
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
//REMOVE ALL DATA with few exceptions of manager user, license, schema tables
|
cmd.CommandText = "delete from atranslationitem where translationid > 4;";
|
||||||
//and job logs because this is called by job code
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
await EraseTableAsync("atranslationitem", conn);
|
|
||||||
await EraseTableAsync("atranslation", conn);
|
|
||||||
//Load the default TRANSLATIONS
|
|
||||||
await AyaNova.Biz.PrimeData.PrimeTranslations();
|
|
||||||
|
|
||||||
|
cmd.CommandText = "delete from atranslation where id > 4;";
|
||||||
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
//REMOVE ALL REMAINING DATA
|
||||||
await EraseTableAsync("afileattachment", conn);
|
await EraseTableAsync("afileattachment", conn);
|
||||||
await EraseTableAsync("awidget", conn);
|
await EraseTableAsync("awidget", conn);
|
||||||
await EraseTableAsync("aevent", conn);
|
await EraseTableAsync("aevent", conn);
|
||||||
await EraseTableAsync("adatalistview", conn);
|
await EraseTableAsync("adatalistview", conn);
|
||||||
await EraseTableAsync("apicklisttemplate", conn);
|
await EraseTableAsync("apicklisttemplate", conn, true);
|
||||||
await EraseTableAsync("aformcustom", conn);
|
await EraseTableAsync("aformcustom", conn);
|
||||||
await EraseTableAsync("asearchkey", conn);
|
await EraseTableAsync("asearchkey", conn);
|
||||||
await EraseTableAsync("asearchdictionary", conn);
|
await EraseTableAsync("asearchdictionary", conn);
|
||||||
await EraseTableAsync("atag", conn);
|
await EraseTableAsync("atag", conn);
|
||||||
//CUSTOMER
|
|
||||||
await EraseTableAsync("acustomer", conn);
|
await EraseTableAsync("acustomer", conn);
|
||||||
|
|
||||||
await EraseTableAsync("acontract", conn);
|
await EraseTableAsync("acontract", conn);
|
||||||
await EraseTableAsync("aheadoffice", conn);
|
await EraseTableAsync("aheadoffice", conn);
|
||||||
await EraseTableAsync("aloanunit", conn);
|
await EraseTableAsync("aloanunit", conn);
|
||||||
@@ -332,8 +337,6 @@ namespace AyaNova.Util
|
|||||||
await EraseTableAsync("aworkorderitem", conn);
|
await EraseTableAsync("aworkorderitem", conn);
|
||||||
await EraseTableAsync("aworkordertemplate", conn);
|
await EraseTableAsync("aworkordertemplate", conn);
|
||||||
await EraseTableAsync("aworkordertemplateitem", conn);
|
await EraseTableAsync("aworkordertemplateitem", conn);
|
||||||
|
|
||||||
|
|
||||||
await conn.CloseAsync();
|
await conn.CloseAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,13 +351,23 @@ namespace AyaNova.Util
|
|||||||
///////////////////////////////////////////
|
///////////////////////////////////////////
|
||||||
// Erase all data from the table specified
|
// Erase all data from the table specified
|
||||||
//
|
//
|
||||||
private static async Task EraseTableAsync(string sTable, Npgsql.NpgsqlConnection conn)
|
private static async Task EraseTableAsync(string sTable, Npgsql.NpgsqlConnection conn, bool tableHasNoSequence = false)
|
||||||
{
|
{
|
||||||
using (var cmd = new Npgsql.NpgsqlCommand())
|
using (var cmd = new Npgsql.NpgsqlCommand())
|
||||||
{
|
{
|
||||||
cmd.Connection = conn;
|
cmd.Connection = conn;
|
||||||
cmd.CommandText = "TRUNCATE \"" + sTable + "\" RESTART IDENTITY;";
|
//Boo! Can't do this becuase it will fail if there is a foreign key which nearly all tables have unless cascade option is used
|
||||||
|
//but then cascade causes things to delete in any referenced table
|
||||||
|
// cmd.CommandText = "TRUNCATE \"" + sTable + "\" RESTART IDENTITY;";
|
||||||
|
|
||||||
|
cmd.CommandText = $"delete from {sTable};";
|
||||||
await cmd.ExecuteNonQueryAsync();
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
if (!tableHasNoSequence)
|
||||||
|
{
|
||||||
|
cmd.CommandText = $"ALTER SEQUENCE {sTable}_id_seq RESTART WITH 1;";
|
||||||
|
await cmd.ExecuteNonQueryAsync();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user