Exemple #1
0
        public void MasterDatabaseScriptExecutor_CreateDatabase()
        {
            string dbName = "CreateANewCatalogueDatabaseWithMasterDatabaseScriptExecutor";

            var database = DiscoveredServerICanCreateRandomDatabasesAndTablesOn.ExpectDatabase(dbName);

            if (database.Exists())
            {
                database.Drop();
            }

            MasterDatabaseScriptExecutor executor = new MasterDatabaseScriptExecutor(database);

            executor.CreateDatabase(@"
CREATE TABLE Bob
(
age int
)
GO", "1.0.0.0", new ThrowImmediatelyCheckNotifier());

            var versionTable = database.ExpectTable("Version");
            var bobTable     = database.ExpectTable("Bob");

            Assert.IsTrue(versionTable.Exists());
            Assert.IsTrue(bobTable.Exists());

            database.Drop();
        }
Exemple #2
0
        public void MasterDatabaseScriptExecutor_CreateDatabase()
        {
            var db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);

            MasterDatabaseScriptExecutor executor = new MasterDatabaseScriptExecutor(db);

            executor.CreateDatabase(@"
CREATE TABLE Bob
(
age int
)
GO", "1.0.0.0", new AcceptAllCheckNotifier()); //database already exists so accept creating it into an existing (empty) db

            var versionTable = db.ExpectTable("Version");
            var bobTable     = db.ExpectTable("Bob");

            Assert.IsTrue(versionTable.Exists());
            Assert.IsTrue(bobTable.Exists());
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            var db = serverDatabaseTableSelector1.GetDiscoveredDatabase();

            if (db == null)
            {
                MessageBox.Show(
                    "You must pick an empty database or enter the name of a new one (that doesn't exist yet)");
                return;
            }

            if (_completed)
            {
                MessageBox.Show("Setup completed already, review progress messages then close Form");
                return;
            }

            if (_tCreateDatabase != null && !_tCreateDatabase.IsCompleted)
            {
                MessageBox.Show("Setup already underaway");
                return;
            }

            var createSql = _patcher.GetInitialCreateScriptContents(db);
            var patches   = _patcher.GetAllPatchesInAssembly(db);

            var preview = new SQLPreviewWindow("Confirm happiness with SQL",
                                               "The following SQL is about to be executed:", createSql.EntireScript);

            var executor = new MasterDatabaseScriptExecutor(db);

            if (preview.ShowDialog() == DialogResult.OK)
            {
                _tCreateDatabase = Task.Run(() =>

                {
                    var memory = new ToMemoryCheckNotifier(checksUI1);

                    if (executor.CreateDatabase(createSql, memory))
                    {
                        _completed = executor.PatchDatabase(patches, memory, silentlyApplyPatchCallback);

                        DatabaseCreatedIfAny = db;

                        var worst = memory.GetWorst();
                        if (worst == CheckResult.Success || worst == CheckResult.Warning)
                        {
                            if (MessageBox.Show("Succesfully created database, close form?", "Success", MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                _programaticClose = true;
                                Invoke(new MethodInvoker(Close));
                            }
                        }
                    }
                    else
                    {
                        _completed = false;    //failed to create database
                    }
                }
                                            );
            }
        }