sql updates #15
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
@@ -13,7 +13,6 @@ namespace timetracker.Data.Migrations
|
|||||||
migrationBuilder.AddColumn<bool>(
|
migrationBuilder.AddColumn<bool>(
|
||||||
name: "IsTenantAdmin",
|
name: "IsTenantAdmin",
|
||||||
table: "Users",
|
table: "Users",
|
||||||
type: "INTEGER",
|
|
||||||
nullable: false,
|
nullable: false,
|
||||||
defaultValue: false);
|
defaultValue: false);
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,44 @@ using (var scope = app.Services.CreateScope())
|
|||||||
}
|
}
|
||||||
|
|
||||||
await db.Database.MigrateAsync();
|
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
|
var forwardedHeadersOptions = new ForwardedHeadersOptions
|
||||||
|
|||||||
Reference in New Issue
Block a user