protected void EnsureTablesExist()
        {
            // TODO: Should this be stored in UmbracoIdentity SQL CE database?
            var dbCtx = ApplicationContext.Current.DatabaseContext;
            var dbSchemaHelper = new DatabaseSchemaHelper(dbCtx.Database, LoggerResolver.Current.Logger, dbCtx.SqlSyntax);

            if (!dbSchemaHelper.TableExist(typeof(OAuthClient).Name))
            {
                // Create table
                dbSchemaHelper.CreateTable(false, typeof(OAuthClient));

                // Seed the table
                dbCtx.Database.Save(new OAuthClient
                {
                    ClientId = "DemoClient",
                    Name = "Demo Client",
                    Secret = "demo",
                    SecurityLevel = SecurityLevel.Insecure,
                    RefreshTokenLifeTime = 14400,
                    AllowedOrigin = "*"
                });
            }

            if (!dbSchemaHelper.TableExist(typeof(OAuthRefreshToken).Name))
            {
                // Create table
                dbSchemaHelper.CreateTable(false, typeof(OAuthRefreshToken));
            }
        }
Exemple #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);
        }
        public void Init()
        {
            var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]);
            _worker = new DbPreTestDataWorker {SqlSyntax = syntax };

            var schemaHelper = new DatabaseSchemaHelper(_worker.Database, _worker.TestLogger, _worker.SqlSyntaxProvider);
            var deletions = new DatabaseSchemaCreation(_worker.Database, _worker.TestLogger, schemaHelper, _worker.SqlSyntaxProvider);
            deletions.UninstallDatabaseSchema();
        }
        public static bool DatabaseTableExists(DatabaseContext dbCtx, string tableName)
        {
            DatabaseSchemaHelper dsh = new DatabaseSchemaHelper(
                dbCtx.Database,
                ApplicationContext.Current.ProfilingLogger.Logger,
                dbCtx.SqlSyntax);

            return(dsh.TableExist(tableName));
        }
Exemple #5
0
        /// <summary>
        /// Handles the application started event.
        /// </summary>
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication,
                                                   ApplicationContext applicationContext)
        {
            var ctx = applicationContext.DatabaseContext;
            var db  = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger,
                                               ctx.SqlSyntax);

            TryCreateTable <HistoryItem>(db, HistoryItem.TableName);
        }
Exemple #6
0
        /// <summary>
        /// Creates the merchProduct2ProductCollection table in the database
        /// </summary>
        public override void Up()
        {
            var database = ApplicationContext.Current.DatabaseContext.Database;

            if (!database.TableExist("merchProduct2EntityCollection"))
            {
                DatabaseSchemaHelper.InitializeDatabaseSchema(database, OrderedTables, "Merchello 1.11.0 upgrade");
            }
        }
Exemple #7
0
        public DbRents()
        {
            var applicationContext = ApplicationContext.Current;
            var ctx = applicationContext.DatabaseContext;

            _dbSchemaHelper = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger, ctx.SqlSyntax);
            _db             = ApplicationContext.Current.DatabaseContext.Database;
            _tableName      = "CrRents";
        }
Exemple #8
0
        private void EnsureContentTable(DatabaseContext databaseContext, string tableName)
        {
            var dbHelper = new DatabaseSchemaHelper(databaseContext.Database, _logger, databaseContext.SqlSyntax);

            if (!dbHelper.TableExist(tableName))
            {
                // create the table here... but we need to do it with diffrent table name.
                //
            }
        }
        /// <summary>
        /// On Application Started we need to ensure that the Redirects table exists. If not, create it
        /// </summary>
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //Grab the Umbraco database context and spin up a new DatabaseSchemaHelper
            var db = applicationContext.DatabaseContext.Database;
            var creator = new DatabaseSchemaHelper(db, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider);

            //Ensure the Redirects table exists. If not, create it
            if (!creator.TableExist("Redirects"))
                creator.CreateTable<Redirect>(false);
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            DatabaseContext      ctx      = ApplicationContext.Current.DatabaseContext;
            DatabaseSchemaHelper dbSchema = new DatabaseSchemaHelper(ctx.Database, ApplicationContext.Current.ProfilingLogger.Logger, ctx.SqlSyntax);

            if (!dbSchema.TableExist("messagesCustomTable"))
            {
                dbSchema.CreateTable <MessageDto>(true);
            }
        }
Exemple #11
0
        protected void EnsureTablesExist()
        {
            var dbCtx          = ApplicationContext.Current.DatabaseContext;
            var dbSchemaHelper = new DatabaseSchemaHelper(dbCtx.Database, LoggerResolver.Current.Logger, dbCtx.SqlSyntax);

            if (!dbSchemaHelper.TableExist(typeof(OAuthRefreshToken).Name))
            {
                dbSchemaHelper.CreateTable(false, typeof(OAuthRefreshToken));
            }
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var ctx = applicationContext.DatabaseContext;
            var db  = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger, ctx.SqlSyntax);

            if (!db.TableExist("CMSupportGroups"))
            {
                db.CreateTable <SupportGroups>(false);
            }
        }
Exemple #13
0
 public DatabaseFactory(ApplicationContext context)
 {
     Database       = context.DatabaseContext.Database;
     DatabaseHelper = new DatabaseSchemaHelper
                      (
         context.DatabaseContext.Database,
         context.ProfilingLogger.Logger,
         context.DatabaseContext.SqlSyntax
                      );
 }
        public async Task FoundDeliveryPreviouslyRun_WillBeSkipped()
        {
            var provider = Substitute.For <ISqlSyntaxProvider>();

            provider.DoesTableExist(Arg.Any <Database>(), Arg.Any <string>()).Returns(true);

            var    settings = Substitute.For <IChauffeurSettings>();
            string s;

            settings.TryGetChauffeurDirectory(out s).Returns(x =>
            {
                x[0] = @"c:\foo";
                return(true);
            });

            var reader = Substitute.For <IDataReader>();

            reader.Read().Returns(true, false);
            reader.GetBoolean(Arg.Any <int>()).Returns(true);
            reader.GetInt32(Arg.Any <int>()).Returns(1);
            reader.GetString(Arg.Any <int>()).Returns(string.Empty);
            reader.GetDateTime(Arg.Any <int>()).Returns(DateTime.Now);
            reader.GetValue(Arg.Any <int>()).Returns(DateTime.Now);
            reader.FieldCount.Returns(5); //the number of properties on the table
            reader.GetName(Arg.Any <int>()).Returns("Id", "Name", "ExecutionDate", "SignedFor", "Hash");
            reader.GetFieldType(Arg.Any <int>()).Returns(typeof(int), typeof(string), typeof(DateTime), typeof(bool), typeof(string));
            var cmd = Substitute.For <IDbCommand>();

            cmd.ExecuteReader().Returns(reader);
            cmd.ExecuteScalar().Returns(1);
            var conn = Substitute.For <IDbConnection>();

            conn.CreateCommand().Returns(cmd);
            var db = new Database(conn);

            var writer = new MockTextWriter();

            var deliverableScript = "foo";
            var fs = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { @"c:\foo\bar.delivery", new MockFileData(deliverableScript) }
            });

            var host = Substitute.For <IChauffeurHost>();

            host.Run(Arg.Any <string[]>()).Returns(Task.FromResult(DeliverableResponse.Continue));

            var dbSchema = new DatabaseSchemaHelper(db, null, provider);

            var deliverable = new DeliveryDeliverable(null, writer, dbSchema, db, settings, fs, host, provider);

            await deliverable.Run(null, new string[0]);

            host.Received(0).Run(Arg.Any <string[]>()).IgnoreAwaitForNSubstituteAssertion();
        }
Exemple #15
0
        public UmbracoDatabaseRepository(UmbracoContext umbracoContext)
        {
            if (umbracoContext == null)
            {
                throw new ArgumentNullException(nameof(umbracoContext));
            }

            DatabaseContext       = umbracoContext.Application.DatabaseContext;
            Database              = DatabaseContext.Database;
            _databaseSchemaHelper = new DatabaseSchemaHelper(Database, LoggerResolver.Current.Logger, DatabaseContext.SqlSyntax);
        }
Exemple #16
0
        public DatababaseFixture()
        {
            _sqlCeConnection = TableDataHelper.SetSqlCeConnection();

            Db = new UmbracoDatabase(_sqlCeConnection, Mock.Of <ILogger>());

            _dbSchemaHelper = new DatabaseSchemaHelper(Db, Mock.Of <ILogger>(), new SqlCeSyntaxProvider());

            PrepareTables();
            FillTablesWithTestData();
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var ctx = applicationContext.DatabaseContext;
            var db  = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger, ctx.SqlSyntax);

            //Check if the DB table does NOT exist
            if (!db.TableExist("PushSubscriptions"))
            {
                db.CreateTable <PushSubscription>(false);
            }
        }
Exemple #18
0
        public static void Tables()
        {
            // ensure required tables exist
            DatabaseSchemaHelper persistenceHelper = Persistence.Helper();

            persistenceHelper.CreateTable <UserGroupPoco>();
            persistenceHelper.CreateTable <User2UserGroupPoco>();
            persistenceHelper.CreateTable <UserGroupPermissionsPoco>();
            persistenceHelper.CreateTable <WorkflowSettingsPoco>();
            persistenceHelper.CreateTable <WorkflowInstancePoco>();
            persistenceHelper.CreateTable <WorkflowTaskInstancePoco>();
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var dbContext = applicationContext.DatabaseContext;
            var helper    = new DatabaseSchemaHelper(dbContext.Database, LoggerResolver.Current.Logger, dbContext.SqlSyntax);

            if (helper.TableExist("PromoteModules"))
            {
                return;
            }

            helper.CreateTable <PromoPoco>(false);
        }
        /// <summary>
        /// On Application Started we need to ensure that the Redirects table exists. If not, create it
        /// </summary>
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //Grab the Umbraco database context and spin up a new DatabaseSchemaHelper
            var db      = applicationContext.DatabaseContext.Database;
            var creator = new DatabaseSchemaHelper(db, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider);

            //Ensure the Redirects table exists. If not, create it
            if (!creator.TableExist("Redirects"))
            {
                creator.CreateTable <Redirect>(false);
            }
        }
Exemple #21
0
        public void Initialize()
        {
            var tableName = _tableNameHelper.GetTableName();

            var databaseContext      = UmbracoContext.Current.Application.DatabaseContext;
            var databaseSchemaHelper = new DatabaseSchemaHelper(databaseContext.Database, LoggerResolver.Current.Logger, databaseContext.SqlSyntax);

            if (!databaseSchemaHelper.TableExist(tableName))
            {
                databaseSchemaHelper.CreateTable <NodeReport>(false);
            }
        }
Exemple #22
0
        internal IEnumerable <MigrationModel> GetMigrations()
        {
            var ctx    = ApplicationContext.Current.DatabaseContext;
            var helper = new DatabaseSchemaHelper(ctx.Database, ApplicationContext.Current.ProfilingLogger.Logger, ctx.SqlSyntax);

            if (helper.TableExist("umbracoMigration"))
            {
                const string sql = @"select Id, Name, CreateDate, Version from umbracoMigration";
                return(db.Fetch <MigrationModel>(sql));
            }

            return(null);
        }
Exemple #23
0
        internal IEnumerable <ServerModel> GetRegistredServers()
        {
            var ctx    = ApplicationContext.Current.DatabaseContext;
            var helper = new DatabaseSchemaHelper(ctx.Database, ApplicationContext.Current.ProfilingLogger.Logger, ctx.SqlSyntax);

            if (helper.TableExist("umbracoServer"))
            {
                const string sql = @"SELECT Id, Address, ComputerName, RegisteredDate, LastNotifiedDate, IsActive, IsMaster FROM umbracoServer";
                return(db.Fetch <ServerModel>(sql));
            }

            return(null);
        }
Exemple #24
0
        /// <summary>
        /// Initializes, creates the database corresponding poco classes
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="appContext"></param>
        /// <param name="type"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        private static bool Register <T>(ApplicationContext appContext, Type type, string tableName) where T : new()
        {
            var dbContext       = appContext.DatabaseContext;
            var logger          = LoggerResolver.Current.Logger;
            var dbSchemaUtility = new DatabaseSchemaHelper(dbContext.Database, logger, dbContext.SqlSyntax);

            if (!dbSchemaUtility.TableExist(tableName))
            {
                dbSchemaUtility.CreateTable <T>(false);
                return(true);
            }
            return(false);
        }
Exemple #25
0
        private void ConfigureDatabase()
        {
            var dbContext = ApplicationContext.Current.DatabaseContext;
            var logger    = LoggerResolver.Current.Logger;

            _database       = dbContext.Database;
            _dbSchemaHelper = new DatabaseSchemaHelper(dbContext.Database, logger, dbContext.SqlSyntax);

            if (!_dbSchemaHelper.TableExist("Chauffeur_Changes"))
            {
                _dbSchemaHelper.CreateTable <ChauffeurChangesTable>(false);
            }
        }
Exemple #26
0
        /// <summary>
        /// Initialize the database by creating the umbraco db schema
        /// </summary>
        public void InitializeDatabaseSchema()
        {
            var e = new DatabaseCreationEventArgs();

            FireBeforeCreation(e);

            if (!e.Cancel)
            {
                DatabaseSchemaHelper.InitializeDatabaseSchema(_database, OrderedTables, MerchelloVersion.Current.ToString());
            }

            FireAfterCreation(e);
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var db      = applicationContext.DatabaseContext.Database;
            var creator = new DatabaseSchemaHelper(db, LoggerResolver.Current.Logger, applicationContext.DatabaseContext.SqlSyntax);

            //Ensure the FavoriteContent table exists and if not, create it
            if (!creator.TableExist("FavoriteContent"))
            {
                creator.CreateTable <FavoriteContentModel>(false);
            }

            ContentService.Saving += SaveAndPublishEvents.UpdateFavoritePropertyInDatabase;
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            DatabaseContext      ctx      = ApplicationContext.Current.DatabaseContext;
            DatabaseSchemaHelper dbSchema = new DatabaseSchemaHelper(ctx.Database, ApplicationContext.Current.ProfilingLogger.Logger, ctx.SqlSyntax);

            // use for testing dbSchema.DropTable<PageNotFound>();
            if (!dbSchema.TableExist(PageNotFound.TableName))
            {
                dbSchema.CreateTable <PageNotFound>(false);
                var migrator = new Migrator(ctx.Database);
                migrator.Start();
            }
        }
        protected override void ApplicationStarted(
            UmbracoApplicationBase umbracoApplication,
            ApplicationContext applicationContext)
        {
            var dbContext      = applicationContext.DatabaseContext;
            var dbSchemaHelper = new DatabaseSchemaHelper(
                dbContext.Database,
                ApplicationContext.Current.ProfilingLogger.Logger,
                dbContext.SqlSyntax);

            CreateTableScript(dbSchemaHelper);
            SeedDatabase(dbContext);
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData += OnGatheringNodeData;
            PreRenderViewActionFilterAttribute.ActionExecuted += PreRenderViewActionFilterAttribute_ActionExecuted;
            var logger    = LoggerResolver.Current.Logger;
            var dbContext = ApplicationContext.Current.DatabaseContext;
            var helper    = new DatabaseSchemaHelper(dbContext.Database, logger, dbContext.SqlSyntax);

            if (!helper.TableExist("PageViews"))
            {
                helper.CreateTable <PageView>(false);
            }
        }
Exemple #31
0
        public void Init()
        {
            var syntax = (DbSyntax)Enum.Parse(typeof(DbSyntax), ConfigurationManager.AppSettings["syntax"]);

            _worker = new DbPreTestDataWorker {
                SqlSyntax = syntax
            };

            var schemaHelper = new DatabaseSchemaHelper(_worker.Database, _worker.TestLogger, _worker.SqlSyntaxProvider);
            var deletions    = new DatabaseSchemaCreation(_worker.Database, _worker.TestLogger, schemaHelper, _worker.SqlSyntaxProvider);

            deletions.UninstallDatabaseSchema();
        }
Exemple #32
0
        private void CheckFieldsDatabase()
        {
            var logger    = LoggerResolver.Current.Logger;
            var dbContext = ApplicationContext.Current.DatabaseContext;
            var dbHelper  = new DatabaseSchemaHelper(dbContext.Database, logger, dbContext.SqlSyntax);

            if (dbHelper.TableExist(PackageConstants.DbStateTable))
            {
                dbHelper.DropTable(PackageConstants.DbStateTable);
                dbHelper.CreateTable(false, typeof(TState));
            }

            var tables = new Dictionary <string, Type>
            {
                { PackageConstants.DbStatisticTable, typeof(TImageStatistic) },
            };

            for (var i = 0; i < tables.Count; i++)
            {
                if (dbHelper.TableExist(tables.ElementAt(i).Key))
                {
                    var checkColumn    = new Sql(@"SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE 
                                                TABLE_NAME = 'TinifierImagesStatistic' AND COLUMN_NAME = 'TotalSavedBytes'");
                    var checkHidePanel = new Sql(@"SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE
                                                TABLE_NAME = 'TinifierUserSettings' AND COLUMN_NAME = 'HideLeftPanel'");
                    var checkMetaData  = new Sql(@"SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE 
                                                TABLE_NAME = 'TinifierUserSettings' AND COLUMN_NAME = 'PreserveMetadata'");
                    int?exists         = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar <int?>(checkColumn);
                    int?hidePanel      = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar <int?>(checkHidePanel);
                    int?metaData       = ApplicationContext.Current.DatabaseContext.Database.ExecuteScalar <int?>(checkMetaData);

                    if (exists == null || exists == -1)
                    {
                        ApplicationContext.Current.DatabaseContext.Database.Execute
                            (new Sql("ALTER TABLE TinifierImagesStatistic ADD COLUMN TotalSavedBytes bigint"));
                    }

                    if (hidePanel == null || hidePanel == -1)
                    {
                        ApplicationContext.Current.DatabaseContext.Database.Execute
                            (new Sql("ALTER TABLE TinifierUserSettings ADD COLUMN HideLeftPanel bit not null default(0)"));
                    }

                    if (metaData == null || metaData == -1)
                    {
                        ApplicationContext.Current.DatabaseContext.Database.Execute
                            (new Sql("ALTER TABLE TinifierUserSettings ADD COLUMN PreserveMetadata bit not null default(0)"));
                    }
                }
            }
        }
 protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
 {
     TreeControllerBase.TreeNodesRendering += TreeControllerBase_TreeNodesRendering;
     var ctx = ApplicationContext.Current.DatabaseContext;
     var db = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger, ctx.SqlSyntax);
     //Check if the DB table does NOT exist
     if (!db.TableExist("LookWhosEditingNow"))
     {
         //Create DB table - and set overwrite to false
         db.CreateTable<Edit>(false);
     }
     //Install dashboard
     AddStartUpSectionDashboard();
 }
Exemple #34
0
        /// <summary>
        /// Gets the hierarchy.
        /// </summary>
        /// <param name="useCache">if set to <c>true</c> the score from the database is used, else it will be calculated.</param>
        /// <returns></returns>
        public List <PageScoreNode> GetHierarchy(bool useCache = true)
        {
            var tableName = _tableNameHelper.GetTableName();

            var databaseContext      = UmbracoContext.Current.Application.DatabaseContext;
            var databaseSchemaHelper = new DatabaseSchemaHelper(databaseContext.Database, LoggerResolver.Current.Logger, databaseContext.SqlSyntax);

            if (databaseSchemaHelper.TableExist(tableName))
            {
                var nodeCollection = _umbracoHelper.TypedContentAtRoot();
                return(_pageScoreNodeHelper.GetPageHierarchy(nodeCollection, useCache));
            }
            return(null);
        }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var dbContext = applicationContext.DatabaseContext;
            var db = new DatabaseSchemaHelper(dbContext.Database, applicationContext.ProfilingLogger.Logger, dbContext.SqlSyntax);

            // automatically create the tables for the index on app start
            if (db.TableExist("FormEditorEntries") == false)
            {
                db.CreateTable<Entry>(false);
                // hack to get SQL server to use NVARCHAR(MAX) datatype
                dbContext.Database.Execute("ALTER TABLE FormEditorEntries ALTER COLUMN FieldValues NVARCHAR(MAX)");
            }
            if (db.TableExist("FormEditorFiles") == false)
            {
                db.CreateTable<File>(false);
            }
        }
        /// <summary>
        /// Updates the column size
        /// </summary>
        public override void Up()
        {
            var database = ApplicationContext.Current.DatabaseContext.Database;

            var databaseSchemaHelper = new DatabaseSchemaHelper(database, this.Logger, this.SqlSyntax);
            if (databaseSchemaHelper.TableExist("merchAppliedPayment"))
            {
                // Add another assertion that the field size has not already been changed to 500
                // and some other migration failed which flagged the version to 2.2.0 or earlier
                var size = database.GetDbTableColumnSize("merchAppliedPayment", "description");

                if (size == 500) return;

                // Update the column to allow for 500 characters instead of 255 which proved too small
                Alter.Table("merchAppliedPayment").AlterColumn("description").AsString(500).NotNullable();
            }
        }
        /// <summary>
        /// Updates the merchProductAttribute table altering detachedContentValues to NTEXT.
        /// </summary>
        public override void Up()
        {
            var database = ApplicationContext.Current.DatabaseContext.Database;

            var databaseSchemaHelper = new DatabaseSchemaHelper(database, this.Logger, this.SqlSyntax);
            if (databaseSchemaHelper.TableExist("merchProductAttribute"))
            {
                // Add another assertion that the field size has not already been changed to NTEXT
                // and some other migration failed which flagged the version to 2.3.0 or earlier
                var size = database.GetDbTableColumnSize("merchProductAttribute", "detachedContentValues");

                if (size > 500) return;

                // Update the column to be NTEXT instead of 255 - BUG FIX
                var textType = this.SqlSyntax.GetSpecialDbType(SpecialDbTypes.NTEXT);
                Alter.Table("merchProductAttribute").AlterColumn("detachedContentValues").AsCustom(textType).Nullable();
            }

            Logger.Debug<AlterProductAttributeColumnToNtext>("AlterProductAttributeColumnToNtext has been called.");
        }
Exemple #38
0
        internal static void CreateTables(ApplicationContext applicationContext)
        {
            //Get the Umbraco Database context
            var ctx = applicationContext.DatabaseContext;
            var db = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger, ctx.SqlSyntax);

            LogHelper.Info<EasyADApplication>("Creating EasyAD tables");

            //Check if the DB table does NOT exist
            if (!db.TableExist(AppConstants.TableNames.EasyADGroups))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<EasyADGroup>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist(AppConstants.TableNames.EasyADGroup2Users))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<EasyADGroup2User>(false);
            }
        }
        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.");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateProductOptionAttributeShareTable"/> class.
 /// </summary>
 public CreateProductOptionAttributeShareTable()
 {
     var dbContext = ApplicationContext.Current.DatabaseContext;
     _schemaHelper = new DatabaseSchemaHelper(dbContext.Database, LoggerResolver.Current.Logger, dbContext.SqlSyntax);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateInvoice2EntityCollectionTable"/> class.
 /// </summary>
 public CreateInvoice2EntityCollectionTable()
 {
     var dbContext = ApplicationContext.Current.DatabaseContext;
     _schemaHelper = new DatabaseSchemaHelper(dbContext.Database, LoggerResolver.Current.Logger, dbContext.SqlSyntax);    
 }
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            //Get the Umbraco Database context
            var ctx = applicationContext.DatabaseContext;
            var db = new DatabaseSchemaHelper(ctx.Database, applicationContext.ProfilingLogger.Logger, ctx.SqlSyntax);

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusRegions"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<Region>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusDistricts"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<District>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusGrants"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<Grant>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusEmployDepartments"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<EmployDepartment>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusGrantDefinitions"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<GrantDefinition>(false);
            }

            //Check if the DB table does NOT exist
            /*
            if (!db.TableExist("JobsplusGrantsGrantDefinitions"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<GrantGrantDefinition>(false);
            }
             */

            if (!db.TableExist("JobsplusGrantDefEmployDeparts"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<GrantDefEmployDeparts>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusSpecializations"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<Specialization>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusJobs"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<Job>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusJobTemplates"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<JobTemplate>(false);
            }

            //Check if the DB table does NOT exist
            if (!db.TableExist("JobsplusAdvertisementReply"))
            {
                //Create DB table - and set overwrite to false
                db.CreateTable<AdvertisementReply>(false);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AddTaxMethodColumn"/> class.
 /// </summary>
 /// <param name="sqlSyntax">
 /// The SQL syntax.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public AddTaxMethodColumn(ISqlSyntaxProvider sqlSyntax, ILogger logger)
     : base(sqlSyntax, logger)
 {
     _sqlSyntaxProvider = ApplicationContext.Current.DatabaseContext.SqlSyntax;
     _databaseSchemaHelper = new DatabaseSchemaHelper(ApplicationContext.Current.DatabaseContext.Database, Umbraco.Core.Logging.Logger.CreateWithDefaultLog4NetConfiguration(), _sqlSyntaxProvider);
 }
Exemple #44
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateNoteTable"/> class.
 /// </summary>
 public CreateNoteTable()
 {
     var dbContext = ApplicationContext.Current.DatabaseContext;
     _database = dbContext.Database;
     _schemaHelper = new DatabaseSchemaHelper(dbContext.Database, LoggerResolver.Current.Logger, dbContext.SqlSyntax);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateOneNineZeroTables"/> class.
 /// </summary>
 public CreateOneNineZeroTables()
 {
     var dbContext = ApplicationContext.Current.DatabaseContext;
     _schemaHelper = new DatabaseSchemaHelper(dbContext.Database, LoggerResolver.Current.Logger, dbContext.SqlSyntax);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DatabaseSchemaCreation"/> class.
 /// </summary>
 /// <param name="database">
 /// The database.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="databaseSchemaHelper">
 /// The database Schema Helper.
 /// </param>
 public DatabaseSchemaCreation(Database database, ILogger logger, DatabaseSchemaHelper databaseSchemaHelper, ISqlSyntaxProvider sqlSyntax)
 {
     _database = database;
     _logger = logger;
     _umbSchemaHelper = databaseSchemaHelper;
     _sqlSyntax = sqlSyntax;
 }
 /// <summary>
 /// Modifies the database (e.g., adding necessary tables).
 /// </summary>
 /// <param name="applicationContext">
 /// The application context.
 /// </param>
 private void InitializeDatabase(ApplicationContext applicationContext)
 {
     var dbContext = applicationContext.DatabaseContext;
     var logger = applicationContext.ProfilingLogger.Logger;
     var db = dbContext.Database;
     var dbHelper = new DatabaseSchemaHelper(db, logger, dbContext.SqlSyntax);
     try
     {
         dbHelper.CreateTable<FormulateSubmission>();
     }
     catch (Exception ex)
     {
         LogHelper.Error<ApplicationStartedHandler>(TableCreationError, ex);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateProductVariantDetachedContentTable"/> class.
 /// </summary>
 public CreateProductVariantDetachedContentTable()
 {
     var dbContext = ApplicationContext.Current.DatabaseContext;
     _schemaHelper = new DatabaseSchemaHelper(dbContext.Database, LoggerResolver.Current.Logger, dbContext.SqlSyntax);
 }