Continuing the discussion from Manually restoring a Discourse backup for development:
on my local machine, I want to delete a tag in the backup database before restore. how can I do it via console?
The discussion addresses how to delete a tag from a development database on a local machine, particularly from a backup that cannot be restored due to duplicate tag issues. Pad_Pors asks how to remove a tag via the console before restoring a backup. simon suggests using the Rails console with Tag.find_by_name('<your_tag_name>').destroy! to ensure all related records are cleaned up. Pad_Pors clarifies the need to delete the tag from an unrun backup. simon recommends first deleting the tag on the original site and creating a new backup, or directly using SQL in a psql terminal with DELETE FROM tags WHERE name = <your_tag_name>;, though caution is advised as this may not fully remove tag references. He also suggests testing on a copy and using SELECT to verify the tag’s existence.
Continuing the discussion from Manually restoring a Discourse backup for development:
on my local machine, I want to delete a tag in the backup database before restore. how can I do it via console?
To delete a tag from the Rails console, try:
t = Tag.find_by_name('<your_tag_name>')
t.destroy!
Calling destroy! instead of delete in the last command will clean up all records on the site that are associated with the removed tag.
thanks for your help ![]()
is it possible to delete a tag from a database that hasn’t been running yet? i.e. from a backup, which can’t be restored (because of the duplicated tag problem)?
I hope the question is clear.
If I was doing this myself, I would start by going back to the site that the backup file was created on, delete the tag through the Rails console, then create a new backup file.
If that is not possible, or if it does not solve the duplicate tag issue, you could delete the row from the table by opening a psql terminal on it. Something like:
DELETE FROM tags WHERE name = <your_tag_name>;
My concern with this is that it will not remove usages of the deleted tag from the site’s database in the same way as is done if you use the Rails destroy! command. It might be a good idea to test this out on a copy of the backup file to make sure that it does not break anything.
It might also be a good idea to run a SELECT statement before deleting the tag. That might show the cause of the issue:
SELECT FROM tags WHERE name = <your_tag_name>;