fix #2182 - modifications to address MySQL compatibility issues
This commit is contained in:
parent
b1d6c35e99
commit
345b0bc95f
|
@ -32,6 +32,21 @@ namespace Oqtane.Database.SqlServer
|
|||
return table.Column<int>(name: name, nullable: false).Annotation("SqlServer:Identity", "1, 1");
|
||||
}
|
||||
|
||||
public override void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode, string index)
|
||||
{
|
||||
var elements = index.Split(':', StringSplitOptions.RemoveEmptyEntries);
|
||||
if (elements.Length != 0)
|
||||
{
|
||||
builder.DropIndex(elements[0], table);
|
||||
}
|
||||
builder.AlterColumn<string>(name, table, maxLength: length, nullable: nullable, unicode: unicode);
|
||||
if (elements.Length != 0)
|
||||
{
|
||||
var columns = elements[1].Split(',');
|
||||
builder.CreateIndex(elements[0], table, columns, null, bool.Parse(elements[2]), null);
|
||||
}
|
||||
}
|
||||
|
||||
public override int ExecuteNonQuery(string connectionString, string query)
|
||||
{
|
||||
var conn = new SqlConnection(FormatConnectionString(connectionString));
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Oqtane.Database.Sqlite
|
|||
// not implemented as SQLite does not support dropping columns
|
||||
}
|
||||
|
||||
public override void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode)
|
||||
public override void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode, string index)
|
||||
{
|
||||
// not implemented as SQLite does not support altering columns
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace Oqtane.Databases
|
|||
builder.DropColumn(name, table);
|
||||
}
|
||||
|
||||
public virtual void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode)
|
||||
public virtual void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode, string index)
|
||||
{
|
||||
builder.AlterColumn<string>(RewriteName(name), RewriteName(table), maxLength: length, nullable: nullable, unicode: unicode);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace Oqtane.Databases.Interfaces
|
|||
|
||||
public void DropColumn(MigrationBuilder builder, string name, string table);
|
||||
|
||||
public void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode);
|
||||
public void AlterStringColumn(MigrationBuilder builder, string name, string table, int length, bool nullable, bool unicode, string index);
|
||||
|
||||
public DbContextOptionsBuilder UseDatabase(DbContextOptionsBuilder optionsBuilder, string connectionString);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace Oqtane.Migrations.EntityBuilders
|
|||
|
||||
protected override AspNetUserLoginsEntityBuilder BuildTable(ColumnsBuilder table)
|
||||
{
|
||||
LoginProvider = AddStringColumn(table, "LoginProvider", 450);
|
||||
ProviderKey = AddStringColumn(table, "ProviderKey", 450);
|
||||
LoginProvider = AddStringColumn(table, "LoginProvider", 128);
|
||||
ProviderKey = AddStringColumn(table, "ProviderKey", 128);
|
||||
ProviderDisplayName = AddMaxStringColumn(table, "ProviderDisplayName", true);
|
||||
UserId = AddStringColumn(table, "UserId", 450);
|
||||
return this;
|
||||
|
|
|
@ -187,9 +187,20 @@ namespace Oqtane.Migrations.EntityBuilders
|
|||
return table.Column<decimal>(name: RewriteName(name), nullable: nullable, precision: precision, scale: scale, defaultValue: defaultValue);
|
||||
}
|
||||
|
||||
public void AlterStringColumn(string name, int length, bool nullable = false, bool unicode = true)
|
||||
public void AlterStringColumn(string name, int length, bool nullable = false, bool unicode = true, string index = "")
|
||||
{
|
||||
ActiveDatabase.AlterStringColumn(_migrationBuilder, RewriteName(name), RewriteName(EntityTableName), length, nullable, unicode);
|
||||
if (index != "")
|
||||
{
|
||||
// indexes are in the form IndexName:Column1,Column2:Unique
|
||||
var elements = index.Split(':');
|
||||
index = RewriteName(elements[0]) + ":";
|
||||
foreach (var column in elements[1].Split(','))
|
||||
{
|
||||
index += RewriteName(column) + ",";
|
||||
}
|
||||
index = index.Substring(0, index.Length - 1) + ":" + elements[2];
|
||||
}
|
||||
ActiveDatabase.AlterStringColumn(_migrationBuilder, RewriteName(name), RewriteName(EntityTableName), length, nullable, unicode, index);
|
||||
}
|
||||
|
||||
public void DropColumn(string name)
|
||||
|
|
|
@ -17,21 +17,15 @@ namespace Oqtane.Migrations.Tenant
|
|||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
// Drop the index is needed because the Path is already associated with IX_Folder
|
||||
folderEntityBuilder.DropIndex("IX_Folder");
|
||||
folderEntityBuilder.AlterStringColumn("Name", 256);
|
||||
folderEntityBuilder.AlterStringColumn("Path", 512);
|
||||
folderEntityBuilder.AddIndex("IX_Folder", new[] { "SiteId", "Path" }, true);
|
||||
folderEntityBuilder.AlterStringColumn("Path", 512, false, true, "IX_Folder:SiteId,Path:true");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
// Drop the index is needed because the Path is already associated with IX_Folder
|
||||
folderEntityBuilder.DropIndex("IX_Folder");
|
||||
folderEntityBuilder.AlterStringColumn("Path", 50);
|
||||
folderEntityBuilder.AlterStringColumn("Name", 50);
|
||||
folderEntityBuilder.AddIndex("IX_Folder", new[] { "SiteId", "Path" }, true);
|
||||
folderEntityBuilder.AlterStringColumn("Path", 50, false, true, "IX_Folder:SiteId,Path:true");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,19 +17,13 @@ namespace Oqtane.Migrations.Tenant
|
|||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
// Drop the index is needed because the Name is already associated with IX_File
|
||||
fileEntityBuilder.DropIndex("IX_File");
|
||||
fileEntityBuilder.AlterStringColumn("Name", 256);
|
||||
fileEntityBuilder.AddIndex("IX_File", new[] { "FolderId", "Name" }, true);
|
||||
fileEntityBuilder.AlterStringColumn("Name", 256, false, true, "IX_File:FolderId,Name:true");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
// Drop the index is needed because the Name is already associated with IX_File
|
||||
fileEntityBuilder.DropIndex("IX_File");
|
||||
fileEntityBuilder.AlterStringColumn("Name", 50);
|
||||
fileEntityBuilder.AddIndex("IX_File", new[] { "FolderId", "Name" }, true);
|
||||
fileEntityBuilder.AlterStringColumn("Name", 50, false, true, "IX_File:FolderId,Name:true");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,11 +20,9 @@ namespace Oqtane.Migrations.Tenant
|
|||
visitorEntityBuilder.AlterStringColumn("Url", 2048);
|
||||
|
||||
var urlMappingEntityBuilder = new UrlMappingEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
// Drop the index is needed because the Url is already associated with IX_UrlMapping
|
||||
urlMappingEntityBuilder.DropIndex("IX_UrlMapping");
|
||||
urlMappingEntityBuilder.AlterStringColumn("Url", 2048);
|
||||
urlMappingEntityBuilder.AlterStringColumn("MappedUrl", 2048);
|
||||
urlMappingEntityBuilder.AddIndex("IX_UrlMapping", new[] { "SiteId", "Url" }, true);
|
||||
// Url is an index column and MySQL only supports indexes of 3072 bytes (this index will be 750X4+4=3004 bytes)
|
||||
urlMappingEntityBuilder.AlterStringColumn("Url", 750, false, true, "IX_UrlMapping:SiteId,Url:true");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
|
@ -33,11 +31,8 @@ namespace Oqtane.Migrations.Tenant
|
|||
visitorEntityBuilder.AlterStringColumn("Url", 500);
|
||||
|
||||
var urlMappingEntityBuilder = new UrlMappingEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
// Drop the index is needed because the Url is already associated with IX_UrlMapping
|
||||
urlMappingEntityBuilder.DropIndex("IX_UrlMapping");
|
||||
urlMappingEntityBuilder.AlterStringColumn("Url", 500);
|
||||
urlMappingEntityBuilder.AlterStringColumn("MappedUrl", 500);
|
||||
urlMappingEntityBuilder.AddIndex("IX_UrlMapping", new[] { "SiteId", "Url" }, true);
|
||||
urlMappingEntityBuilder.AlterStringColumn("Url", 500, false, true, "IX_UrlMapping:SiteId,Url:true");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ namespace Oqtane.Repository
|
|||
|
||||
public UrlMapping GetUrlMapping(int siteId, string url)
|
||||
{
|
||||
url = (url.Length > 750) ? url.Substring(0, 750) : url;
|
||||
var urlMapping = _db.UrlMapping.Where(item => item.SiteId == siteId && item.Url == url).FirstOrDefault();
|
||||
if (urlMapping == null)
|
||||
{
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user