Re-add EnsureExists signature to fix compat with old plugins
Fixes #862
This commit is contained in:
parent
0adcf32e3f
commit
04145a4aca
11 changed files with 33 additions and 11 deletions
24
TShockAPI/DB/SqlTable.cs
Normal file → Executable file
24
TShockAPI/DB/SqlTable.cs
Normal file → Executable file
|
|
@ -53,7 +53,7 @@ namespace TShockAPI.DB
|
|||
}
|
||||
|
||||
// Returns true if the table was created; false if it was not.
|
||||
public bool EnsureExists(SqlTable table)
|
||||
public bool EnsureTableStructure(SqlTable table)
|
||||
{
|
||||
var columns = GetColumns(table);
|
||||
if (columns.Count > 0)
|
||||
|
|
@ -72,6 +72,28 @@ namespace TShockAPI.DB
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures a table exists and that its structure is correct
|
||||
/// </summary>
|
||||
/// <param name="table">The table name</param>
|
||||
[Obsolete("This method will be replaced by EnsureTableExists.")]
|
||||
public void EnsureExists(SqlTable table)
|
||||
{
|
||||
var columns = GetColumns(table);
|
||||
if (columns.Count > 0)
|
||||
{
|
||||
if (!table.Columns.All(c => columns.Contains(c.Name)) || !columns.All(c => table.Columns.Any(c2 => c2.Name == c)))
|
||||
{
|
||||
var from = new SqlTable(table.Name, columns.Select(s => new SqlColumn(s, MySqlDbType.String)).ToList());
|
||||
database.Query(creator.AlterTable(from, table));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
database.Query(creator.CreateTable(table));
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> GetColumns(SqlTable table)
|
||||
{
|
||||
var ret = new List<string>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue