Skip to content

Commit

Permalink
add stupid check of table scheme :|
Browse files Browse the repository at this point in the history
  • Loading branch information
DiFFoZ committed May 8, 2021
1 parent d6e9091 commit ffbc12b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Kits/Databases/MySqlKitDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,22 @@ public async Task LoadDatabaseAsync()
command.CommandText = $"SHOW TABLES LIKE '{TableName}';";
if (await command.ExecuteScalarAsync() != null)
{
// FIXME: :|
command.CommandText = $"SELECT * FROM `{TableName}` LIMIT 0;";
var reader = await command.ExecuteReaderAsync();
var schema = await reader.GetColumnSchemaAsync();
if (schema[0].ColumnName.Equals("id", StringComparison.OrdinalIgnoreCase))
{
return;
}

command.CommandText = $@"ALTER TABLE `{TableName}`
ADD COLUMN IF NOT EXISTS `Id` INT(11) NOT NULL AUTO_INCREMENT FIRST,
ADD COLUMN `Id` INT(11) NOT NULL AUTO_INCREMENT FIRST,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`Id`);";

await command.ExecuteNonQueryAsync();

return;
}

Expand Down

0 comments on commit ffbc12b

Please # to comment.