sql updates
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace timetracker.Data.Migrations
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsTenantAdmin",
|
||||
table: "Users",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
|
||||
@@ -195,6 +195,44 @@ using (var scope = app.Services.CreateScope())
|
||||
}
|
||||
|
||||
await db.Database.MigrateAsync();
|
||||
|
||||
if (dbProvider.Equals("PostgreSQL", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
var conn = db.Database.GetDbConnection();
|
||||
if (conn.State != System.Data.ConnectionState.Open)
|
||||
{
|
||||
await conn.OpenAsync();
|
||||
}
|
||||
|
||||
// Check if column IsTenantAdmin in Users table is of type integer
|
||||
using (var cmdCheckType = conn.CreateCommand())
|
||||
{
|
||||
cmdCheckType.CommandText = @"
|
||||
SELECT data_type
|
||||
FROM information_schema.columns
|
||||
WHERE table_name = 'Users' AND column_name = 'IsTenantAdmin';";
|
||||
var dataType = await cmdCheckType.ExecuteScalarAsync() as string;
|
||||
if (dataType != null && dataType.Equals("integer", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// Alter the column type to boolean
|
||||
using (var cmdAlterType = conn.CreateCommand())
|
||||
{
|
||||
cmdAlterType.CommandText = @"
|
||||
ALTER TABLE ""Users""
|
||||
ALTER COLUMN ""IsTenantAdmin"" TYPE boolean
|
||||
USING (""IsTenantAdmin"" <> 0);";
|
||||
await cmdAlterType.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Fehler beim Konvertieren der IsTenantAdmin-Spalte in PostgreSQL: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var forwardedHeadersOptions = new ForwardedHeadersOptions
|
||||
|
||||
Reference in New Issue
Block a user