How to change page type table naem

Tomasz Czado asked on September 6, 2018 07:27

Hi,

what is the way to export and import site when one of page types has the same sql table name on both environments? How to change that sql table name on one of the environments and don't lose the pages?

Recent Answers


Juraj Ondrus answered on September 6, 2018 12:27

Hi,
To avoid conflicts like this, the best practice is always use the site name as a prefix when creating any custom object in Kentico.
Right now, the only way would be changing the values in the DB directly and also changing appropriate records in the CMS_Class table for given page type. However, this is really not recommended - it can cause serious damage. Be sure you have DB backups ready before doing any changes to the DB.

1 votesVote for this answer Mark as a Correct answer

Tomasz Czado answered on September 6, 2018 13:17

I know but I only support this project. Anyway I did it by updating few places in Kentico:


Update CMS_Class

UPDATE [dbo].[CMS_Class] SET [ClassTableName] = 'newtablename' WHERE [ClassName] = 'pagetypecodename';
GO

Rename sql table name

EXEC sp_rename 'oldtablename', 'newtablename';  
GO

Create new join view

CREATE VIEW [dbo].[View_newname_Joined] AS SELECT View_CMS_Tree_Joined.*, newtablename.* FROM View_CMS_Tree_Joined INNER JOIN newtablename ON View_CMS_Tree_Joined.DocumentForeignKeyValue = newtablename.[ID] WHERE (ClassName = 'pagetypecodename')
GO

Remvoe old join view

DROP VIEW [dbo].[View_oldname_Joined]
GO
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 6, 2018 14:18

What I'd suggest is cloning the page type you're dealing with in the envirnoment it came from to your new name. Then exporting it again and re-import it into your new environment.

Before making SQL changes, what about version history? Does this page type have any pages currently? Kentico uses classnames for everything so even though you may change the table name, it could have a negative effect on version history and other places if you update/change the class name too. I've been through 4 upgrades this year in which something like this was done manually and it corrupted over 100,000 version history records (large site).

1 votesVote for this answer Mark as a Correct answer

Tomasz Czado answered on September 6, 2018 14:51

Page type code name is different - only sql table name is the same.

When importing I don't have to take care about versioning - which is good news. Bad news is that on both environments I have pages based on that page types so I can't clone page type because I still need to do something with pages associated with them.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.