Пример #1
0
        public void Upgrade(IDotEntityTransaction transaction)
        {
            Db.AddColumn <MenuItem, string>(nameof(MenuItem.Description), "", transaction);
            Db.AddColumn <MenuItem, string>(nameof(MenuItem.ExtraData), "", transaction);
            //execute the following only if it's not a fresh install
            if (transaction.CurrentlyRanVersions.All(x => x.GetType() != typeof(Version1)))
            {
                var parentMenuItemIdCol = DotEntityDb.Provider.SafeEnclose("ParentMenuItemId");
                var parentIdCol         = DotEntityDb.Provider.SafeEnclose(nameof(MenuItem.ParentId));
                var menuItemTable       = DotEntityDb.GetTableNameForType <MenuItem>();
                Db.AddColumn <MenuItem, int>(nameof(MenuItem.ParentId), 0, transaction);
                Db.Query($"UPDATE {menuItemTable} SET {parentIdCol}={parentMenuItemIdCol}", null, transaction);
                Db.DropColumn <MenuItem>("ParentMenuItemId", transaction);
            }

            var cartTable  = DotEntityDb.Provider.SafeEnclose(DotEntityDb.GetTableNameForType <Cart>());
            var orderTable = DotEntityDb.Provider.SafeEnclose(DotEntityDb.GetTableNameForType <Order>());
            var selectedShippingOptionCol = DotEntityDb.Provider.SafeEnclose(nameof(Cart.SelectedShippingOption));
            var query =
                $"UPDATE {cartTable} SET {selectedShippingOptionCol}='[{{\"name\":\"' + {selectedShippingOptionCol} + '\"}}]'";

            Db.Query(query, null, transaction);
            query =
                $"UPDATE {orderTable} SET {selectedShippingOptionCol}='[{{\"name\":\"' + {selectedShippingOptionCol} + '\"}}]'";
            Db.Query(query, null, transaction);
        }
Пример #2
0
        public void Downgrade(IDotEntityTransaction transaction)
        {
            Db.DropColumn <MenuItem>(nameof(MenuItem.Description), transaction);
            Db.DropColumn <MenuItem>(nameof(MenuItem.ExtraData), transaction);

            var parentMenuItemIdCol = DotEntityDb.Provider.SafeEnclose("ParentMenuItemId");
            var parentIdCol         = DotEntityDb.Provider.SafeEnclose(nameof(MenuItem.ParentId));
            var menuItemTable       = DotEntityDb.GetTableNameForType <MenuItem>();

            Db.AddColumn <MenuItem, int>("ParentMenuItemId", 0, transaction);
            Db.Query($"UPDATE {menuItemTable} SET {parentMenuItemIdCol}={parentIdCol}", null, transaction);
            Db.DropColumn <MenuItem>(nameof(MenuItem.ParentId), transaction);
        }
Пример #3
0
        public void Downgrade(IDotEntityTransaction transaction)
        {
            Db.DropTable <EntityTag>(transaction);
            Db.DropColumn <MenuItem>(nameof(MenuItem.OpenInNewWindow), transaction);

            var parentCategoryIdCol = DotEntityDb.Provider.SafeEnclose(nameof(Category.ParentCategoryId));
            var parentIdCol         = DotEntityDb.Provider.SafeEnclose(nameof(Category.ParentId));
            var categoryTable       = DotEntityDb.GetTableNameForType <Category>();

            Db.AddColumn <Category, int>(nameof(Category.ParentCategoryId), 0, transaction);
            Db.Query($"UPDATE {categoryTable} SET {parentCategoryIdCol}={parentIdCol}", null, transaction);
            Db.DropColumn <Category>(nameof(Category.ParentId), transaction);

            Db.DropColumn <ContentPage>(nameof(ContentPage.ParentId), transaction);
        }
Пример #4
0
        public void Upgrade(IDotEntityTransaction transaction)
        {
            Db.CreateTable <EntityTag>(transaction);

            //execute the following only if it's not a fresh install
            if (transaction.CurrentlyRanVersions.All(x => x.GetType() != typeof(Version1)))
            {
                Db.AddColumn <MenuItem, bool>(nameof(MenuItem.OpenInNewWindow), false, transaction);
                var parentCategoryIdCol = DotEntityDb.Provider.SafeEnclose(nameof(Category.ParentCategoryId));
                var parentIdCol         = DotEntityDb.Provider.SafeEnclose(nameof(Category.ParentId));
                var categoryTable       = DotEntityDb.GetTableNameForType <Category>();
                Db.AddColumn <Category, int>(nameof(Category.ParentId), 0, transaction);
                Db.Query($"UPDATE {categoryTable} SET {parentIdCol}={parentCategoryIdCol}", null, transaction);
                Db.DropColumn <Category>(nameof(Category.ParentCategoryId), transaction);
                Db.AddColumn <ContentPage, int>(nameof(ContentPage.ParentId), 0, transaction);
            }
        }
Пример #5
0
        public void Upgrade(IDotEntityTransaction transaction)
        {
            Db.AddColumn <OrderFulfillment, bool>(nameof(OrderFulfillment.Locked), true, transaction);

            #region MultiStore and Catalog

            Db.CreateTable <Store>(transaction);
            Db.CreateTable <Catalog>(transaction);
            Db.CreateTable <EntityStore>(transaction);
            Db.CreateTable <ProductCatalog>(transaction);
            Db.CreateTable <CatalogCountry>(transaction);

            Db.CreateConstraint(Relation.Create <Store, EntityStore>("Id", "StoreId"), transaction, true);
            Db.CreateConstraint(Relation.Create <Product, ProductCatalog>("Id", "ProductId"), transaction, true);
            Db.CreateConstraint(Relation.Create <Catalog, ProductCatalog>("Id", "CatalogId"), transaction, true);

            //run following only if it's not a fresh install
            if (transaction.CurrentlyRanVersions.All(x => x.GetType() != typeof(Version1)))
            {
                //add a default store
                var store = new Store()
                {
                    Name = "Primary Store",
                    Live = true
                };
                EntitySet <Store> .Insert(store, transaction);

                var storeId = 1; //this will be the store id for new store
                //next create a default catalog
                var catalog = new Catalog()
                {
                    Name = "Primary Catalog",
                    IsCountrySpecific = false
                };
                EntitySet <Catalog> .Insert(catalog, transaction);

                EntitySet <EntityStore> .Insert(new EntityStore()
                {
                    EntityId   = 1,
                    StoreId    = 1,
                    EntityName = nameof(Catalog)
                }, transaction);

                Db.AddColumn <Setting, int>(nameof(Setting.StoreId), storeId, transaction);
                Db.AddColumn <Order, int>(nameof(Order.StoreId), storeId, transaction);

                //assign all products to this catalog
                var productTableName        = DotEntityDb.Provider.SafeEnclose(DotEntityDb.GetTableNameForType <Product>());
                var productCatalogTableName = DotEntityDb.Provider.SafeEnclose(DotEntityDb.GetTableNameForType <ProductCatalog>());
                var productIdCol            = DotEntityDb.Provider.SafeEnclose(nameof(ProductCatalog.ProductId));
                var catalogIdCol            = DotEntityDb.Provider.SafeEnclose(nameof(ProductCatalog.CatalogId));
                var idCol = DotEntityDb.Provider.SafeEnclose(nameof(ProductCatalog.Id));

                var query =
                    $"INSERT INTO {productCatalogTableName}({productIdCol}, {catalogIdCol}) SELECT {idCol}, 1 FROM {productTableName}";
                Db.Query(query, null, transaction);

                //update active status of plugins
                var pluginSetting = EntitySet <Setting> .Where(x =>
                                                               x.GroupName == nameof(PluginSettings) && x.Key == nameof(PluginSettings.SitePlugins)).Select().FirstOrDefault();

                if (pluginSetting != null)
                {
                    var pluginStatuses = JsonConvert.DeserializeObject <IList <PluginStatus> >(pluginSetting.Value);
                    foreach (var pluginStatus in pluginStatuses)
                    {
                        pluginStatus.ActiveStoreIds = pluginStatus.Active ? new List <int> {
                            store.Id
                        } : new List <int>();
                    }

                    pluginSetting.Value = JsonConvert.SerializeObject(pluginStatuses);
                    EntitySet <Setting> .Update(pluginSetting, transaction);
                }

                //update widgets
                pluginSetting = EntitySet <Setting> .Where(x =>
                                                           x.GroupName == nameof(PluginSettings) && x.Key == nameof(PluginSettings.SiteWidgets)).Select().FirstOrDefault();

                if (pluginSetting != null)
                {
                    var widgetStatuses = JsonConvert.DeserializeObject <IList <WidgetStatus> >(pluginSetting.Value);
                    foreach (var ws in widgetStatuses)
                    {
                        ws.StoreId = storeId;
                    }
                    pluginSetting.Value = JsonConvert.SerializeObject(widgetStatuses);
                    EntitySet <Setting> .Update(pluginSetting, transaction);
                }

                //update store ids to 0 for plugin settings as it is now global from this version
                EntitySet <Setting> .Update(new { storeId = 0 }, x => x.GroupName == nameof(PluginSettings), transaction);

                //update menus
                MoveEntityToStore <Menu>(storeId, transaction);
                //update content pages
                MoveEntityToStore <ContentPage>(storeId, transaction);
            }


            #endregion
        }