How to remove and rename custom tables in my plugin?

10 месяцев назад
Hi, like the title says I am wondering how to remove tables on plugin uninstall. For now I thought I could use:
public override void Down()
{

}

But I can't seem to find an appropriate way to remove the tables I made in "Up" method. My migrations class is deriving from: MigrationBase.
The other question is how to rename the tables? In the Domain folder I added "Model" suffix to every table or model, for better readibility, but the tables also have "Model" in them, and I want to remove this.
Thanks
10 месяцев назад
Remove.  Try
    if (Schema.Table("YourTableName").Exists())
    {
        Delete.Table("YourTableName");
    }


Rename.  Try
    if (Schema.Table("OldTableName").Exists())
    {
        Rename.Table("OldTableName").To("NewTableName");
    }
10 месяцев назад
It doesn't find. The Delete.Table() or Rename
10 месяцев назад
Also I am using 4.60.3
10 месяцев назад
A typical Up / Down Migration looks like


using Nop.Core;
using Nop.Data.Extensions;
using Nop.Data.Mapping;
using Nop.Data.Migrations;
using Nop.Services.Configuration;
using Nop.Services.Stores;

namespace Nop.Plugin.Name.Group.Data
{
    [NopMigration("2022/07/05 00:00:01:1687541", "Name.Group base schema", MigrationProcessType.Installation)]
    public class SchemaMigration : FluentMigrator.Migration
    {
        protected IMigrationManager _migrationManager;
        protected ISettingService _settingService;
        protected IStoreService _storeService;
        protected IStoreContext _storeContext;

        public SchemaMigration(IMigrationManager migrationManager,
            ISettingService settingService,
            IStoreService storeService,
            IStoreContext storeContext)
        {
            _migrationManager = migrationManager;
            _settingService = settingService;
            _storeService = storeService;
            _storeContext = storeContext;
        }

        public override void Up()
        {
            try
            {
                // Try to create database table
                if (!Schema.Schema("dbo").Table(NameCompatibilityManager.GetTableName(typeof(XXXXX_Table))).Exists())
                    Create.TableFor<XXXXX_Table>();
            }
            catch
            {
                // Error code
            }
        }

        public override void Down()
        {
            Delete.Table(NameCompatibilityManager.GetTableName(typeof(XXXXX_Table)));
        }
    }
}