This commit is contained in:
2020-11-25 17:36:40 +00:00
parent eccefd7a6c
commit fcab7cb1ae

View File

@@ -273,30 +273,15 @@ namespace AyaNova.Util
//Reports
//Logos
//Delete from user options table first
//prepare to delete by removing foreign keys
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;";
cmd.CommandText = "update auser set customerid=null;";
await cmd.ExecuteNonQueryAsync();
}
//Delete users
using (var cmd = new Npgsql.NpgsqlCommand())
{
cmd.Connection = conn;
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 \"adashboardview\" where userid <> 1;";
await cmd.ExecuteNonQueryAsync();
}
//Delete non stock translations
using (var cmd = new Npgsql.NpgsqlCommand())
@@ -324,6 +309,7 @@ namespace AyaNova.Util
await EraseTableAsync("asearchkey", conn);
await EraseTableAsync("asearchdictionary", conn);
await EraseTableAsync("atag", conn);
await EraseTableAsync("acustomernote", conn);
await EraseTableAsync("acustomer", conn);
await EraseTableAsync("acontract", conn);
await EraseTableAsync("aheadoffice", conn);
@@ -365,6 +351,31 @@ namespace AyaNova.Util
await EraseTableAsync("anotifysubscription", conn);
//Delete from user options table first
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();
}
//Delete users
using (var cmd = new Npgsql.NpgsqlCommand())
{
cmd.Connection = conn;
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 \"adashboardview\" where userid <> 1;";
await cmd.ExecuteNonQueryAsync();
}
await conn.CloseAsync();
}