Compare commits
4 Commits
108-add-re
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b88bd1960 | ||
| 1aa2476779 | |||
|
|
7ed144bc39 | ||
| 3b42a73b73 |
@@ -226,6 +226,53 @@ public class SQLHelper:IDisposable
|
|||||||
Thread.Sleep(sleepTime);
|
Thread.Sleep(sleepTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public async Task ExecuteInTransactionAsync(Func<MySqlConnection, DbTransaction, Task> operation)
|
||||||
|
{
|
||||||
|
var poolElement = await GetMySqlConnectionPoolElement();
|
||||||
|
var connection = poolElement.Connection;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await operation(connection, transaction);
|
||||||
|
await transaction.CommitAsync();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
await transaction.RollbackAsync();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
poolElement.Semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExecuteInTransaction(Action<MySqlConnection, MySqlTransaction> operation)
|
||||||
|
{
|
||||||
|
var poolElement = GetMySqlConnectionPoolElement().Result;
|
||||||
|
var connection = poolElement.Connection;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var transaction = connection.BeginTransaction();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
operation(connection, transaction);
|
||||||
|
transaction.Commit();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
poolElement.Semaphore.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct MySqlConnectionPoolElement
|
public struct MySqlConnectionPoolElement
|
||||||
|
|||||||
@@ -29,14 +29,10 @@ public static class DatabaseMigrations
|
|||||||
if (version >= databaseVersion)
|
if (version >= databaseVersion)
|
||||||
{
|
{
|
||||||
databaseVersion = (int)method.Invoke(null, new object[] { helper });
|
databaseVersion = (int)method.Invoke(null, new object[] { helper });
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (databaseVersion != initialDatabaseVersion)
|
|
||||||
{
|
|
||||||
var _ = helper.ExecuteSQLNonQuery("UPDATE settings SET value = @databaseVersion", new() { ["databaseVersion"] = databaseVersion.ToString() }).Result;
|
var _ = helper.ExecuteSQLNonQuery("UPDATE settings SET value = @databaseVersion", new() { ["databaseVersion"] = databaseVersion.ToString() }).Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int DatabaseGetVersion(SQLHelper helper)
|
public static int DatabaseGetVersion(SQLHelper helper)
|
||||||
{
|
{
|
||||||
@@ -122,25 +118,41 @@ public static class DatabaseMigrations
|
|||||||
{
|
{
|
||||||
// Add id_entity to embedding
|
// Add id_entity to embedding
|
||||||
var _ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding ADD COLUMN id_entity INT NULL", []).Result;
|
var _ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding ADD COLUMN id_entity INT NULL", []).Result;
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
public static int UpdateFrom6(SQLHelper helper)
|
||||||
|
{
|
||||||
int count;
|
int count;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
count = helper.ExecuteSQLNonQuery("UPDATE embedding e JOIN datapoint d ON d.id = e.id_datapoint JOIN (SELECT id FROM embedding WHERE id_entity IS NULL LIMIT 10000) x on x.id = e.id SET e.id_entity = d.id_entity;", []).Result;
|
count = helper.ExecuteSQLNonQuery("UPDATE embedding e JOIN datapoint d ON d.id = e.id_datapoint JOIN (SELECT id FROM embedding WHERE id_entity IS NULL LIMIT 10000) x on x.id = e.id SET e.id_entity = d.id_entity;", []).Result;
|
||||||
} while (count == 10000);
|
} while (count == 10000);
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
public static int UpdateFrom7(SQLHelper helper)
|
||||||
|
{
|
||||||
_ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding MODIFY id_entity INT NOT NULL;", []).Result;
|
_ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding MODIFY id_entity INT NOT NULL;", []).Result;
|
||||||
_ = helper.ExecuteSQLNonQuery("CREATE INDEX idx_embedding_entity_model ON embedding (id_entity, model)", []).Result;
|
_ = helper.ExecuteSQLNonQuery("CREATE INDEX idx_embedding_entity_model ON embedding (id_entity, model)", []).Result;
|
||||||
|
|
||||||
// Add id_searchdomain to embedding
|
// Add id_searchdomain to embedding
|
||||||
_ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding ADD COLUMN id_searchdomain INT NULL", []).Result;
|
_ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding ADD COLUMN id_searchdomain INT NULL", []).Result;
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int UpdateFrom8(SQLHelper helper)
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
count = helper.ExecuteSQLNonQuery("UPDATE embedding e JOIN entity en ON en.id = e.id_datapoint JOIN (SELECT id FROM embedding WHERE id_searchdomain IS NULL LIMIT 10000) x on x.id = e.id SET e.id_searchdomain = en.id_searchdomain;", []).Result;
|
count = helper.ExecuteSQLNonQuery("UPDATE embedding e JOIN entity en ON en.id = e.id_entity JOIN (SELECT id FROM embedding WHERE id_searchdomain IS NULL LIMIT 10000) x on x.id = e.id SET e.id_searchdomain = en.id_searchdomain;", []).Result;
|
||||||
} while (count == 10000);
|
} while (count == 10000);
|
||||||
|
return 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int UpdateFrom9(SQLHelper helper)
|
||||||
|
{
|
||||||
_ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding MODIFY id_searchdomain INT NOT NULL;", []).Result;
|
_ = helper.ExecuteSQLNonQuery("ALTER TABLE embedding MODIFY id_searchdomain INT NOT NULL;", []).Result;
|
||||||
_ = helper.ExecuteSQLNonQuery("CREATE INDEX idx_embedding_searchdomain_model ON embedding (id_searchdomain)", []).Result;
|
_ = helper.ExecuteSQLNonQuery("CREATE INDEX idx_embedding_searchdomain_model ON embedding (id_searchdomain)", []).Result;
|
||||||
|
return 10;
|
||||||
return 6;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user