Skip to content

Commit

Permalink
Update Scripts for mysql and sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne-KTCSZ committed Sep 18, 2024
1 parent 2b2e5fd commit 7c7434f
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 35 deletions.
70 changes: 35 additions & 35 deletions Database/Update/4.1/MsSql.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
IF NOT EXISTS (SELECT *
IF NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'ArticleTypeRelation')
Expand All @@ -17,36 +17,36 @@ GO
TRUNCATE TABLE [dbo].[ArticleTypeRelation]
GO
INSERT INTO [dbo].[ArticleTypeRelation] (ArticleId, ArticleTypeId)
SELECT DISTINCT ContentID,ArticleTypeID FROM [Article]
SELECT DISTINCT ISNULL(ContentID,ID),ArticleTypeID FROM dbo.[Article]
GO

IF NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'WidgetArticleTypeRelation')
AND TABLE_NAME = 'CMS_WidgetArticleTypeRelation')
BEGIN
CREATE TABLE [dbo].[WidgetArticleTypeRelation](
CREATE TABLE [dbo].[CMS_WidgetArticleTypeRelation](
[WidgetId] [nvarchar](100) NOT NULL,
[ArticleTypeId] [int] NOT NULL,
CONSTRAINT [PK_WidgetArticleTypeRelation] PRIMARY KEY CLUSTERED
CONSTRAINT [PK_CMS_WidgetArticleTypeRelation] PRIMARY KEY CLUSTERED
(
[WidgetId] ASC,
[ArticleTypeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
TRUNCATE TABLE dbo.WidgetArticleTypeRelation
TRUNCATE TABLE dbo.CMS_WidgetArticleTypeRelation
GO
INSERT INTO [dbo].[WidgetArticleTypeRelation](WidgetId,ArticleTypeId)
SELECT T0.ID, T1.ID FROM ArticleListWidget T0
INNER JOIN ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID =T1.ParentID
INSERT INTO [dbo].[CMS_WidgetArticleTypeRelation](WidgetId,ArticleTypeId)
SELECT T0.ID, T1.ID FROM dbo.ArticleListWidget T0
INNER JOIN dbo.ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID =T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM ArticleTopWidget T0
INNER JOIN ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID =T1.ParentID
SELECT T0.ID, T1.ID FROM dbo.ArticleTopWidget T0
INNER JOIN dbo.ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID =T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM ArticleTypeWidget T0
INNER JOIN ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID
SELECT T0.ID, T1.ID FROM dbo.ArticleTypeWidget T0
INNER JOIN dbo.ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID
GO


Expand All @@ -69,33 +69,33 @@ GO
TRUNCATE TABLE [dbo].[ProductCategoryRelation]
GO
INSERT INTO [dbo].[ProductCategoryRelation] (ProductId, ProductCategoryId)
SELECT DISTINCT ContentID, ProductCategoryID FROM dbo.[Product]
SELECT DISTINCT ISNULL(ContentID,ID), ProductCategoryID FROM dbo.[Product]
GO

IF NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'WidgetProductCategoryRelation')
AND TABLE_NAME = 'CMS_WidgetProductCategoryRelation')
BEGIN
CREATE TABLE [dbo].[WidgetProductCategoryRelation](
CREATE TABLE [dbo].[CMS_WidgetProductCategoryRelation](
[WidgetId] [nvarchar](100) NOT NULL,
[ProductCategoryId] [int] NOT NULL,
CONSTRAINT [PK_WidgetProductCategoryRelation] PRIMARY KEY CLUSTERED
CONSTRAINT [PK_CMS_WidgetProductCategoryRelation] PRIMARY KEY CLUSTERED
(
[WidgetId] ASC,
[ProductCategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
TRUNCATE TABLE dbo.[WidgetProductCategoryRelation]
TRUNCATE TABLE dbo.[CMS_WidgetProductCategoryRelation]
GO
INSERT INTO [dbo].[WidgetProductCategoryRelation](WidgetId, ProductCategoryId)
SELECT T0.ID, T1.ID FROM ProductListWidget T0
INNER JOIN ProductCategory T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID =T1.ParentID
INSERT INTO [dbo].[CMS_WidgetProductCategoryRelation](WidgetId, ProductCategoryId)
SELECT T0.ID, T1.ID FROM dbo.ProductListWidget T0
INNER JOIN dbo.ProductCategory T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID =T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM ProductCategoryWidget T0
INNER JOIN ProductCategory T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID = T1.ParentID
SELECT T0.ID, T1.ID FROM dbo.ProductCategoryWidget T0
INNER JOIN dbo.ProductCategory T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID = T1.ParentID
GO

IF NOT EXISTS (SELECT *
Expand All @@ -117,34 +117,34 @@ GO
TRUNCATE TABLE [dbo].[VideoTypeRelation]
GO
INSERT INTO [dbo].[VideoTypeRelation] (VideoId, VideoTypeId)
SELECT DISTINCT ContentID,VideoTypeID FROM [Video]
SELECT DISTINCT ISNULL(ContentID,ID),VideoTypeID FROM dbo.[Video]
GO

IF NOT EXISTS (SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'WidgetVideoTypeRelation')
AND TABLE_NAME = 'CMS_WidgetVideoTypeRelation')
BEGIN
CREATE TABLE [dbo].[WidgetVideoTypeRelation](
CREATE TABLE [dbo].[CMS_WidgetVideoTypeRelation](
[WidgetId] [nvarchar](100) NOT NULL,
[VideoTypeId] [int] NOT NULL,
CONSTRAINT [PK_WidgetVideoTypeRelation] PRIMARY KEY CLUSTERED
CONSTRAINT [PK_CMS_WidgetVideoTypeRelation] PRIMARY KEY CLUSTERED
(
[WidgetId] ASC,
[VideoTypeId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
TRUNCATE TABLE dbo.WidgetVideoTypeRelation
TRUNCATE TABLE dbo.CMS_WidgetVideoTypeRelation
GO
INSERT INTO [dbo].[WidgetVideoTypeRelation](WidgetId,VideoTypeId)
SELECT T0.ID, T1.ID FROM VideoListWidget T0
INNER JOIN VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID =T1.ParentID
INSERT INTO [dbo].[CMS_WidgetVideoTypeRelation](WidgetId,VideoTypeId)
SELECT T0.ID, T1.ID FROM dbo.VideoListWidget T0
INNER JOIN dbo.VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID =T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM VideoTopWidget T0
INNER JOIN VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID =T1.ParentID
SELECT T0.ID, T1.ID FROM dbo.VideoTopWidget T0
INNER JOIN dbo.VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID =T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM VideoTypeWidget T0
INNER JOIN VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID
SELECT T0.ID, T1.ID FROM dbo.VideoTypeWidget T0
INNER JOIN dbo.VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID
GO
83 changes: 83 additions & 0 deletions Database/Update/4.1/MySql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
CREATE TABLE IF NOT EXISTS `ArticleTypeRelation` (
`ArticleId` VARCHAR(100) NOT NULL,
`ArticleTypeId` VARCHAR(100) NOT NULL,
PRIMARY KEY (`ArticleId`, `ArticleTypeId`)
);

TRUNCATE TABLE `ArticleTypeRelation`;

INSERT INTO `ArticleTypeRelation` (ArticleId, ArticleTypeId)
SELECT DISTINCT IFNULL(ContentID, ID), ArticleTypeID FROM `Article`;

CREATE TABLE IF NOT EXISTS `CMS_WidgetArticleTypeRelation` (
`WidgetId` VARCHAR(100) NOT NULL,
`ArticleTypeId` INT NOT NULL,
PRIMARY KEY (`WidgetId`, `ArticleTypeId`)
);

TRUNCATE TABLE `CMS_WidgetArticleTypeRelation`;

INSERT INTO `CMS_WidgetArticleTypeRelation` (WidgetId, ArticleTypeId)
SELECT T0.ID, T1.ID FROM `ArticleListWidget` T0
INNER JOIN `ArticleType` T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM `ArticleTopWidget` T0
INNER JOIN `ArticleType` T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM `ArticleTypeWidget` T0
INNER JOIN `ArticleType` T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID;

CREATE TABLE IF NOT EXISTS `ProductCategoryRelation` (
`ProductId` VARCHAR(100) NOT NULL,
`ProductCategoryId` VARCHAR(100) NOT NULL,
PRIMARY KEY (`ProductId`, `ProductCategoryId`)
);

TRUNCATE TABLE `ProductCategoryRelation`;

INSERT INTO `ProductCategoryRelation` (ProductId, ProductCategoryId)
SELECT DISTINCT IFNULL(ContentID, ID), ProductCategoryID FROM `Product`;

CREATE TABLE IF NOT EXISTS `CMS_WidgetProductCategoryRelation` (
`WidgetId` VARCHAR(100) NOT NULL,
`ProductCategoryId` INT NOT NULL,
PRIMARY KEY (`WidgetId`, `ProductCategoryId`)
);

TRUNCATE TABLE `CMS_WidgetProductCategoryRelation`;

INSERT INTO `CMS_WidgetProductCategoryRelation` (WidgetId, ProductCategoryId)
SELECT T0.ID, T1.ID FROM `ProductListWidget` T0
INNER JOIN `ProductCategory` T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM `ProductCategoryWidget` T0
INNER JOIN `ProductCategory` T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID = T1.ParentID;

CREATE TABLE IF NOT EXISTS `VideoTypeRelation` (
`VideoId` VARCHAR(100) NOT NULL,
`VideoTypeId` VARCHAR(100) NOT NULL,
PRIMARY KEY (`VideoId`, `VideoTypeId`)
);

TRUNCATE TABLE `VideoTypeRelation`;

INSERT INTO `VideoTypeRelation` (VideoId, VideoTypeId)
SELECT DISTINCT IFNULL(ContentID, ID), VideoTypeID FROM `Video`;

CREATE TABLE IF NOT EXISTS `CMS_WidgetVideoTypeRelation` (
`WidgetId` VARCHAR(100) NOT NULL,
`VideoTypeId` INT NOT NULL,
PRIMARY KEY (`WidgetId`, `VideoTypeId`)
);

TRUNCATE TABLE `CMS_WidgetVideoTypeRelation`;

INSERT INTO `CMS_WidgetVideoTypeRelation` (WidgetId, VideoTypeId)
SELECT T0.ID, T1.ID FROM `VideoListWidget` T0
INNER JOIN `VideoType` T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM `VideoTopWidget` T0
INNER JOIN `VideoType` T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM `VideoTypeWidget` T0
INNER JOIN `VideoType` T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID;
83 changes: 83 additions & 0 deletions Database/Update/4.1/Sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
CREATE TABLE IF NOT EXISTS ArticleTypeRelation (
ArticleId TEXT NOT NULL,
ArticleTypeId TEXT NOT NULL,
PRIMARY KEY (ArticleId, ArticleTypeId)
);

DELETE FROM ArticleTypeRelation;

INSERT INTO ArticleTypeRelation (ArticleId, ArticleTypeId)
SELECT DISTINCT IFNULL(ContentID, ID), ArticleTypeID FROM Article;

CREATE TABLE IF NOT EXISTS CMS_WidgetArticleTypeRelation (
WidgetId TEXT NOT NULL,
ArticleTypeId INTEGER NOT NULL,
PRIMARY KEY (WidgetId, ArticleTypeId)
);

DELETE FROM CMS_WidgetArticleTypeRelation;

INSERT INTO CMS_WidgetArticleTypeRelation (WidgetId, ArticleTypeId)
SELECT T0.ID, T1.ID FROM ArticleListWidget T0
INNER JOIN ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM ArticleTopWidget T0
INNER JOIN ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM ArticleTypeWidget T0
INNER JOIN ArticleType T1 ON T0.ArticleTypeID = T1.ID OR T0.ArticleTypeID = T1.ParentID;

CREATE TABLE IF NOT EXISTS ProductCategoryRelation (
ProductId TEXT NOT NULL,
ProductCategoryId TEXT NOT NULL,
PRIMARY KEY (ProductId, ProductCategoryId)
);

DELETE FROM ProductCategoryRelation;

INSERT INTO ProductCategoryRelation (ProductId, ProductCategoryId)
SELECT DISTINCT IFNULL(ContentID, ID), ProductCategoryID FROM Product;

CREATE TABLE IF NOT EXISTS CMS_WidgetProductCategoryRelation (
WidgetId TEXT NOT NULL,
ProductCategoryId INTEGER NOT NULL,
PRIMARY KEY (WidgetId, ProductCategoryId)
);

DELETE FROM CMS_WidgetProductCategoryRelation;

INSERT INTO CMS_WidgetProductCategoryRelation (WidgetId, ProductCategoryId)
SELECT T0.ID, T1.ID FROM ProductListWidget T0
INNER JOIN ProductCategory T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM ProductCategoryWidget T0
INNER JOIN ProductCategory T1 ON T0.ProductCategoryID = T1.ID OR T0.ProductCategoryID = T1.ParentID;

CREATE TABLE IF NOT EXISTS VideoTypeRelation (
VideoId TEXT NOT NULL,
VideoTypeId TEXT NOT NULL,
PRIMARY KEY (VideoId, VideoTypeId)
);

DELETE FROM VideoTypeRelation;

INSERT INTO VideoTypeRelation (VideoId, VideoTypeId)
SELECT DISTINCT IFNULL(ContentID, ID), VideoTypeID FROM Video;

CREATE TABLE IF NOT EXISTS CMS_WidgetVideoTypeRelation (
WidgetId TEXT NOT NULL,
VideoTypeId INTEGER NOT NULL,
PRIMARY KEY (WidgetId, VideoTypeId)
);

DELETE FROM CMS_WidgetVideoTypeRelation;

INSERT INTO CMS_WidgetVideoTypeRelation (WidgetId, VideoTypeId)
SELECT T0.ID, T1.ID FROM VideoListWidget T0
INNER JOIN VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM VideoTopWidget T0
INNER JOIN VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID
UNION
SELECT T0.ID, T1.ID FROM VideoTypeWidget T0
INNER JOIN VideoType T1 ON T0.VideoTypeID = T1.ID OR T0.VideoTypeID = T1.ParentID;

0 comments on commit 7c7434f

Please sign in to comment.