mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Increased field storage size
- Ensure AlterColumn defines the field Type if the size is changed --HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Data;
|
using System;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Autofac;
|
using Autofac;
|
||||||
using NHibernate;
|
using NHibernate;
|
||||||
@@ -37,8 +38,6 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
|
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
|
|
||||||
builder.RegisterInstance(new ShellSettings { DataTablePrefix = "TEST_", DataProvider = "SqlCe" });
|
|
||||||
|
|
||||||
var session = _sessionFactory.OpenSession();
|
var session = _sessionFactory.OpenSession();
|
||||||
builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
|
builder.RegisterInstance(appDataFolder).As<IAppDataFolder>();
|
||||||
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
|
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
|
||||||
@@ -49,7 +48,7 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
|
builder.RegisterType<SessionFactoryHolder>().As<ISessionFactoryHolder>();
|
||||||
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(session)).As<ISessionLocator>();
|
builder.RegisterInstance(new DefaultContentManagerTests.TestSessionLocator(session)).As<ISessionLocator>();
|
||||||
builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty<RecordBlueprint>() }).As<ShellBlueprint>();
|
builder.RegisterInstance(new ShellBlueprint { Records = Enumerable.Empty<RecordBlueprint>() }).As<ShellBlueprint>();
|
||||||
builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST_" }).As<ShellSettings>();
|
builder.RegisterInstance(new ShellSettings { Name = "temp", DataProvider = "SqlCe", DataTablePrefix = "TEST" }).As<ShellSettings>();
|
||||||
builder.RegisterModule(new DataModule());
|
builder.RegisterModule(new DataModule());
|
||||||
_container = builder.Build();
|
_container = builder.Build();
|
||||||
|
|
||||||
@@ -154,6 +153,61 @@ namespace Orchard.Tests.DataMigration {
|
|||||||
.Column("UserId", DbType.Int32, column => column.NotNull()))
|
.Column("UserId", DbType.Int32, column => column.NotNull()))
|
||||||
.CreateForeignKey("FK_User", "Address", new[] { "UserId" }, "User", new[] { "Id" })
|
.CreateForeignKey("FK_User", "Address", new[] { "UserId" }, "User", new[] { "Id" })
|
||||||
.DropForeignKey("Address", "FK_User");
|
.DropForeignKey("Address", "FK_User");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, ExpectedException]
|
||||||
|
public void BiggerDataShouldNotFit() {
|
||||||
|
_schemaBuilder
|
||||||
|
.CreateTable("ContentItemRecord", table => table
|
||||||
|
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
|
||||||
|
.Column("Data", DbType.String, column => column.WithLength(255)));
|
||||||
|
|
||||||
|
// should write successfully less than 255 chars
|
||||||
|
_schemaBuilder
|
||||||
|
.ExecuteSql("insert into TEST_ContentItemRecord (Data) values('Hello World')");
|
||||||
|
|
||||||
|
// should throw an exception if trying to write more data
|
||||||
|
_schemaBuilder
|
||||||
|
.ExecuteSql(String.Format("insert into TEST_ContentItemRecord (Data) values('{0}')", new String('x', 256)));
|
||||||
|
|
||||||
|
_schemaBuilder
|
||||||
|
.AlterTable("ContentItemRecord", table => table
|
||||||
|
.AlterColumn("Data", column => column.WithType(DbType.String).WithLength(257)));
|
||||||
|
|
||||||
|
_schemaBuilder
|
||||||
|
.ExecuteSql(String.Format("insert into TEST_ContentItemRecord (Data) values('{0}')", new String('x', 256)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ShouldAllowFieldSizeAlteration() {
|
||||||
|
_schemaBuilder
|
||||||
|
.CreateTable("ContentItemRecord", table => table
|
||||||
|
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
|
||||||
|
.Column("Data", DbType.String, column => column.WithLength(255)));
|
||||||
|
|
||||||
|
// should write successfully less than 255 chars
|
||||||
|
_schemaBuilder
|
||||||
|
.ExecuteSql("insert into TEST_ContentItemRecord (Data) values('Hello World')");
|
||||||
|
|
||||||
|
_schemaBuilder
|
||||||
|
.AlterTable("ContentItemRecord", table => table
|
||||||
|
.AlterColumn("Data", column => column.WithType(DbType.String).WithLength(2048)));
|
||||||
|
|
||||||
|
// should write successfully a bigger value now
|
||||||
|
_schemaBuilder
|
||||||
|
.ExecuteSql(String.Format("insert into TEST_ContentItemRecord (Data) values('{0}')", new String('x', 2048)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, ExpectedException(typeof(OrchardException))]
|
||||||
|
public void ChangingSizeWithoutTypeShouldNotBeAllowed() {
|
||||||
|
_schemaBuilder
|
||||||
|
.CreateTable("ContentItemRecord", table => table
|
||||||
|
.Column("Id", DbType.Int32, column => column.PrimaryKey().Identity())
|
||||||
|
.Column("Data", DbType.String, column => column.WithLength(255)));
|
||||||
|
|
||||||
|
_schemaBuilder
|
||||||
|
.AlterTable("ContentItemRecord", table => table
|
||||||
|
.AlterColumn("Data", column => column.WithLength(2048)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
using Orchard.Data.Migration;
|
using System.Data;
|
||||||
|
using Orchard.Data.Migration;
|
||||||
|
|
||||||
namespace Orchard.ContentManagement.DataMigrations {
|
namespace Orchard.ContentManagement.DataMigrations {
|
||||||
public class FrameworkDataMigration : DataMigrationImpl {
|
public class FrameworkDataMigration : DataMigrationImpl {
|
||||||
@@ -35,5 +36,13 @@ namespace Orchard.ContentManagement.DataMigrations {
|
|||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int UpdateFrom1() {
|
||||||
|
SchemaBuilder
|
||||||
|
.AlterTable("ContentItemRecord", table => table
|
||||||
|
.AlterColumn("Data", column => column.WithType(DbType.String).Unlimited()));
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -39,7 +39,7 @@ namespace Orchard.Data.Migration.Interpreters {
|
|||||||
_reportsCoordinator = reportsCoordinator;
|
_reportsCoordinator = reportsCoordinator;
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
var configuration = _sessionFactoryHolder.GetConfiguration();
|
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||||
_dialect = Dialect.GetDialect(configuration.Properties);
|
_dialect = Dialect.GetDialect(configuration.Properties);
|
||||||
}
|
}
|
||||||
@@ -192,6 +192,11 @@ namespace Orchard.Data.Migration.Interpreters {
|
|||||||
if (command.DbType != DbType.Object) {
|
if (command.DbType != DbType.Object) {
|
||||||
builder.Append(GetTypeName(command.DbType, command.Length, command.Precision, command.Scale));
|
builder.Append(GetTypeName(command.DbType, command.Length, command.Precision, command.Scale));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if(command.Length > 0 || command.Precision > 0 || command.Scale > 0) {
|
||||||
|
throw new OrchardException(T("Error while executing data migration: you need to specify the field's type in order to change it's properies"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// [default value]
|
// [default value]
|
||||||
if (!string.IsNullOrEmpty(command.Default)) {
|
if (!string.IsNullOrEmpty(command.Default)) {
|
||||||
|
Reference in New Issue
Block a user