mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-08 00:14:31 +08:00
Compare commits
5 Commits
99ce4ca61e
...
feature/un
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4288e7516b | ||
![]() |
1973b183d5 | ||
![]() |
d1ae701154 | ||
![]() |
76e2c8a069 | ||
![]() |
cbbe57d373 |
@@ -111,5 +111,27 @@ namespace Orchard.Core.Settings {
|
||||
|
||||
return 4;
|
||||
}
|
||||
|
||||
public int UpdateFrom4() {
|
||||
SchemaBuilder.AlterTable("ContentFieldDefinitionRecord",
|
||||
table => table.AddUniqueConstraint("UC_CFDR_Name", "Name"));
|
||||
SchemaBuilder.AlterTable("ContentPartDefinitionRecord",
|
||||
table => table.AddUniqueConstraint("UC_CPDR_Name", "Name"));
|
||||
SchemaBuilder.AlterTable("ContentPartFieldDefinitionRecord",
|
||||
table => table.AddUniqueConstraint("UC_CPFDR_CPDRId_Name", "ContentPartDefinitionRecord_Id", "Name"));
|
||||
SchemaBuilder.AlterTable("ContentTypeDefinitionRecord",
|
||||
table => table.AddUniqueConstraint("UC_CTDR_CPDRId", "Name"));
|
||||
SchemaBuilder.AlterTable("ContentTypePartDefinitionRecord",
|
||||
table => table.AddUniqueConstraint("UC_CTPDR_CPDRId_CTDRId", "ContentPartDefinitionRecord_id", "ContentTypeDefinitionRecord_Id"));
|
||||
// TODO: Orchard creates dupes in this table so no can do for now.
|
||||
//SchemaBuilder.AlterTable("ShellFeatureRecord",
|
||||
// table => table.AddUniqueConstraint("UC_SFR_SDRId_Name", "ShellDescriptorRecord_id", "Name"));
|
||||
SchemaBuilder.AlterTable("ShellFeatureStateRecord",
|
||||
table => table.AddUniqueConstraint("UC_SFSR_SSRId_Name", "ShellStateRecord_Id", "Name"));
|
||||
SchemaBuilder.AlterTable("ShellParameterRecord",
|
||||
table => table.AddUniqueConstraint("UC_SPR_SDRId_Component_Name", "ShellDescriptorRecord_id", "Component", "Name"));
|
||||
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
}
|
@@ -92,11 +92,15 @@ namespace Orchard.ImportExport.Services
|
||||
environment.Resolve<ITransactionManager>().RequireNew();
|
||||
|
||||
var schemaBuilder = new SchemaBuilder(environment.Resolve<IDataMigrationInterpreter>());
|
||||
|
||||
schemaBuilder.CreateTable("Orchard_Framework_DataMigrationRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
||||
.Column<string>("DataMigrationClass")
|
||||
.Column<int>("Version"));
|
||||
|
||||
schemaBuilder.AlterTable("Orchard_Framework_DataMigrationRecord",
|
||||
table => table.AddUniqueConstraint("UC_DMR_DataMigrationClass_Version", "DataMigrationClass", "Version"));
|
||||
|
||||
var dataMigrationManager = environment.Resolve<IDataMigrationManager>();
|
||||
dataMigrationManager.Update("Settings");
|
||||
|
||||
|
@@ -146,11 +146,13 @@ namespace Orchard.Setup.Services {
|
||||
// Make a workaround to avoid the Transaction issue for PostgreSQL
|
||||
environment.Resolve<ITransactionManager>().RequireNew();
|
||||
|
||||
schemaBuilder.CreateTable("Orchard_Framework_DataMigrationRecord",
|
||||
table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
||||
.Column<string>("DataMigrationClass")
|
||||
.Column<int>("Version"));
|
||||
schemaBuilder.CreateTable("Orchard_Framework_DataMigrationRecord", table => table
|
||||
.Column<int>("Id", column => column.PrimaryKey().Identity())
|
||||
.Column<string>("DataMigrationClass")
|
||||
.Column<int>("Version"));
|
||||
|
||||
schemaBuilder.AlterTable("Orchard_Framework_DataMigrationRecord",
|
||||
table => table.AddUniqueConstraint("UC_DMR_DataMigrationClass_Version", "DataMigrationClass", "Version"));
|
||||
|
||||
var dataMigrationManager = environment.Resolve<IDataMigrationManager>();
|
||||
dataMigrationManager.Update("Settings");
|
||||
|
@@ -64,5 +64,14 @@ namespace Orchard.ContentManagement.DataMigrations {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public int UpdateFrom3() {
|
||||
SchemaBuilder.AlterTable("ContentItemVersionRecord", table => {
|
||||
table.AddUniqueConstraint("UC_CIVR_CIRId_Number", "ContentItemRecord_id", "Number");
|
||||
table.AddUniqueConstraint("UC_CIVR_CIRId_Published", "ContentItemRecord_id", "Published");
|
||||
table.AddUniqueConstraint("UC_CIVR_CIRId_Latest", "ContentItemRecord_id", "Latest");
|
||||
});
|
||||
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
@@ -125,41 +125,54 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
return;
|
||||
}
|
||||
|
||||
// drop columns
|
||||
// Drop columns.
|
||||
foreach (var dropColumn in command.TableCommands.OfType<DropColumnCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, dropColumn);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// add columns
|
||||
// Add columns.
|
||||
foreach (var addColumn in command.TableCommands.OfType<AddColumnCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, addColumn);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// alter columns
|
||||
// Alter columns.
|
||||
foreach (var alterColumn in command.TableCommands.OfType<AlterColumnCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, alterColumn);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// add index
|
||||
// Add index.
|
||||
foreach (var addIndex in command.TableCommands.OfType<AddIndexCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, addIndex);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// drop index
|
||||
// Drop index.
|
||||
foreach (var dropIndex in command.TableCommands.OfType<DropIndexCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, dropIndex);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// Add unique constraint.
|
||||
foreach (var addUniqueConstraint in command.TableCommands.OfType<AddUniqueConstraintCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, addUniqueConstraint);
|
||||
RunPendingStatements();
|
||||
}
|
||||
|
||||
// Drop unique constraint.
|
||||
foreach (var dropUniqueConstraint in command.TableCommands.OfType<DropUniqueConstraintCommand>()) {
|
||||
var builder = new StringBuilder();
|
||||
Visit(builder, dropUniqueConstraint);
|
||||
RunPendingStatements();
|
||||
}
|
||||
}
|
||||
|
||||
public void Visit(StringBuilder builder, AddColumnCommand command) {
|
||||
@@ -210,7 +223,6 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
|
||||
public void Visit(StringBuilder builder, AddIndexCommand command) {
|
||||
if (ExecuteCustomInterpreter(command)) {
|
||||
return;
|
||||
@@ -235,6 +247,31 @@ namespace Orchard.Data.Migration.Interpreters {
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
public void Visit(StringBuilder builder, AddUniqueConstraintCommand command) {
|
||||
if (ExecuteCustomInterpreter(command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} add constraint {1} unique ({2})",
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(PrefixTableName(command.ConstraintName)),
|
||||
String.Join(", ", command.ColumnNames));
|
||||
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
public void Visit(StringBuilder builder, DropUniqueConstraintCommand command) {
|
||||
if (ExecuteCustomInterpreter(command)) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.AppendFormat("alter table {0} drop constraint {1}",
|
||||
_dialectLazy.Value.QuoteForTableName(PrefixTableName(command.TableName)),
|
||||
_dialectLazy.Value.QuoteForColumnName(PrefixTableName(command.ConstraintName)));
|
||||
|
||||
_sqlStatements.Add(builder.ToString());
|
||||
}
|
||||
|
||||
public override void Visit(SqlStatementCommand command) {
|
||||
if (command.Providers.Count != 0 && !command.Providers.Contains(_shellSettings.DataProvider)) {
|
||||
return;
|
||||
|
@@ -0,0 +1,13 @@
|
||||
namespace Orchard.Data.Migration.Schema {
|
||||
public class AddUniqueConstraintCommand : TableCommand {
|
||||
public string ConstraintName { get; set; }
|
||||
|
||||
public AddUniqueConstraintCommand(string tableName, string constraintName, params string[] columnNames)
|
||||
: base(tableName) {
|
||||
ColumnNames = columnNames;
|
||||
ConstraintName = constraintName;
|
||||
}
|
||||
|
||||
public string[] ColumnNames { get; private set; }
|
||||
}
|
||||
}
|
@@ -47,5 +47,15 @@ namespace Orchard.Data.Migration.Schema {
|
||||
var command = new DropIndexCommand(Name, indexName);
|
||||
TableCommands.Add(command);
|
||||
}
|
||||
|
||||
public void AddUniqueConstraint(string constraintName, params string[] columnNames) {
|
||||
var command = new AddUniqueConstraintCommand(Name, constraintName, columnNames);
|
||||
TableCommands.Add(command);
|
||||
}
|
||||
|
||||
public void DropUniqueConstraint(string constraintName) {
|
||||
var command = new DropUniqueConstraintCommand(Name, constraintName);
|
||||
TableCommands.Add(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,10 @@
|
||||
namespace Orchard.Data.Migration.Schema {
|
||||
public class DropUniqueConstraintCommand : TableCommand {
|
||||
public string ConstraintName { get; set; }
|
||||
|
||||
public DropUniqueConstraintCommand(string tableName, string constraintName)
|
||||
: base(tableName) {
|
||||
ConstraintName = constraintName;
|
||||
}
|
||||
}
|
||||
}
|
@@ -149,6 +149,8 @@
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Data\Migration\Schema\AddUniqueConstraintCommand.cs" />
|
||||
<Compile Include="Data\Migration\Schema\DropUniqueConstraintCommand.cs" />
|
||||
<Compile Include="Environment\Extensions\Helpers\ExtensionManagerExtensions.cs" />
|
||||
<Compile Include="Environment\Extensions\Models\LifecycleStatus.cs" />
|
||||
<Compile Include="Mvc\Updater.cs" />
|
||||
|
Reference in New Issue
Block a user