How do i remove module's data from Orchard database?
Asked Answered
V

3

14

i have installed a module and after the migration and creating tables in Orchard.sdf i want to clear all tables and rollback all changes that the migration did.

I dropped the tables but i guess some metadata should be removed.

how we can clear a modules data completely? thanks.

Vitale answered 24/10, 2012 at 20:54 Comment(0)
P
18

A complete uninstall involves deleting the database tables and rows that are associated with your module's name, the names of its features, and of its namespaces. Here is a process that worked for us.

1: Run orchard.exe > package uninstall Orchard.Module.MyModuleName

2: Then, open SQL Server Management Studio and drop the following database table(s) that are associated with your module.

MyModuleName_MyFeatureNameRecord

3: Do a wildcard search of the following table columns. Be sure to search for MyModuleName, MyNamespaceName, MyFeatureName, etc. You will eventually delete all these rows, but not yet.

SELECT *  FROM Orchard_Framework_ContentTypeRecord  WHERE Name LIKE '%%'
SELECT *  FROM Settings_ContentTypeDefinitionRecord  WHERE Name LIKE '%%'
SELECT *  FROM Settings_ContentPartDefinitionRecord  WHERE Name LIKE '%%'
SELECT *  FROM Settings_ShellFeatureRecord  WHERE Name LIKE '%%'
SELECT *  FROM Settings_ShellFeatureStateRecord  WHERE Name LIKE '%%'
SELECT *  FROM Orchard_Framework_DataMigrationRecord  WHERE DataMigrationClass LIKE '%%'

4: From the search results above, make a note of the Id values of rows in these tables.

Orchard_Framework_ContentTypeRecord.Id
Settings_ContentTypeDefinitionRecord.Id 

5: Now that you have recorded Id, delete the rows that you found in step 3 above.

6: Using the Ids collected in step 4, delete the rows from the following tables.

SELECT * FROM Settings_ContentTypePartDefinitionRecord 
    WHERE ContentTypeDefinitionRecord_Id IN()

SELECT * FROM Orchard_Framework_ContentItemRecord 
    WHERE ContentType_id IN ()

That's what worked for me.

Privation answered 18/4, 2013 at 19:4 Comment(1)
seems to me, you should also delete values from Orchard_Framework_ContentItemVersionRecord where ContentItemRecord_id = Orchard_Framework_ContentItemRecord.id for known ContentTypesTuition
S
5

I don’t know if there is a proper way to do that, but cleaning up Orchard_Framework_DataMigrationRecord should be enough: datamigration checks this table to find the current feature version, if there is already an entry you may not be able to re-enable the feature. Also check Settings_ShellFeatureRecord, Settings_ShellFeatureStateRecord, Settings_ContentPartDefinitionRecord and Settings_ContentTypeDefinitionRecord.

Finally, there may be many references in other tables but I think nothing dangerous.

Seiter answered 24/10, 2012 at 21:57 Comment(0)
G
0

Here is a SQL Query snippet that makes this easier if you use table prefixes with tenants.

USE DatabaseName
DECLARE @moduleName varchar(255);
DECLARE @tableName varchar(255);
DECLARE @tablePrefix varchar(255);

SET @moduleName = '%Orchard.YourModule%';
SET @tablePrefix = 'YourTablePrefix';

SET @tableName = @tablePrefix + '_Orchard_Framework_ContentTypeRecord';
DECLARE @sql nvarchar(4000)
SELECT @sql = ' SELECT * ' +
              ' FROM dbo.' + quotename(@tableName) +
              ' WHERE Name LIKE @moduleName'
EXEC sp_executesql @sql, N'@moduleName varchar(255)', @moduleName;

SET @tableName = @tablePrefix + '_Settings_ContentTypeDefinitionRecord';
SELECT @sql = ' SELECT * ' +
              ' FROM dbo.' + quotename(@tableName) +
          ' WHERE Name LIKE @moduleName'
EXEC sp_executesql @sql, N'@moduleName varchar(255)', @moduleName;

SET @tableName = @tablePrefix + '_Settings_ContentPartDefinitionRecord';
SELECT @sql = ' SELECT * ' +
              ' FROM dbo.' + quotename(@tableName) +
          ' WHERE Name LIKE @moduleName'
EXEC sp_executesql @sql, N'@moduleName varchar(255)', @moduleName;

SET @tableName = @tablePrefix + '_Settings_ShellFeatureRecord';
SELECT @sql = ' SELECT * ' +
              ' FROM dbo.' + quotename(@tableName) +
              ' WHERE Name LIKE @moduleName'
EXEC sp_executesql @sql, N'@moduleName varchar(255)', @moduleName;

SET @tableName = @tablePrefix + '_Settings_ShellFeatureStateRecord';
SELECT @sql = ' SELECT * ' +
              ' FROM dbo.' + quotename(@tableName) +
              ' WHERE Name LIKE @moduleName'
EXEC sp_executesql @sql, N'@moduleName varchar(255)', @moduleName;

SET @tableName = @tablePrefix + '_Orchard_Framework_DataMigrationRecord';
SELECT @sql = ' SELECT * ' +
              ' FROM dbo.' + quotename(@tableName) +
              ' WHERE DataMigrationClass LIKE @moduleName'
EXEC sp_executesql @sql, N'@moduleName varchar(255)', @moduleName;
Giotto answered 22/3, 2016 at 15:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.