Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4855 - dropping required column causes issue on SQLite #4857

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Oqtane.Server/Migrations/Tenant/06000101_AddLanguageName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Oqtane.Databases.Interfaces;
using Oqtane.Migrations.EntityBuilders;
using Oqtane.Repository;

namespace Oqtane.Migrations.Tenant
{
[DbContext(typeof(TenantDBContext))]
[Migration("Tenant.06.00.01.01")]
public class AddLanguageName : MultiDatabaseMigration
{
public AddLanguageName(IDatabase database) : base(database)
{
}

protected override void Up(MigrationBuilder migrationBuilder)
{
// Name column was removed in 5.2.4 however SQLite does not support column removal so it had to be restored
if (ActiveDatabase.Name != "Sqlite")
{
var languageEntityBuilder = new LanguageEntityBuilder(migrationBuilder, ActiveDatabase);
languageEntityBuilder.AddStringColumn("Name", 100, true);
}
}

protected override void Down(MigrationBuilder migrationBuilder)
{
// not implemented
}
}
}
3 changes: 2 additions & 1 deletion Oqtane.Server/Repository/LanguageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Language AddLanguage(Language language)
.ToList()
.ForEach(l => l.IsDefault = false);
}

language.Name = ""; // stored in database but not used (SQLite limitation)
db.Language.Add(language);
db.SaveChanges();

Expand All @@ -55,6 +55,7 @@ public void UpdateLanguage(Language language)
.ForEach(l => l.IsDefault = false);
}

language.Name = ""; // stored in database but not used (SQLite limitation)
db.SaveChanges();
}

Expand Down
4 changes: 3 additions & 1 deletion Oqtane.Shared/Models/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public class File : ModelBase
public string Description { get; set; }

/// <summary>
/// Deprecated - not used
/// Deprecated
/// Note that this property still exists in the database because columns cannot be dropped in SQLite
/// Therefore the property must be retained/mapped even though the framework no longer uses it
/// </summary>
public bool? IsDeleted { get; set; }

Expand Down
4 changes: 3 additions & 1 deletion Oqtane.Shared/Models/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public class Folder : ModelBase
public bool IsSystem { get; set; }

/// <summary>
/// Deprecated - not used
/// Deprecated
/// Note that this property still exists in the database because columns cannot be dropped in SQLite
/// Therefore the property must be retained/mapped even though the framework no longer uses it
/// </summary>
public bool? IsDeleted { get; set; }

Expand Down
3 changes: 2 additions & 1 deletion Oqtane.Shared/Models/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public class Language : ModelBase
/// </summary>
public bool IsDefault { get; set; }

[NotMapped]
/// <summary>
/// Language Name - corresponds to <see cref="Culture.DisplayName"/>, _not_ <see cref="Culture.Name"/>
/// Note that this property still exists in the database because columns cannot be dropped in SQLite
/// Therefore the property must be retained/mapped even though the framework populates it from the Culture API
/// </summary>
public string Name { get; set; }

Expand Down