private async Task ExportDeletionOrderAsync(bool hasCycles, CancellationToken cancellationToken)
        {
            var orderer            = new TableRelationshipOrderer();
            var deletionOrder      = orderer.GetDeletionOrder(Tables);
            var deletionOutputPath = Path.Combine(ExportDirectory.FullName, "deletion-order.sql");
            var deletionOrderDoc   = BuildOrderDocument(deletionOrder);

            using var writer = File.CreateText(deletionOutputPath);
            await writer.WriteLineAsync("-- This is the deletion order for the database.".AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.WriteLineAsync("-- This may not be correct for your database or data relationships.".AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.WriteLineAsync("-- Please check before relying upon this information.".AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.WriteLineAsync().ConfigureAwait(false);

            if (hasCycles)
            {
                await writer.WriteLineAsync("-- NOTE: There are relationship cycles present in the database. This ordering is not guaranteed.".AsMemory(), cancellationToken).ConfigureAwait(false);

                await writer.WriteLineAsync().ConfigureAwait(false);
            }

            await writer.WriteAsync(deletionOrderDoc.AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.FlushAsync().ConfigureAwait(false);
        }
Esempio n. 2
0
        public static void GetDeletionOrder_GivenNullTables_ThrowsArgumentNullException()
        {
            var tableOrder = new TableRelationshipOrderer();

            Assert.That(() => tableOrder.GetDeletionOrder(null), Throws.ArgumentNullException);
        }