From d96c9a77cfe7dd8bdfe87220a0a606f70dcb40de Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Mon, 22 Aug 2022 15:48:17 +0200 Subject: [PATCH] Better exception message when using ALTER TABLE and SQLite (#12848) * Added NotSupportedException when using Alter Table and SQLite. This is considered better than the underlying sql error. * use Environment.NewLine --- .../Expressions/Alter/Table/AlterTableBuilder.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/Migrations/Expressions/Alter/Table/AlterTableBuilder.cs b/src/Umbraco.Infrastructure/Migrations/Expressions/Alter/Table/AlterTableBuilder.cs index 3dc5483266..fd9dee6745 100644 --- a/src/Umbraco.Infrastructure/Migrations/Expressions/Alter/Table/AlterTableBuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/Expressions/Alter/Table/AlterTableBuilder.cs @@ -2,6 +2,7 @@ using System.Data; using Umbraco.Cms.Infrastructure.Migrations.Expressions.Alter.Expressions; using Umbraco.Cms.Infrastructure.Migrations.Expressions.Common.Expressions; using Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Expressions; +using Umbraco.Cms.Infrastructure.Persistence; using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; using Umbraco.Cms.Infrastructure.Persistence.DatabaseModelDefinitions; @@ -21,7 +22,14 @@ public class AlterTableBuilder : ExpressionBuilderBase Expression.Execute(); + public void Do() + { + if (_context.Database.DatabaseType.IsSqlite()) + { + throw new NotSupportedException($"SQLite do not support ALTER TABLE operations.Instead you will have to:{Environment.NewLine}1. Create a temp table.{Environment.NewLine}2. Copy data from existing table into temp table.{Environment.NewLine}3. Delete existing table.{Environment.NewLine}4. Create new table with existing name but new signature{Environment.NewLine}5. Copy data from temp table into the new table.{Environment.NewLine}6. Delete temp table."); + } + Expression.Execute(); + } public IAlterTableColumnOptionBuilder WithDefault(SystemMethods method) {