moved AlterStringColumn to IDatabase interface so that it can be overridden in the Sqlite provider rather than requiring conditional logic in the migrations
This commit is contained in:
		@ -109,7 +109,7 @@ namespace Oqtane.Migrations.EntityBuilders
 | 
			
		||||
 | 
			
		||||
        public void AlterStringColumn(string name, int length, bool nullable = false, bool unicode = true)
 | 
			
		||||
        {
 | 
			
		||||
            _migrationBuilder.AlterColumn<string>(RewriteName(name), RewriteName(EntityTableName), maxLength: length, nullable: nullable, unicode: unicode);
 | 
			
		||||
            ActiveDatabase.AlterStringColumn(_migrationBuilder, RewriteName(name), RewriteName(EntityTableName), length, nullable, unicode);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void AddDecimalColumn(string name, int precision, int scale, bool nullable = false)
 | 
			
		||||
 | 
			
		||||
@ -16,33 +16,22 @@ namespace Oqtane.Migrations.Tenant
 | 
			
		||||
 | 
			
		||||
        protected override void Up(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            if (ActiveDatabase.Name != "Sqlite")
 | 
			
		||||
            {
 | 
			
		||||
                var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
 | 
			
		||||
                folderEntityBuilder.AlterStringColumn("Name", 256);
 | 
			
		||||
 | 
			
		||||
                // Drop the index is needed because the Path is already associated with IX_Folder
 | 
			
		||||
                folderEntityBuilder.DropForeignKey("FK_Folder_Site");
 | 
			
		||||
                folderEntityBuilder.DropIndex("IX_Folder");
 | 
			
		||||
                folderEntityBuilder.AlterStringColumn("Path", 512);
 | 
			
		||||
                folderEntityBuilder.AddIndex("IX_Folder", new[] { "SiteId", "Path" }, true);
 | 
			
		||||
                folderEntityBuilder.AddForeignKey("FK_Folder_Site");
 | 
			
		||||
            }
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            if (ActiveDatabase.Name != "Sqlite")
 | 
			
		||||
            {
 | 
			
		||||
                var folderEntityBuilder = new FolderEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
 | 
			
		||||
                folderEntityBuilder.AlterStringColumn("Name", 50);
 | 
			
		||||
 | 
			
		||||
                folderEntityBuilder.DropIndex("IX_Folder");
 | 
			
		||||
                folderEntityBuilder.AlterStringColumn("Path", 50);
 | 
			
		||||
                folderEntityBuilder.AddIndex("IX_Folder", new[] { "SiteId", "Path" }, true);
 | 
			
		||||
            }
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,29 +16,20 @@ namespace Oqtane.Migrations.Tenant
 | 
			
		||||
 | 
			
		||||
        protected override void Up(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            if (ActiveDatabase.Name != "Sqlite")
 | 
			
		||||
            {
 | 
			
		||||
                var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
 | 
			
		||||
                // Drop the index is needed because the Name is already associated with IX_File
 | 
			
		||||
                fileEntityBuilder.DropForeignKey("FK_File_Folder");
 | 
			
		||||
                fileEntityBuilder.DropIndex("IX_File");
 | 
			
		||||
                fileEntityBuilder.AlterStringColumn("Name", 256);
 | 
			
		||||
                fileEntityBuilder.AddIndex("IX_File", new[] { "FolderId", "Name" }, true);
 | 
			
		||||
                fileEntityBuilder.AddForeignKey("FK_File_Folder");
 | 
			
		||||
            }
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            if (ActiveDatabase.Name != "Sqlite")
 | 
			
		||||
            {
 | 
			
		||||
                var fileEntityBuilder = new FileEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
 | 
			
		||||
                fileEntityBuilder.DropIndex("IX_File");
 | 
			
		||||
                fileEntityBuilder.AlterStringColumn("Name", 50);
 | 
			
		||||
                fileEntityBuilder.AddIndex("IX_File", new[] { "FolderId", "Name" }, true);
 | 
			
		||||
            }
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -16,37 +16,28 @@ namespace Oqtane.Migrations.Tenant
 | 
			
		||||
 | 
			
		||||
        protected override void Up(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            if (ActiveDatabase.Name != "Sqlite")
 | 
			
		||||
            {
 | 
			
		||||
                var visitorEntityBuilder = new VisitorEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
                visitorEntityBuilder.AlterStringColumn("Url", 2048);
 | 
			
		||||
            var visitorEntityBuilder = new VisitorEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
            visitorEntityBuilder.AlterStringColumn("Url", 2048);
 | 
			
		||||
 | 
			
		||||
                // Drop the index is needed because the Url is already associated with IX_UrlMapping
 | 
			
		||||
                var urlMappingEntityBuilder = new UrlMappingEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
                urlMappingEntityBuilder.DropForeignKey("FK_UrlMapping_Site");
 | 
			
		||||
                urlMappingEntityBuilder.DropIndex("IX_UrlMapping");
 | 
			
		||||
                urlMappingEntityBuilder.AlterStringColumn("Url", 2048);
 | 
			
		||||
                urlMappingEntityBuilder.AlterStringColumn("MappedUrl", 2048);
 | 
			
		||||
                urlMappingEntityBuilder.AddIndex("IX_UrlMapping", new[] { "SiteId", "Url" }, true);
 | 
			
		||||
                urlMappingEntityBuilder.AddForeignKey("FK_UrlMapping_Site");
 | 
			
		||||
            }
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected override void Down(MigrationBuilder migrationBuilder)
 | 
			
		||||
        {
 | 
			
		||||
            if (ActiveDatabase.Name != "Sqlite")
 | 
			
		||||
            {
 | 
			
		||||
                var visitorEntityBuilder = new VisitorEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
                visitorEntityBuilder.AlterStringColumn("Url", 500);
 | 
			
		||||
            var visitorEntityBuilder = new VisitorEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
            visitorEntityBuilder.AlterStringColumn("Url", 500);
 | 
			
		||||
 | 
			
		||||
                var urlMappingEntityBuilder = new UrlMappingEntityBuilder(migrationBuilder, ActiveDatabase);
 | 
			
		||||
                urlMappingEntityBuilder.DropForeignKey("FK_UrlMapping_Site");
 | 
			
		||||
                urlMappingEntityBuilder.DropIndex("IX_UrlMapping");
 | 
			
		||||
                urlMappingEntityBuilder.AlterStringColumn("Url", 500);
 | 
			
		||||
                urlMappingEntityBuilder.AlterStringColumn("MappedUrl", 500);
 | 
			
		||||
                urlMappingEntityBuilder.AddIndex("IX_UrlMapping", new[] { "SiteId", "Url" }, true);
 | 
			
		||||
                urlMappingEntityBuilder.AddForeignKey("FK_UrlMapping_Site");
 | 
			
		||||
            }
 | 
			
		||||
            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);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user