コード例 #1
0
        /// <summary>
        /// Creates the tables and data for the database
        /// </summary>
        protected virtual void InitializeDatabase()
        {
            if (DatabaseTestBehavior == DatabaseBehavior.NoDatabasePerFixture || DatabaseTestBehavior == DatabaseBehavior.EmptyDbFilePerTest)
            {
                return;
            }

            //create the schema and load default data if:
            // - is the first test in the session
            // - NewDbFileAndSchemaPerTest
            // - _isFirstTestInFixture + DbInitBehavior.NewDbFileAndSchemaPerFixture

            if (_dbBytes == null &&
                (_isFirstRunInTestSession ||
                 DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerTest ||
                 (_isFirstTestInFixture && DatabaseTestBehavior == DatabaseBehavior.NewDbFileAndSchemaPerFixture)))
            {
                var schemaHelper = new DatabaseSchemaHelper(DatabaseContext.Database, Logger, SqlSyntax);
                //Create the umbraco database and its base data
                schemaHelper.CreateDatabaseSchema(false, ApplicationContext);

                //close the connections, we're gonna read this baby in as a byte array so we don't have to re-initialize the
                // damn db for each test
                CloseDbConnections();

                _dbBytes = File.ReadAllBytes(_dbPath);
            }
        }
コード例 #2
0
        public void Can_Assert_Created_Database()
        {
            string path = TestHelper.CurrentAssemblyDirectory;

            AppDomain.CurrentDomain.SetData("DataDirectory", path);

            //Delete database file before continueing
            //NOTE: we'll use a custom db file for this test since we're re-using the one created with BaseDatabaseFactoryTest
            string filePath = string.Concat(path, "\\DatabaseContextTests.sdf");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            //Get the connectionstring settings from config
            var settings = ConfigurationManager.ConnectionStrings[Constants.System.UmbracoConnectionName];

            //by default the conn string is: Datasource=|DataDirectory|UmbracoPetaPocoTests.sdf;Flush Interval=1;
            //we'll just replace the sdf file with our custom one:
            //Create the Sql CE database
            var connString = settings.ConnectionString.Replace("UmbracoPetaPocoTests", "DatabaseContextTests");

            using (var engine = new SqlCeEngine(connString))
            {
                engine.CreateDatabase();
            }

            var dbFactory     = new DefaultDatabaseFactory(connString, Constants.DatabaseProviders.SqlCe, Mock.Of <ILogger>());
            var scopeProvider = new ScopeProvider(dbFactory);

            //re-map the dbcontext to the new conn string
            _dbContext = new DatabaseContext(
                scopeProvider,
                Mock.Of <ILogger>(),
                new SqlCeSyntaxProvider(),
                dbFactory.ProviderName);

            var schemaHelper = new DatabaseSchemaHelper(_dbContext.Database, Mock.Of <ILogger>(), new SqlCeSyntaxProvider());

            var appCtx = new ApplicationContext(
                _dbContext,
                new ServiceContext(migrationEntryService: Mock.Of <IMigrationEntryService>()),
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));

            //Create the umbraco database
            schemaHelper.CreateDatabaseSchema(false, appCtx);

            bool umbracoNodeTable = schemaHelper.TableExist("umbracoNode");
            bool umbracoUserTable = schemaHelper.TableExist("umbracoUser");
            bool cmsTagsTable     = schemaHelper.TableExist("cmsTags");

            Assert.That(umbracoNodeTable, Is.True);
            Assert.That(umbracoUserTable, Is.True);
            Assert.That(cmsTagsTable, Is.True);
        }
コード例 #3
0
        private void CreateDatabase()
        {
            var context          = ApplicationContext.Current;
            var databaseProvider = context.DatabaseContext.DatabaseProvider;
            var dataDirectory    = DataDirectory;
            var db = new DatabaseSchemaHelper(context.DatabaseContext.Database, context.ProfilingLogger.Logger, context.DatabaseContext.SqlSyntax);

            if (databaseProvider == DatabaseProviders.SqlServerCE)
            {
                var dbPath = Path.Combine(dataDirectory, "Umbraco.sdf");
                if (File.Exists(dbPath) == false)
                {
                    var engine = new SqlCeEngine(@"Data Source=|DataDirectory|\Umbraco.sdf;Flush Interval=1;");
                    engine.CreateDatabase();
                }
            }

            db.CreateDatabaseSchema(false, context);

            Debug.WriteLine("The database schema has been installed");
            Debug.WriteLine("Note: This is just an example, so no backoffice user has been created.");
        }
コード例 #4
0
ファイル: DatabaseContext.cs プロジェクト: agrath/Umbraco-CMS
        internal Result CreateDatabaseSchemaAndData(ApplicationContext applicationContext)
        {
            try
            {
                var readyForInstall = CheckReadyForInstall();
                if (readyForInstall.Success == false)
                {
                    return(readyForInstall.Result);
                }

                _logger.Info <DatabaseContext>("Database configuration status: Started");

                string message;

                var database = new UmbracoDatabase(_connectionString, ProviderName, _logger);

                // If MySQL, we're going to ensure that database calls are maintaining proper casing as to remove the necessity for checks
                // for case insensitive queries. In an ideal situation (which is what we're striving for), all calls would be case sensitive.

                /*
                 * var supportsCaseInsensitiveQueries = SqlSyntax.SupportsCaseInsensitiveQueries(database);
                 * if (supportsCaseInsensitiveQueries  == false)
                 * {
                 *  message = "<p>&nbsp;</p><p>The database you're trying to use does not support case insensitive queries. <br />We currently do not support these types of databases.</p>" +
                 *            "<p>You can fix this by changing the following setting in your my.ini file in your MySQL installation directory:</p>" +
                 *            "<pre>lower_case_table_names=1</pre><br />" +
                 *            "<p>Note: Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                 *            "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                 *            "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";
                 *
                 *  return new Result { Message = message, Success = false, Percentage = "15" };
                 * }
                 */

                message = GetResultMessageForMySql();

                var schemaResult = ValidateDatabaseSchema();

                var installedSchemaVersion = schemaResult.DetermineInstalledVersion();

                //If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing
                if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedSchemaVersion.Equals(new Version(0, 0, 0)))
                {
                    var helper = new DatabaseSchemaHelper(database, _logger, SqlSyntax);
                    helper.CreateDatabaseSchema(true, applicationContext);

                    message = message + "<p>Installation completed!</p>";

                    //now that everything is done, we need to determine the version of SQL server that is executing
                    _logger.Info <DatabaseContext>("Database configuration status: " + message);
                    return(new Result {
                        Message = message, Success = true, Percentage = "100"
                    });
                }

                //we need to do an upgrade so return a new status message and it will need to be done during the next step
                _logger.Info <DatabaseContext>("Database requires upgrade");
                message = "<p>Upgrading database, this may take some time...</p>";
                return(new Result
                {
                    RequiresUpgrade = true,
                    Message = message,
                    Success = true,
                    Percentage = "30"
                });
            }
            catch (Exception ex)
            {
                return(HandleInstallException(ex));
            }
        }
コード例 #5
0
        public override async Task <DeliverableResponse> Run(string command, string[] args)
        {
            var connectionString = settings.ConnectionString;

            if (connectionString == null || string.IsNullOrEmpty(connectionString.ConnectionString))
            {
                await Out.WriteLineAsync("No connection string is setup for your Umbraco instance. Chauffeur expects your web.config to be setup in your deployment package before you try and install.");

                return(DeliverableResponse.Continue);
            }

            if (connectionString.ProviderName == "System.Data.SqlServerCe.4.0")
            {
                var dataDirectory = (string)AppDomain.CurrentDomain.GetData("DataDirectory");
                var dataSource    = connectionString.ConnectionString.Split(';').FirstOrDefault(s => s.ToLower().Contains("data source"));

                if (!string.IsNullOrEmpty(dataSource))
                {
                    var dbFileName = dataSource.Split('=')
                                     .Last()
                                     .Split('\\')
                                     .Last()
                                     .Trim();

                    var location = fileSystem.Path.Combine(dataDirectory, dbFileName);

                    if (!fileSystem.File.Exists(location))
                    {
                        await Out.WriteLineAsync("The SqlCE database specified in the connection string doesn't appear to exist.");

                        var response = args.Length > 0 ? args[0] : null;
                        if (string.IsNullOrEmpty(response))
                        {
                            await Out.WriteAsync("Create it? (Y/n) ");

                            response = await In.ReadLineAsync();
                        }

                        if (string.IsNullOrEmpty(response) || response.Equals("Y", StringComparison.InvariantCultureIgnoreCase))
                        {
                            await Out.WriteLineAsync("Creating the database");

                            var engine = sqlCeEngineFactory(connectionString.ConnectionString);
                            engine.CreateDatabase();
                        }
                        else
                        {
                            await Out.WriteLineAsync("Installation is being aborted");

                            return(DeliverableResponse.Continue);
                        }
                    }
                }
            }

            await Out.WriteLineAsync("Preparing to install Umbraco's database");

            dbSchemaHelper.CreateDatabaseSchema(false, appContext);

            await Out.WriteLineAsync("Database installed and ready to go");

            return(DeliverableResponse.Continue);
        }
コード例 #6
0
        private void CreateDatabase()
        {
            var context = ApplicationContext.Current;
            var databaseProvider = context.DatabaseContext.DatabaseProvider;
            var dataDirectory = DataDirectory;
            var db = new DatabaseSchemaHelper(context.DatabaseContext.Database, context.ProfilingLogger.Logger, context.DatabaseContext.SqlSyntax);

            if (databaseProvider == DatabaseProviders.SqlServerCE)
            {
                var dbPath = Path.Combine(dataDirectory, "Umbraco.sdf");
                if (File.Exists(dbPath))
                {
                    File.Delete(dbPath);
                }
                var engine = new SqlCeEngine(@"Data Source=|DataDirectory|\Umbraco.sdf;Flush Interval=1;");
                engine.CreateDatabase();
            }

            db.CreateDatabaseSchema(false, context);

            Debug.WriteLine("The database schema has been installed");
            Debug.WriteLine("Note: This is just an example, so no backoffice user has been created.");
        }