<commit_before>﻿using NPoco;
using System;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;

namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
{
    public class TablesForScheduledPublishing : MigrationBase
    {
        public TablesForScheduledPublishing(IMigrationContext context)
            : base(context)
        { }

        public override void Migrate()
        {
            //Get anything currently scheduled
            var scheduleSql = new Sql()
                .Select("nodeId", "releaseDate", "expireDate")
                .From("umbracoDocument")
                .Where("releaseDate IS NOT NULL OR expireDate IS NOT NULL");
            var schedules = Database.Dictionary<int, (DateTime? releaseDate, DateTime? expireDate)> (scheduleSql);

            //drop old cols
            Delete.Column("cmsDocument").FromTable("releaseDate").Do();
            Delete.Column("cmsDocument").FromTable("expireDate").Do();
            //add new table
            Create.Table<ContentScheduleDto>().Do();

            //migrate the schedule
            foreach(var s in schedules)
            {
                var date = s.Value.releaseDate;
                var action = ContentScheduleChange.Start.ToString();
                if (!date.HasValue)
                {
                    date = s.Value.expireDate;
                    action = ContentScheduleChange.End.ToString();
                }

                Insert.IntoTable(ContentScheduleDto.TableName)
                    .Row(new { nodeId = s.Key, date = date.Value, action = action })
                    .Do();
            }
        }
    }
}
<commit_msg>fixes migrations<commit_after>﻿using NPoco;
using System;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Dtos;

namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0
{
    public class TablesForScheduledPublishing : MigrationBase
    {
        public TablesForScheduledPublishing(IMigrationContext context)
            : base(context)
        { }

        public override void Migrate()
        {
            //Get anything currently scheduled
            var scheduleSql = new Sql()
                .Select("nodeId", "releaseDate", "expireDate")
                .From("umbracoDocument")
                .Where("releaseDate IS NOT NULL OR expireDate IS NOT NULL");
            var schedules = Database.Dictionary<int, (DateTime? releaseDate, DateTime? expireDate)> (scheduleSql);

            //drop old cols
            Delete.Column("releaseDate").FromTable("cmsDocument").Do();
            Delete.Column("expireDate").FromTable("cmsDocument").Do();
            //add new table
            Create.Table<ContentScheduleDto>().Do();

            //migrate the schedule
            foreach(var s in schedules)
            {
                var date = s.Value.releaseDate;
                var action = ContentScheduleChange.Start.ToString();
                if (!date.HasValue)
                {
                    date = s.Value.expireDate;
                    action = ContentScheduleChange.End.ToString();
                }

                Insert.IntoTable(ContentScheduleDto.TableName)
                    .Row(new { nodeId = s.Key, date = date.Value, action = action })
                    .Do();
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.10125038121378468, 'fraction_numerical': 0.0018298261665141812, 'mean_word_length': 1.7563025210084033, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '19270', 'n_tokens_mistral': 871, 'n_tokens_neox': 819, 'n_words': 177}