예제 #1
0
        /// <summary>
        /// Generates down SQL scripts.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="migration">The migration.</param>
        /// <param name="previousMigration">The previous migration.</param>
        /// <returns></returns>
        protected virtual IReadOnlyList <MigrationCommand> GenerateDownSql(EntityPlugin plugin, Migration migration, Migration previousMigration)
        {
            var historyScript  = PluginHistoryRepository.GetDeleteScript(plugin, migration.GetType().GetCustomAttribute <MigrationAttribute>().Id);
            var historyCommand = RawSqlCommandBuilder.Build(historyScript);

            return(MigrationsSqlGenerator
                   .Generate(migration.DownOperations, previousMigration?.TargetModel)
                   .Concat(new[] { new MigrationCommand(historyCommand, CurrentContext.Context, CommandLogger) })
                   .ToList());
        }
예제 #2
0
        /// <summary>
        /// Generates up SQL scripts.
        /// </summary>
        /// <param name="plugin">The plugin.</param>
        /// <param name="migration">The migration.</param>
        /// <returns></returns>
        protected virtual IReadOnlyList <MigrationCommand> GenerateUpSql(EntityPlugin plugin, Migration migration)
        {
            var migrationId    = migration.GetType().GetCustomAttribute <MigrationAttribute>()?.Id;
            var historyRow     = new HistoryRow(migrationId, ProductInfo.GetVersion());
            var historyScript  = PluginHistoryRepository.GetInsertScript(plugin, historyRow);
            var historyCommand = RawSqlCommandBuilder.Build(historyScript);

            return(MigrationsSqlGenerator
                   .Generate(migration.UpOperations, migration.TargetModel)
                   .Concat(new[] { new MigrationCommand(historyCommand, CurrentContext.Context, CommandLogger) })
                   .ToList());
        }