Webiant Logo Webiant Logo
  1. No results found.

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

NewsLetterSubscriptionMigration.cs

using FluentMigrator;
using Nop.Core.Domain.Messages;
using Nop.Data.Extensions;

namespace Nop.Data.Migrations.UpgradeTo490;

[NopSchemaMigration("2025-03-19 00:00:00", "Multiple newsletter lists")]
public class NewsLetterSubscriptionMigration : ForwardOnlyMigration
{
    /// 
    /// Collect the UP migration expressions
    /// 
    public override void Up()
    {
        if (!Schema.Table(nameof(NewsLetterSubscriptionType)).Exists())
            Create.TableFor();

        if (!Schema.Table(nameof(NewsLetterSubscription)).Column(nameof(NewsLetterSubscription.TypeId)).Exists())
        {
            //add new column
            Alter.Table(nameof(NewsLetterSubscription))
                .AddColumn(nameof(NewsLetterSubscription.TypeId)).AsInt32().ForeignKey().Nullable();
        }

        if (!Schema.Table(nameof(Campaign)).Column(nameof(Campaign.NewsLetterSubscriptionTypeId)).Exists())
        {
            //add new column
            Alter.Table(nameof(Campaign))
                .AddColumn(nameof(Campaign.NewsLetterSubscriptionTypeId)).AsInt32().NotNullable().SetExistingRowsTo(0);
        }
    }
}