Restore all template entry's in the database back to their defaults

My Postgresql db seems to have duplicate entries for template_kinds (2 registration entry’s) as well as also missing the kickstart default provisioning template. I span up a new copy and tried to copy the provisioning template entry to the templates table, but it doesnt show up in the web interface (im assuming theres more relationships and dependencies in the db.

Im happy to have all templates / OS / installation media reset to defaults if i can preserve the current host registations.

Expected outcome:
Provisioning templates to be available in the web interface

Foreman and Proxy versions:
Foreman 3.0.1 - katello 4.2.1

Hmmm templates should be good if you delete them, foreman-rake db:seed should have re-create them. Problem is, those which are associated to hosts cannot be deleted due to foreign key constraints. Kinds that is a bigger problem, our code simply assumes that name is unique.

This is a typical design fallback of Ruby on Rails and its validators - the framework does not like colum constraint (e.g. unique name) as it does not work well with its design. Therefore we don’t have these on most places, thus you can run into these issues.

My suggestion:

  1. Backup!
  2. Delete from both tables, it will fail to delete some records due to references
  3. Run the db seed command
  4. Check the results
  5. Optinally fix the remaining records

You can get all the templates directly from our git, you do not need to side-install a new instance: