From 59a9f0bf03b339ebc6aec260bba8e2ecb8670dc4 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Mon, 17 Oct 2016 14:34:37 -0700 Subject: [PATCH] Fixing SQL exception during automatic migrations in PostgreSql Fixes #6783 Fixes #7323 --- .../Data/Migration/AutomaticDataMigrations.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs index fb5a3456c41..2c936313a11 100644 --- a/src/Orchard/Data/Migration/AutomaticDataMigrations.cs +++ b/src/Orchard/Data/Migration/AutomaticDataMigrations.cs @@ -80,12 +80,25 @@ public void Terminating() { /// /// This ensures that the framework migrations have run for the distributed locking feature, as existing Orchard installations will not have the required tables when upgrading. /// - private void EnsureDistributedLockSchemaExists() { + private void EnsureDistributedLockSchemaExists() + { // Ensure the distributed lock record schema exists. var schemaBuilder = new SchemaBuilder(_dataMigrationInterpreter); var distributedLockSchemaBuilder = new DistributedLockSchemaBuilder(_shellSettings, schemaBuilder); - if (distributedLockSchemaBuilder.EnsureSchema()) + if (!distributedLockSchemaBuilder.SchemaExists()) + { + + // Workaround to avoid some Transaction issue for PostgreSQL. + if (_shellSettings.DataProvider.Equals("PostgreSql", StringComparison.OrdinalIgnoreCase)) + { + _transactionManager.RequireNew(); + distributedLockSchemaBuilder.CreateSchema(); + return; + } + + distributedLockSchemaBuilder.CreateSchema(); _transactionManager.RequireNew(); + } } } }