Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

InventoryBalanceMigration.cs

using FluentMigrator;
using Nop.Data;
using Nop.Data.Migrations;
using Nop.Plugin.Misc.Zettle.Domain;
using Nop.Services.Configuration;

namespace Nop.Plugin.Misc.Zettle.Data;

[NopMigration("2024-04-16 00:00:00", "Misc.Zettle 4.70.5 Inventory balance tracking", MigrationProcessType.Update)]
public class InventoryBalanceMigration : MigrationBase
{
    #region Fields

    protected readonly ISettingService _settingService;

    #endregion

    #region Ctor

    public InventoryBalanceMigration(ISettingService settingService)
    {
        _settingService = settingService;
    }

    #endregion

    #region Methods

    /// 
    /// Collect the UP migration expressions
    /// 
    public override async void Up()
    {
        if (!DataSettingsManager.IsDatabaseInstalled())
            return;

        //add column
        if (!Schema.Table(nameof(ZettleRecord)).Column(nameof(ZettleRecord.ExternalUuid)).Exists())
            Alter.Table(nameof(ZettleRecord)).AddColumn(nameof(ZettleRecord.ExternalUuid)).AsString().Nullable();

        //delete settings
        var setting = await _settingService.GetSettingAsync($"{nameof(ZettleSettings)}.InventoryTrackingIds");
        await _settingService.DeleteSettingAsync(setting);
    }

    /// 
    /// Collects the DOWN migration expressions
    /// 
    public override void Down()
    {
        //nothing
    }

    #endregion
}