示例#1
0
        /// <summary>
        /// Tests the given <see cref="SQLFile"/> on the given <see cref="Database"/>.
        /// </summary>
        public void CreateData(Database database, SQLFile target)
        {
            if (database.CurrentVersion < target.Version)
            {
                throw new InvalidOperationException("The target file was not executed on the database");
            }

            // read file
            PgDatabase postgresDatabase = PgDumpLoader.LoadDatabaseSchema(target.Path, database, false, false);

            // create data for tables
            foreach (var schema in postgresDatabase.Schemas)
            {
                var tables = new Dictionary <PgTable, bool>();
                foreach (var table in schema.Tables)
                {
                    tables.Add(table, false);
                }

                foreach (var table in schema.Tables)
                {
                    this.CreateData(database, target, schema, table, tables);
                }
            }
        }
示例#2
0
        public SQLFileDisplayData(SQLFile file)
        {
            this.SQLFile = file;

            this.WarningText   = string.Empty;
            this.Status        = ErrorStatus.Unknown;
            this.SQLStatements = new ObservableCollection <StatementDisplayData>();
            this.RefreshStatements();
        }
示例#3
0
        public void TestEmptyMethods(Database database, SQLFile target)
        {
            if (database.CurrentVersion < target.Version)
            {
                throw new InvalidOperationException("The target file was not executed on the database");
            }

            // read file
            PgDatabase oldDatabase = PgDumpLoader.LoadDatabaseSchema(target.Path, database, false, false);

            // call empty functions
        }
示例#4
0
 partial void SQLFileBeforeSet(SQLFile newValue);
        /// <summary>
        /// Undoes all changes which were made to this database by creating an undo diff and executing it.
        /// </summary>
        public void UndoChanges(string dumpCreatorPath, string host, string id, string password, int port)
        {
            Log.Info($"Start undoing Database {this.Name} to version {this.CurrentVersion}");

            // create undo diff
            this.SetProgress(0, "Start undoing changes");
            this.UpdateVersion();

            // file paths
            var previousDump = this.GenerateFileLocation(this.CurrentVersion, SQLTemplates.DumpFile);
            var dump         = this.GenerateFileLocation($"{DatabaseVersion.TempDumpName}{this.CurrentVersion}", SQLTemplates.DumpFile);
            var undoDiff     = this.GenerateFileLocation($"{DatabaseVersion.TempUndoDiffName}{this.CurrentVersion}", SQLTemplates.UndoDiffFile);

            try
            {
                // update version before creating dump, so the new dump contains the next version
                this.SetProgress(10, "Creating dump with changes which should be undone");
                this.CreateDump(dump, dumpCreatorPath, host, id, password, port);

                if (this.fileSystemAccess.GetFileSize(previousDump) == this.fileSystemAccess.GetFileSize(dump))
                {
                    // check files byte by byte
                    var oldDump = this.fileSystemAccess.ReadAllLines(previousDump);
                    var newDump = this.fileSystemAccess.ReadAllLines(dump);

                    if (oldDump.SequenceEqual(newDump))
                    {
                        throw TeamworkException.NoChanges(previousDump, dump);
                    }
                }

                // diff only original dumps
                this.SetProgress(20, "Finding differences and creating files");
                this.CreateDiffFile(dump, previousDump, undoDiff);

                // execute undo diff
                var file = new SQLFile(undoDiff, this, this.fileSystemAccess);
                file.ExecuteInTransaction();
            }
            catch (TeamworkConnectionException ex)
            {
                Log.Warn(string.Format("Error occured while testing exported files."), ex);
                var message = $"Error occured in file [File] while testing exported files. Diff and Dump files will not be deleted and can be edited manually.Error: {ex.Message}";

                if (ex.File != null)
                {
                    message = message.Replace("[File]", ex.File.Path);
                    throw new TeamworkTestException(message, ex);
                }

                // do not delete files if only the test did not work => can be manually fixed by the user
                message = message.Replace("[File]", "unknown");
                throw new Exception(message, ex);
            }
            catch (Exception ex)
            {
                Log.Error("Error occured while undoing changes", ex);
                throw;
            }
            finally
            {
                // remove undo diff and dump
                if (this.fileSystemAccess.FileExists(dump))
                {
                    this.fileSystemAccess.DeleteFile(dump);
                }

                if (this.fileSystemAccess.FileExists(undoDiff))
                {
                    this.fileSystemAccess.DeleteFile(undoDiff);
                }

                this.SetProgress(100);
            }
        }